Best way to store attachmets in database

Mar 23, 2013 at 12:45 PM
First I want to thank you for all your effort and this library.
I am working on web email client some thing like zimbra (home work for school) and I need to store all mails on some database.
In a database there should be columns: to,from, body etc.
My problem is how to store attachments, I figure out two solutions:
  1. Store path to file on server
  2. Store in BLOB field
I preferred second way because then I can compare raw data to see are attachments same, but I dont know how to get this from message, there are too many content field, different encodings ...
How you would do this?

Sorry for my bad English, thx for help
Mar 24, 2013 at 11:31 PM
You can get raw data by Data property of MailMessage object.

using (ImapClient cl = new ImapClient("", 993, "", "your_password"))
cl.Ssl = true;
if (cl.Authenticate() == true)
    ImapFolder r = cl.SelectFolder("Your_Folder_Name");
    var mg = cl.GetMessage(1);
    String text = mg.Data;

Does it fulfill your requirement?
Mar 25, 2013 at 8:52 PM
Only way that I know to get attachment from message is this:
foreach (MailContent ct in mg.Contents)
                                if (ct.ContentDisposition.FileName != "")
                                    String filePath = @"C:\posta\" + ct.ContentDisposition.FileName;
data property contains all headers of mail, body text and data from attachments mark with part xxx -------------------------
Is there way to take only attachment without parsing it.
Then I can store it and later assing to another message.
Thx for reply.
Mar 26, 2013 at 2:31 AM
You can copy data to MemoryStream.

MemoryStream mm = new MemoryStream();
ct.DecodeData(mm, false);
var bb = mm.ToArray();