Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving the original message stream in case of an exception #198

Closed
dieks opened this issue May 29, 2015 · 10 comments
Closed

Saving the original message stream in case of an exception #198

dieks opened this issue May 29, 2015 · 10 comments
Labels
enhancement New feature or request question A question about how to do something

Comments

@dieks
Copy link

dieks commented May 29, 2015

Hi,

I am evaluating MailKit as the base library for an adapter I'm building. The adapter will be part of a larger application integration framework.
So far Mailkit looks promising.

I have a question though. One of my requirements is the ability to save the original stream (whenever possible and for as much as possible) in case of an exception while parsing it.
The purpose of this would mainly be to record problematic emails either for manual processing (in case of exceptions in production environments we need a way to continue the workflow)
or to slap the developer on the server/other end in the face with.

In https://github.com/jstedfast/MailKit/blob/master/README.md you say:
"It [MailKit] also parses messages directly from the socket instead of downloading the message into a
large string buffer before parsing it (...)"
This leads me to believe it could be difficult to record the complete message stream.
I'd appreciate it if you could give me some advice on how to implement this.

@jstedfast jstedfast added the question A question about how to do something label May 29, 2015
@jstedfast
Copy link
Owner

I should probably update that text because I think I ended up changing the code to download the message data into a memory stream before parsing it internally to be better able to recover from parsing exceptions :-)

Are you working with IMAP or POP3? If you are working with IMAP, you could use the ImapFolder.GetStream() methods to fetch the raw message or mime-part data and then parse that stream after you get it.

@dieks
Copy link
Author

dieks commented May 29, 2015

Ah, great!
Is there something similar to ImapFolder.GetStream() in case of Pop3?
I'm working with Pop3.

@jstedfast
Copy link
Owner

Unfortunately, no :-(

Perhaps an API can be added...

@dieks
Copy link
Author

dieks commented May 29, 2015

I'll dive into your code and add a GetStream() somewhere ;)
Might take a little while though.

@jstedfast
Copy link
Owner

Done.

@dieks
Copy link
Author

dieks commented May 29, 2015

And I was looking forward to fork MailKit, write a line of code and do a pull request.
(All of that would have taken me a day since I'm new to github and git, but I seriously would have enjoyed it.)
Ah well, maybe I get lucky and think of another feature request. ;)

Thanks!

@jstedfast jstedfast added the enhancement New feature or request label May 29, 2015
@jstedfast
Copy link
Owner

You could still fork it and start looking over the code :-)

@jstedfast
Copy link
Owner

FWIW, relating back to the original question, MimeKit's parser is pretty liberal in what it accepts, so it's rare for it to throw an exception if it looks anything like a message.

@jstedfast
Copy link
Owner

These seem to be the only 2 places where you can get an exception from parsing a message:

truncated header block:
https://github.com/jstedfast/MimeKit/blob/master/MimeKit/MimeParser.cs#L842

the first line of the message does not look like a valid header:
https://github.com/jstedfast/MimeKit/blob/master/MimeKit/MimeParser.cs#L928

the other places are for the UNIX mbox parser (i.e. multiple messages back-to-back in the same file)

@dieks
Copy link
Author

dieks commented May 29, 2015

Mimekit's liberalness is probably what will win me over. Still I need an escape route for those rare occasions something does go wrong. GetStream() seems to be what I want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question A question about how to do something
Projects
None yet
Development

No branches or pull requests

2 participants