getmail.icn: Procedure to parse mail file

link getmail
August 19, 1996; Charles Shartsis
Requires: Icon Version 9 or greater
This file is in the public domain.

The getmail procedure reads a Unix/Internet type mail folder
and generates a sequence of records, one per mail message.
It fails when end-of-file is reached.  Each record contains the
message header and message text components parsed into separate
record fields.  The entire uninterpreted message (header and text)
are also stored in the record.  See the description
of message_record below.

The argument to getmail is either the name of a mail folder or
the file handle for a mail folder which has already been opened
for reading.  If getmail is resumed after the last message is
generated, it closes the mail folder and returns failure.

If getmail generates an incomplete sequence (does not close the
folder and return failure) and is then restarted (not resumed)
on the same or a different mail folder, the previous folder file
handle remains open and inaccessible.  This may be a problem if
done repeatedly since there is usually an OS-imposed limit
on number of open file handles.  Safest way to use getmail
is using one of the below forms:

    message := message_record()
    every message := !getmail("folder_name") do {

            process message ...

    }

    message := message_record()
    coex := create getmail("folder_name")
    while message := @coex do {

            process message ...

    }

Note that if message_record's are stored  in a list, the records
may be sorted by individual components (like sender, _date, _subject)
using sortf function in Icon Version 9.0.

Source code | Program Library Page | Icon Home Page