header parallax image
uncoditional

code liberated

  • Home
  • Pete
  • Home
  • Pete
CFML & Mach-IITools

Extracting Header rows from .cfmail file

May 11, 2015Peter Lombardo4206 views

With a big node to Mr. Hartfield, below is a simplified cfscript function which will get you the header data from a .cfmail file. Most likely that you want to get out of the undelivr folder. Note, that you can also use your own mail params (starting with an X-) which will help you keep track of emails.

see below this code for an example of utilizing it.

public struct function parseEmail(required string filePath) {
    var emailStruct = {};
    var properties = {};
    if (findNoCase( 'Unix', cgi.SERVER_SOFTWARE)) {
        variables.OS = 'unix';
        variables.seperator = chr(47);
    } else {
        variables.OS = 'windows';
        variables.seperator = chr(92);
    }
    var mailFolder = server.coldfusion.rootdir && seperator && 'Mail' & amp;
    seperator;
    if (fileExists(arguments.filePath)) {
        properties = createObject( " java ", " java.lang.System ").getProperties();
        properties.put(javacast( " string ", " mail.host "), javacast( " string ", " localhost "));
        properties.put(javacast( " string ", " mail.transport.protocol "), javacast( " string ", " smtp "));
        mailSession = createObject( " java ", " javax.mail.Session ").getDefaultInstance(properties, javacast( " null ", " "));
        fileStream = createObject( " java ", " java.io.FileInputStream ").init(arguments.filePath);
        mimeMessage = createObject( " java ", " javax.mail.internet.MimeMessage ").init(mailSession, fileStream);
        headers = mimeMessage.getAllHeaderLines();
        while (headers.hasMoreElements()) {
            curHeader = headers.nextElement();
            emailStruct.headers[listFirst(curHeader, ':')] = listDeleteAt(curHeader, 1, ':');
        }
    }
    return emailStruct;
}

Now use it..

call it…


var undelivrFileArr = directoryList(mailFolder & seperator & 'Undelivr', false, 'name','*.cfmail')
 
for (file in undelivrFileArr){
    cfMailFileInfoStruct = parseEmail(file.Directory & file.fileName);
 
    curMailRecord = spoolerMessageGateway.getMessageSendAttemptsCount(
        messageUUID = cfMailFileInfoStruct.messageUUID,
        senderEmail = cfMailFileInfoStruct.from,
        recipientEmail= cfMailFileInfoStruct.to,
        messageSubject = cfMailFileInfoStruct.subject
    );
}

There you have it. a curMailRecord structure with naming conventions for the data you want to extract. (I used messageUUID as my example of an x-[custom param] example.

– Pete

  • tweet
previous story

Programmatically test ColdFusion smtp server connection

next story

CFScript Components and OO notes

Peter Lombardo

Peter Lombardo

Web developer too long.

you might also like

Programmatically test ColdFusion smtp server connection

April 22, 2015

com.amazonaws.ClientConfiguration Errors

September 18, 2014

Balsamiq Mockups: the good and the bad

May 2, 2013

Leave a Response Cancel reply

You must be logged in to post a comment.

about me

uncoditional

Pete Lombardo

I like people and coding. Both change. Twenty years of full-stack development. I live in Maryland.

Recent Posts

  •   lives on!
    									
  • Cannot find module ‘…/…’ or its corresponding type declarations.
  • *ngIf – use parentheses
  • Angular component code block execution order
  • material dialog- how to get response data .subscribe()

Recent Comments

    Archives

    • June 2022
    • March 2022
    • June 2020
    • June 2019
    • November 2017
    • October 2017
    • September 2017
    • August 2017
    • June 2017
    • June 2015
    • May 2015
    • April 2015
    • October 2014
    • September 2014
    • July 2014
    • June 2014
    • May 2013
    • February 2013
    • January 2013
    • November 2012
    • October 2012

    Categories

    • angular
    • AWS
    • before the code
    • Browser Support
    • CFML & Mach-II
    • Chromebook
    • ckEditor
    • CloudSearch
    • ColdFusion
    • Java
    • javascript/typescript
    • JQuery and CSS
    • Languages
    • Life
    • material design
    • project
    • Projects
    • SNS
    • SQL
    • Tools
    • Uncategorized
    • unCODitional

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    0
    Followers
    0
    Followers
    0
    Followers
    0
    Followers

    Follow @ Instagram

    Configuration error or no pictures...