开发者

Lumisoft IMAP attachment saved 0 bytes

开发者 https://www.devze.com 2023-03-22 05:32 出处:网络
I am trying to save an attachment via IMAP protocol in .NET c#, using Lumisoft library. The problem is that 开发者_如何学编程the file is downloaded and can be saved, but it\'s filesize is 0B.

I am trying to save an attachment via IMAP protocol in .NET c#, using Lumisoft library. The problem is that 开发者_如何学编程the file is downloaded and can be saved, but it's filesize is 0B.

Attachment is fetched by IMAP_Fetch_DataItem_Rfc822(). Variable mail is message parsed from stream: var mail = Mail_Message.ParseFromStream(stream);

foreach (var att in mail.Attachments)
{
  if (att.ContentType.Type == "image")
  { 
    try
    {
      var fPath = Path.Combine(dirPath, att.ContentType.Param_Name);
      if (!File.Exists(fPath))
      {
        Stream data = ((MIME_b_SinglepartBase)att.Body).GetDataStream();

        using (FileStream fs = File.Create(fPath))
        {
           LumiSoft.Net.Net_Utils.StreamCopy(data, fs, 4096);
        }  
     }
   Console.WriteLine("Storing image attachment into: " + fPath);

 ...


You need to close Stream data:

Stream data = ((MIME_b_SinglepartBase)att.Body).GetDataStream();
using (FileStream fs = File.Create(fPath))
{
       LumiSoft.Net.Net_Utils.StreamCopy(data, fs, 4096);
}
data.Close(); // missing close
...


It seems that the Lumisoft parser did not decode attachment correctly. Are you sure the attachment size after download is more that zero?

LumiSoft unfortunately is pretty buggy, you may consider using commercial alternative, here's my product: http://www.lesnikowski.com/mail/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号