This project is read-only.

How i can clear IEnumerable<ImapX.Messages>?

Topics: Help requests
Jan 26, 2016 at 9:45 AM
Hi,
I downloaded all the messages and checked their attachment . They are filling RAM. I am called that code in threads.
Image
using (var client = new ImapClient(hostname, true))
                        {
                            if (client.Connect( /* optional, use parameters here */ ))
                            {
                                // connection successful
                                if (client.Login(login, pass))
                                {
                                    // login successful
                                    FolderCollection folders = client.Folders;
                                    int i = 0;
                                    foreach (Folder myfolder in folders)
                                    {

                                        var messages = client.Folders[i].Search("ALL");
                                        i++;
                                        foreach (var message in messages)
                                        {
                                            var attachments = message.Attachments;
                                            if (attachments.Count() > 0)
                                                if (!Directory.Exists(folder + @"\" + login))
                                                {
                                                    DirectoryInfo di = Directory.CreateDirectory(folder + @"\" + login);// Try to create the directory.
                                                }
                                            foreach (var attachment in attachments)
                                            {
                                                attachment.Download();
                                                attachment.Save(folder + @"\" + login);
                                            }
                                        }

                                        GC.Collect();
                                    }
                                }
                            }
                            client.Disconnect();
                            client.Dispose();
                        }
Coordinator
Jan 27, 2016 at 12:00 PM
Hi Ivan,

currently there is no reliable way to clear the messages collection. I will provide an update shortly which will add a new method to the MessageCollection class.

Greets,

Pavel