Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 3380 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Just done a bit of research for a system I am building into extracting the text from .eml files. so here a first version. Requires apache Commons-mail

<code>

// EMLextract ( fm_fileIn )

// 15_09_03 JRenfrew

// v1.0

// requires commons-mail

// from http://www.cnblogs.com/jiaoyiping/p/3761560.html

 

import org.apache.commons.mail.util.MimeMessageParser

import org.apache.commons.mail.util.MimeMessageUtils

 

removeCarr = { it ->

    return it.replace('\r\n' , '\n').replace('\n\n', '\n')

} //end removeCarr

 

file = new File (fm_fileIn)

mimeMessage = MimeMessageUtils.createMimeMessage(null, file)

parser = new MimeMessageParser(mimeMessage)

parsed = parser.parse()

 

if (parsed.hasPlainContent()){

    //smgetvariable to extract these - also getCc(), getBcc(), getReplyTo(), getTo()

    fm_from = parser.getFrom()

    fm_subj = parser.getSubject()

    return 'FROM: ' + fm_from + '\n' + 'SUBJECT: ' + fm_subj + '\n' + removeCarr(parsed.getPlainContent())

} else if (parser.parse().hasHtmlContent()){

    return removeCarr(parsed.getHtmlContent())

} else {

    return 'no text or html parts found'

} //end if

 

</code>

 

This topic is 3380 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.