views:

582

answers:

3

Hi - I am new here so first of all my greetings to you

I am writing an application to run on my Windows Mobile (Pocket PC). FYI, I am using VB.NET.

My idea is to use my e-mail account with my provider, who gives me a lot GB:s to use, as a virtual online storage disk. In a few words, more or less like the GMAIL-drive which you may have read about. I have already written code to connect, using a telnet-socket, to my provider's SMTP, POP3 and IMAP accounts. I can log in and thus so far so good.

In my specific case, I'm not interested in the e-mails themselfes but actually the attachments which will be my files on this virtual storgae-card. I have found a lot of free classes, mostly in C#, for downloading e-mails with attachments and most important, the MIME-parsing. Unfortunately all these classes, in one way or another, uses classes/namespaces of the Net Framework which are not included in the NET Compact Framework which is used by Windows Mobile. Writing a MIME-parser myself is far too complex for me and my knowledge.

Therefore, at least in regard to my code for receiving via POP3 or IMAP, I was thinking that once I have downloaded all bytes on my device, I would simply parse the full e-mail (verifying where the boundaries are) and get the part(s) which have been encoded in Base64 and then decode it and rename it using the name and the extension of the file which I wrote in the subject-field of the e-mail at the time of sending. In this way, I could perhaps avoid all stuff about MIME and all its meanings...

What regards, sending thru' SMTP, I still have to look into it. Any ideas would be appreciated.

Sorry for this romance - what do you think - can I skip getting MIME-parsers and just use ordinary string-parsing?

Kind regards, Moster67

+1  A: 

A MIME parser IS just a string parser. They're very easy to write, especially if you know you just want/need a subset of MIME types. Lookup the RFC and implement it yourself.

Robert C. Barth
Thank you. You confirmed what I was believing i.e. that probably a hack using ordinary string-parsing may work
moster67
"They're very easy to write"? I would have said, "They not so bad to write...". What Piskvor says is my experience, about the brittle-ness.
Corey Trager
+1  A: 

You can try looking for the boundaries in the mail headers and then split the e-mail on this string. Parsing the subparts will be IMHO necessary (encoding and charset come to mind; just dropping the headers won't work in most cases), but a little bit easier than dealing with the whole message at once.

A word of caution: this is a brittle approach - it'll work on some messages, but break on others (e.g. nested multipart messages, changing boundary string (should not, but could happen) etc.).

Piskvor
What you are mentioning is more or less what I had in mind i.e. using the boundaries. I will try to find some examples of emails which contains nested multipart messagtes. Thank you for your suggestions.
moster67
Nested multi-part messages won't matter because the MIME boundary marker will be different for the nested message than it will be for the root message.
Robert C. Barth
+1  A: 

Hi,

writing a string parser of the mail message IS in fact writing a simple MIME parser. You can write a quick-and-dirty MIME parser in a few hours. If you will use it for parsing similar mails (e.g. sent from one location by same client software) it should all you need.

For details about MIME see

Few days of work should be realistic. I was involved in development of a simple in-house MIME parser (took few days to hack and parsed 95% of received emails), which envolved into a commercial product (few months of work, tons of unittest and hudreds of really vierd test emails from the wild) and then was modified so it can be used in Compact Framework (changes because of memory-constrained devices, changes because only small portion of .NET framework is ported to .NET CF). And add rewriting of quite big part of CryptoAPI functionality in order to make signed and encrypted S/MIME emails work on .NET CF.

The MIME parser is part of the Rebex Secure Mail for .NET/.NET CF component and can be downloaded from http://www.rebex.net/secure-mail.net/

All version of .NET and .NET CF are supported. Even the .NET CF1 dinosaurus ;-). However, it's not free.

Martin Vobr
interesting. Yes, I knew about your products (if I recall I believe I even tried a few) but since my application was meant to be free, I had to find an alternative way. For the time being, this project of mine is on hold but I will probably get on with it when I find some spare-time.
moster67