Failed to read attachments using ImapX library (wrong count)

Topics: Issues
Jul 1, 2013 at 3:23 PM
When i am reading attachments it is displaying wrong count of attachments..if the email has only one attachment, i will get the output as 3. please someone help me to solve this,,
This is the code i use to get attachments..

// Getting the Attachments and insert into the database
                    List<ImapX.Attachment> attachmentList = message.Attachments;
                    if (attachmentList.Count > 0)
                    {
                        foreach (var attachment in attachmentList)
                        {
                            Model.Attachments myAttachment = new Model.Attachments();

                            myAttachment.MessageId = myMails;

                            myAttachment.AttachmentName = attachment.FileName;
                            myAttachment.AttachmentEncodings = attachment.FileEncoding;
                            myAttachment.BinaryData = attachment.FileData;
                            myAttachment.FileType = attachment.FileType;
                            myAttachment.FileSize = attachment.FileSize;
                            myAttachment.MailSubject = myMails.MailSubject;
                            myAttachment.MailUser = myMails;
                            myAttachment.FolderName = myMails;


                            // Insert Mails Into Mails table code gores here
                            bool resultAttachment = mailsToDb.insertIntoAttachmentTable(myAttachment);
                            if (resultAttachment)
                            {

                            }
                        }
Coordinator
Jul 1, 2013 at 7:45 PM
Edited Jul 1, 2013 at 7:45 PM
Hi tharush,

in order to fix this issue I need the original message with all the body parts.

Can you connect to your account using the sample application and export the message that gets parsed wrong? (use the context menu on the message, it has an "Export for report" option).

I'd like to ask you sending me the report file being generated to p13a92@googlemail.com , so I can take a look at it and provide a fix.


Best regards,

Pavel Azanov
Jul 1, 2013 at 8:52 PM
Edited Jul 1, 2013 at 8:53 PM
Hi pavel, Thnkz for the reply :)

In this case i will process the message two times,
                                                 foreach (ImapX.Message msg in m)
                                                {
                                                    //bool sucess = msg.Process();
                                                    int mesgId = msg.MessageUid;


                                                    DataTable dtSpecMail = searchFromDb.searchSpecificMailsContentForSync(mesgId, gFolderName, userName);
                                                    if (dtSpecMail != null)
                                                    {                             

purpose of the first time process is to retrieve the message flags, for the Second time i will process the mesage "bool sucess = msg.Process();" when i insert the message to the database, So i comment the first time process and run, then i got correct output for attachments,
Coordinator
Jul 2, 2013 at 7:16 AM
Hi tharush,

awesome! Happy you figured out what the problem was.
Jul 4, 2013 at 3:03 PM
hi pavel_azanov

Thnkz. :) But now i want to move message to a different folder, for that this is the code i use, But this is always return false. :(

ImapX.FolderCollection gmailFolders = null;
            try
            {
                gmailFolders = new FolderCollection();
                gmailFolders = client.Folders;

            }
            catch (Exception)
            {
            }

            ImapX.MessageCollection mNew = null;
            string uid = "UID " + msgId;

            try
            {
                mNew = new MessageCollection();
                mNew = client.Folders[oldFolderName].Search(uid, true);
            }
            catch (ImapException ex)
            {
                Mouse.OverrideCursor = Cursors.Arrow;
                MessageBox.Show("In rule " + ex.Message);
            }

            if (mNew != null)
            {
                if (mNew.Count > 0)
                {
                    foreach (var msg in mNew)
                    {
                        bool bol = msg.Process();
                        if (!moveMailFolderName.Equals(""))
                        {
                            Folder fromFolder = gmailFolders[oldFolderName];
                            Folder toFolder = gmailFolders[moveMailFolderName];

                         __ bool s = fromFolder.MoveMessageToFolder(msg, toFolder);__
                            if (s)
                            {
                                Mouse.OverrideCursor = Cursors.Arrow;
                                DashBoardProject.RetriveMails.GUI_M.MessageWindow msgWindow = new MessageWindow("Information", "Sucessfully Moved to " + moveMailFolderName + " Folder", "pack://application:,,,/Images/Muli/SendMail/infor.ico");
                                msgWindow.ShowDialog();
                            }
                        } 
Coordinator
Jul 5, 2013 at 8:13 AM
Edited Jul 5, 2013 at 8:15 AM
Hi tharush,

are you sure you move the messages to a folder that can contain messages? Can you try doing this using the sample application? It has an option to move messages to another folder. (use message contex tmenu)

Greets,

Pavel