File getmail.icn |
########################################################################### File: getmail.icn Subject: Procedure to parse mail file Author: Charles Shartsis Date: August 19, 1996 ########################################################################### 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. ########################################################################### Requires: Icon Version 9 or greater ###########################################################################
This file is part of the (main) package.
Source code.Details |
Procedures: |
getmail SEQ
mfield_to_rfield_name(mfield_name)
process_header_field(message, field)
Records: |
sender | E-Mail address of sender
|
dayofweek | |
month | |
day | |
time | |
year | selected message header fields
The following record fields hold the contents of common
message header fields. Each record field contains the
corresponding message field's body (as a string) or a null indicating
that no such field was present in the header.
Note that a list of message_record's
can be sorted on any of these fields using the sortff function.
The record field name is related to the message header field name
in the following way:
record_field_name := "_" ||
map(message_header_field_name, &ucase || "-", &lcase || "_")
Thus the "Mime-Version" field body is stored in the _mime_version
record field. Multiline message header fields are "unfolded"
into a single line according to RFC 822. The message field
name, the following colon, and any immediately following
whitespace are stripped from the beginning of the
record field. E.g., if a header contains
Mime-Version: 1.0
then
message._mime_version := "1.0"
The "Received:" field is handled differently from the other
fields since there are typically multiple occurrences of it
in the same header. The _received record field is either null or
contains a list of "Received:" fields. The message field names
are NOT stripped off. Thus
Received: from relay4.UU.NET by mail.netcom.com (8.6.12/Netcom)
id PAA10801; Sun, 28 May 1995 15:24:17 -0700
Received: from alterdial.UU.NET by relay4.UU.NET with SMTP
id QQyrsr05731; Sun, 28 May 1995 18:17:45 -0400
get stored as:
message._received :=
["Received: from relay4.UU.NET by mail.netcom.com (8.6.12/Netcom) id etc...",
"Received: from alterdial.UU.NET by relay4.UU.NET with SMTP id etc..."]
|
_return_path | |
_received | |
_date | |
_message_id | |
_x_sender | |
_x_mailer | |
_mime_version | |
_content_type | |
_to | |
_from | |
_subject | |
_status | |
_x_status | |
_path | |
_xref | |
_references | |
_errors_to | |
_x_lines | |
_x_vm_attributes | |
_reply_to | |
_newsgroups | |
_content_length | The "other" field gets all the message header fields for which we have not set up
a specific record field. The "other" record field either contains null
or a list of header fields not stored in the previous fields.
Message field names are NOT stripped off field bodies before being stored.
If there are multiple occurrences of the previously selected fields
(except _received which is assumed to occur multiple times), then
the first occurrence is stored in the appropriate record field from
the list above while subsequent occurences in the same header are
stored as separate list elements in the "other" record field.
E.g., the following header fields:
...
Whatever: Hello
Status: RO
Status: XX
Status: YY
...
would be stored as
message._status := "RO"
message.other :=
[..., "Whatever: Hello", "Status: XX", "Status: YY", ...]
|
other | The message text
This field is either null or a list of lines comprising
the message text.
|
message_text | The entire message - header and text
This field contains a list of uninterpreted lines (no RFC 822 unfolding)
comprising the raw message.
|
all |
components of "From " line