Exam task sample: wwwnews

Let's suppose we have a WWW page with "news", i.e. the index page contains a list of references to news items in separate web pages located in the same directory. The list of news is managed by emails. Write a script implementing this work. The script reads mails delivered to a special address, checks the sender address (the "From:" header value) agains a list of valid senders written in the FROM shell variable (a string with space separated addresses) and according to the mail content, it modifies the list of news.

The index.html page has the following format:

... lines not containing <OL>
<LI><A HREF="message-file-name">news title</A> (dd. mm. yyyy)
<LI><A HREF="message-file-name">news title</A> (dd. mm. yyyy)
... rest of the page

The mail must contain either:

a) Subject: DEL date [n]
then the n-th item from the given day is removed from the list (i.e. the line in the index file together with the message page file); if n is omitted, all news items from the given day are removed.
b) Subject: news title
then the mail body contains the text of a new item; it should be saved under a unique name and an appropriate line added to the index.

A log of all executed operations is sent back to the original sender. Every incoming mail data (i.e. date, time, sender, subject) is logged to the access.log file. All the files must be locked during modification to guard against the simultaneous processing of two or more incoming mails.