Skip to content
Snippets Groups Projects
Commit 5482edc5 authored by rswindell's avatar rswindell
Browse files

Created parse_msg_header() convenience function (in mailproc_util.js) to

create an object (associative array) that contains all the RFC822 header
fields as string properties.
parent c056a7ce
No related branches found
No related tags found
No related merge requests found
// mailproc_util.js
// Utility functions for Synchronet external mail processors
// $Id$
// Parses raw RFC822-formatted messages for use with SMTP Mail Processors
// Returns an array of header fields parsed from the msgtxt
// msgtxt is an array of lines from the source (RFC822) message text
function parse_msg_header(msgtxt)
{
var hdr={};
for(i in msgtxt) {
if(msgtxt[i].length==0) /* Header delimiter */
break;
var match = msgtxt[i].match(/\s*(\S+)\s*:\s*(.*)/);
hdr[match[0]]=match[1];
}
return(hdr);
}
\ No newline at end of file
......@@ -5,6 +5,8 @@
// $Id$
load("mailproc_util.js");
// Set to false at any time to indicate a processing failure
var success=true;
......@@ -25,19 +27,27 @@ var recipient=rcptlst.iniGetAllObjects("number");
// These lines open the message text file in append mode (writing to the end)
var msgtxt = new File(message_text_filename);
if(!msgtxt.open("a")) // Change thie mode to "r+" for "read/update" access
if(!msgtxt.open("a+")) // Change the mode to "r+" for "read/update" access
exit();
// Create an object (associative array) of header field strings
var header = parse_msg_header(msgtxt.readAll());
// This an example of modifying the message text.
// In this case, we're adding some text (a dump of the recipient object array)
// to the end of the message.
msgtxt.writeln("\r\nHello from mailproc_example.js\r\n");
msgtxt.writeln("Array of recipient objects (message envelopes):\r\n");
msgtxt.writeln("\r\nHello from mailproc_example.js");
// Dump recipient object array
msgtxt.writeln("\r\nArray of recipient objects (message envelopes):\r\n");
for(i in recipient) // For each recipient object...
for(j in recipient[i]) // For each property...
msgtxt.writeln("recipient[" +i+ "]." +j+ "=" + recipient[i][j]);
msgtxt.writeln("recipient[" +i+ "]." +j+ " = " + recipient[i][j]);
// Dump header field strings
msgtxt.writeln("\r\nArray of RFC822 header fields:\r\n");
for(i in header)
msgtxt.writeln("header." +i+ " = " + header[i]);
// If there were any processing errors... reject the message
if(!success)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment