www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Parse .eml files

reply bachmeier <no spam.net> writes:
I want to save all email messages related to a research project 
into a directory, call a D program to generate an index of all 
messages, and push it to the repo server. That way all coauthors 
have access to all email messages even if they joined a project 
after several years. My client is Thunderbird, which by default 
creates .eml files.

Is there a way to do this in D? The email libraries I've found 
don't appear to work with .eml.
Apr 09 2018
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 9 April 2018 at 18:47:16 UTC, bachmeier wrote:
 Is there a way to do this in D? The email libraries I've found 
 don't appear to work with .eml.
My understanding is .eml is the same MIME format the email itself and mbox and maildir all use. So any of those libraries are likely to work with it. You should open the eml file in Notepad or whatever and see if there are more than one message in it. If so, my email.d can handle is mbox http://dpldocs.info/experimental-docs/arsd.email.processMboxData.html just `cast(immutable(ubyte)[]) std.file.read` the file to get that array. Otherwise, my email.d would do it as an individual message you can construct with this: http://dpldocs.info/experimental-docs/arsd.email.IncomingEmailMessage.this.1.html just std.file.readText and splitLines to get the string[] array. my email.d is here https://github.com/adamdruppe/arsd/blob/master/email.d it depends on dom.d htmltotext.d and characterencodings.d or on dub http://code.dlang.org/packages/arsd-official%3Aemail
Apr 09 2018
next sibling parent bachmeier <no spam.net> writes:
On Monday, 9 April 2018 at 19:17:20 UTC, Adam D. Ruppe wrote:

 My understanding is .eml is the same MIME format the email 
 itself and mbox and maildir all use.
Thanks. I didn't know that. I will try it using email.d.
Apr 09 2018
prev sibling parent reply bachmeier <no spam.net> writes:
On Monday, 9 April 2018 at 19:17:20 UTC, Adam D. Ruppe wrote:

[...]

I had a chance to try this out and it worked without a problem. I 
did have to download color.d in addition to the other 
dependencies you listed. In the event that Google brings someone 
here, this is a complete working program:

import std.file, std.stdio, std.string;
import arsd.email;

void main(string[] args) {
   string[] f = std.file.readText(args[1]).splitLines();
   auto em = new IncomingEmailMessage(f);
   writeln("From: ", em.from);
   writeln("To: ", em.to);
   writeln("Subject: ", em.subject);
   writeln(em.textMessageBody);
}

Compile with

dmd *.d -ofreademail

And run

./reademail 'email message.eml'
Apr 10 2018
parent reply Martin Tschierschke <mt smartdolphin.de> writes:
On Wednesday, 11 April 2018 at 02:37:39 UTC, bachmeier wrote:
 On Monday, 9 April 2018 at 19:17:20 UTC, Adam D. Ruppe wrote:

 [...]

 I had a chance to try this out and it worked without a problem. 
 I did have to download color.d in addition to the other 
 dependencies you listed. In the event that Google brings 
 someone here, this is a complete working program:

 import std.file, std.stdio, std.string;
 import arsd.email;

 void main(string[] args) {
   string[] f = std.file.readText(args[1]).splitLines();
   auto em = new IncomingEmailMessage(f);
   writeln("From: ", em.from);
   writeln("To: ", em.to);
   writeln("Subject: ", em.subject);
   writeln(em.textMessageBody);
 }

 Compile with

 dmd *.d -ofreademail

 And run

 ./reademail 'email message.eml'
Very cool, I was looking for something similar, thank you both for sharing! My goal is to store mails in a mysql table with fulltext index, connected to a existing old crm solution via the email address as a foreign key. My question in the moment is, how do I invoke Thunderbird to display a certain single mail (or maildir) file? How do I use Thunderbird as the client, to show, to answer or to forward these mails. An alternative would be to use a browser based mailer? Handling all attachments is an other purpose.
Apr 11 2018
parent reply bachmeier <no spam.net> writes:
On Wednesday, 11 April 2018 at 15:20:08 UTC, Martin Tschierschke 
wrote:

 My question in the moment is, how do I invoke Thunderbird to 
 display a certain single mail (or maildir) file?
 How do I use Thunderbird as the client, to show, to answer or 
 to forward these mails.
 An alternative would be to use a browser based mailer? Handling 
 all attachments is an other purpose.
Can you use executeShell and call Thunderbird from the command line? Something like executeShell("thunderbird -compose \"subject='My Christmas Gift',body='Please send me a new car',to='santa claus.net'") http://kb.mozillazine.org/Command_line_arguments_%28Thunderbird%29
Apr 11 2018
parent Martin Tschierschke <mt smartdolphin.de> writes:
On Thursday, 12 April 2018 at 00:00:04 UTC, bachmeier wrote:
 On Wednesday, 11 April 2018 at 15:20:08 UTC, Martin 
 Tschierschke wrote:

 My question in the moment is, how do I invoke Thunderbird to 
 display a certain single mail (or maildir) file?
 How do I use Thunderbird as the client, to show, to answer or 
 to forward these mails.
 An alternative would be to use a browser based mailer? 
 Handling all attachments is an other purpose.
Can you use executeShell and call Thunderbird from the command line? Something like executeShell("thunderbird -compose \"subject='My Christmas Gift',body='Please send me a new car',to='santa claus.net'") http://kb.mozillazine.org/Command_line_arguments_%28Thunderbird%29
Thank you, especially for the Link! There I saw, that attachment with a local file is possible. So It should be possible to invoke Thunderbird with the extracted elements of an existing email.
Apr 12 2018