Quantcast
Channel: imapx Discussions Rss Feed
Viewing all 1144 articles
Browse latest View live

New Post: How to use the folder.Search() method?

$
0
0
It looks like ImapX's Search() method takes a query string that you have to provide yourself, which means you'll have to do a bit of reading up on the IMAP SEARCH syntax:

https://tools.ietf.org/html/rfc3501#page-49

There are IMAP extensions that provide more SEARCH options as well.

For MailKit, I ended up implementing a SearchQuery class that helps construct these queries without needing to know the IMAP SEARCH syntax. Maybe something like that could be added to ImapX.

To use your first set of search criteria as an example:
// let's search for all messages received between 2015-01-01 and 2015-01-31
var query = SearchQuery.DeliveredAfter (DateTime.Parse ("2015-01-01"))
    .And (SearchQuery.DeliveredBefore (DateTime.Parse ("2015-01-31")));

foreach (var uid in inbox.Search (query)) {
    var message = inbox.GetMessage (uid);
    Console.WriteLine ("[match] {0}: {1}", uid, message.Subject);
}
You can even sort them:
// let's do the same search, but this time sort them in reverse arrival order
var orderBy = new [] { OrderBy.ReverseArrival };
foreach (var uid in inbox.Search (query, orderBy)) {
    var message = inbox.GetMessage (uid);
    Console.WriteLine ("[match] {0}: {1}", uid, message.Subject);
}

// you'll notice that the orderBy argument is an array... this is because you
// can actually sort the search results based on multiple columns:
orderBy = new [] { OrderBy.ReverseArrival, OrderBy.Subject };
foreach (var uid in inbox.Search (query, orderBy)) {
    var message = inbox.GetMessage (uid);
    Console.WriteLine ("[match] {0}: {1}", uid, message.Subject);
}
Hopefully this gives Pavel some good ideas :)

New Post: How to use the folder.Search() method?

$
0
0
This is how you'd make the the particular queries you asked for in ImapX:
folder.Search ("AND SINCE \"1-Jan-2015\" BEFORE \"31-Jan-2015\"");
folder.Search ("SUBJECT \"Blah\"");
folder.Search ("FROM \"BillBob@gmail.com\"");
The DateTime.ToString() format you want to use for the dates is "d-MMM-yyyy", since I'm sure you'll want that info.

Hope that helps.

New Post: Adding a letter into the folder

$
0
0
How can i add a letter into the folder(Sent,for example).I wrote code,looking just like this snippet 'imapClient.Folder.Sent.AppendMessage(message);',but the folder was still empty.

New Post: Adding a letter into the folder

$
0
0
Looking into the source code for AppendMessage(), it appears that the logic is broken if the message contains non-ascii text in the 8bit encoding (it should work fine if the 8bit text is base64 or quoted-printable encoded) or if the message has raw 8bit text in the headers because it will incorrectly calculate the length of the literal that it will be sending in the APPEND command.

I'm not sure if this is the issue you are having or not.

This doesn't appear to be a trivial bug to fix because each mime part of the message could potentially be defined to use a different charset so the code can't simply be fixed to use Encoding.UTF8.GetBytes() to get a proper byte-count.

I would expect you to get an exception in that case, though, rather than no errors at all.

To rule out the possibility of a server bug, maybe you could try using my MailKit library to write a quick sample test to see if that works.
using (var client = new ImapClient (new ProtocolLogger ("imap.log"))) {
    client.Connect (hostName, port, useSsl);
    client.Authenticate (userName, password);

    IMailFolder sent;
    if (client.Capabilities.HasFlag (ImapCapabilities.XList) || client.Capabilities.HasFlag (ImapCapabilities.SpecialUse)) {
        // the IMAP server can tell us which folder is the Sent folder
        sent = client.GetFolder (SpecialFolder.Sent);
    } else {
        // the IMAP server has no idea which folder is the Sent folder, it is client-specific
        var personal = client.GetFolder (client.PersonalNamespaces[0]);
        sent = personal.GetSubfolder ("Sent Mail"); // or whatever the name of the folder is on your server
    }

    sent.Append (message);

    client.Disconnect (true);
}
If that doesn't work, you'll be able to look at the imap.log file to see exactly what commands were sent to the IMAP server and hopefully use that to figure out the problem (or email me and I can take a look at it).

Hopefully that helps.

New Post: Mail properties are null

$
0
0
I managed to read mails using your library incl. body & attachments but basic mail properties (subject, from, to) are all null on the mail object. I initialize the client with following behaviors:

_mailclient = new ImapClient
            {
                Behavior =
                {
                    AutoPopulateFolderMessages = true,
                    MessageFetchMode = MessageFetchMode.Full,
                    AutoDownloadBodyOnAccess = true,
                    RequestedHeaders = new[] { "Message-Id" }
                }
            };

New Post: Mail properties are null

$
0
0
The ImapX maintainer seems like he might be really swamped at work again because he's been pretty quiet on these forums the past few months, so I've been trying to help answer questions. Unfortunately, I'm not very familiar with ImapX internals so I can't really help answer your particular question regarding ImapX, however, I wrote my own IMAP library called MailKit that I'd be able to help you with if you need answers right away.

My email address is listed on my github page and I'd be happy to answer any questions you have if you decide to try MailKit, otherwise, hopefully someone else will chime in with a solution for you.

Good luck!

New Post: Mail properties are null

$
0
0
Thanks Jeff,

MailKit is unfortunately not an option as we need .Net 3.5 support.

I have evaluated couple libraries both open source and licensed software, and have decided to use Mail.dll from limilabs.com

Br,
Ahmet


New Post: How get all messages from all folders?

$
0
0
Hi,
i am using the latest build of ImapX, and i wanted to get messages and attachments from all folders

That is my code, i can get all folders, but messages not. How to get messages?
if (client.Login(login, pass))
                {
                    // login successful
                    FolderCollection folders = client.Folders;
                    foreach (Folder myfolder in folders)
                    {

                        var messages = myfolder.Messages;

                        foreach (var message in messages)
                        {
                            MessageBox.Show(message.Subject);
                            var attachments = message.Attachments;
                            if (attachments.Count() > 0)
                                foreach (var attachment in attachments)
                                {
                                    MessageBox.Show(attachment.FileName);
                                }
                        }
                    }
                }

New Post: How i can clear IEnumerable?

$
0
0
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();
                        }

New Post: How get all messages from all folders?

$
0
0
Hi Ivan,

there are multiple ways for fetching the messages.

You can configure the client to always fetch the messages once you access Messages:
client.Behavior.AutoPopulateFolderMessages = true; 
This is not a good practice as it gets you less control about what and how you download. A better way is to use the Download or Search method:
/* .. Init client, authenticate .. */        
/* .. folder = any folder .. */  
folder.Messages.Download(/* optional, add filter, change download mode, limit number of messages */)
/* .. Init client, authenticate .. */        
/* .. folder = any folder .. */  
var messages = folder.Search(/* optional, add filter, change download mode, limit number of messages */)
More details can be found in the documentation:
Greets,

Pavel

New Post: How i can clear IEnumerable?

$
0
0
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

New Post: How to read the Message-ID property from an email?

$
0
0
Hi mattslay,

you can use the Message.MessageId property.

Greets,

Pavel

New Post: Process leaks memory. Am I using ImapX incorrectly?

$
0
0
When I tried to run application with this code
client.Behavior.MessageFetchMode = MessageFetchMode.Headers;
client.Behavior.AutoPopulateFolderMessages = true; 

ImapX.Folder myInbox = client.Folders.Inbox;

foreach (ImapX.Message currentMessage in myInbox.Messages)
{
    currentMessage.Download(MessageFetchMode.Full, false);
    //...............
    foreach (Attachment file in currentMessage.Attachments)
    {
        try
        {
            string curFileName = getFreeFileName(file.FileName);
            file.Save(AttachesStoragePath, curFileName);
            //.............................
        }
        catch (Exception ex)
        {
            //.............................
        }
    }
    saveMailMessageToDb(UID, From, Subject, Date, filenamesList, AttachesStoragePath, Body, errorsList);
}
it fills more and more memory, and not release it in the end. If there's too many messages at a mail server, process throws outOfMemory exception.

New Post: the attachment.Download method delete the attachment content

$
0
0
Hello,

this is the issue I'm facing with (2.0.0.18)

my message has 2 attachments. I can see the message and the attachments [0] and [1].

the attachment [1] is a XML file (att.FileSize = 1025)

After performing the download method, the FileSize becomes 0, so I cannot access to the file:
GetString(att.FileData) returns a zero length string and
Save(<path>, <filename>) saves a zero length file..

any advice ? Please it is urgent.

thanks
francesco

New Post: the attachment.Download method delete the attachment content

$
0
0
same happens with the attachment [0]

sample code (VB)
    For Each att As ImapX.Attachment In m.Attachments

                ' before the download, FileSize > 0 
                att.Download()

                ' now, FileSize = 0

                att.Save("c:\_myfolder", att.FileName)    ' save an empty file
                daticert = System.Text.Encoding.Default.GetString(att.FileData)   ' return an empty string

    Next
please help me :)
francesco

New Post: How to properly generates a Reply message from a message received from IMapX

$
0
0
Hi There,

Thank you alot for your awesome library.

I've a simple need, I just want to generate a Reply message from a message I've retrieved by IMapX.

So that it can be properly associated to a Thread and displayed as this in GMail for instance.

a) I tried to send the reply with "Re: + Blah" in subject -> No Success (considered as a separate conversation)
b) I tries to send the reply by appending with the body of the message I wanna reply to -> No Success

How can I proceed ?

Thanks

New Post: How to properly generates a Reply message from a message received from IMapX

$
0
0
There are a few things you'll need to do when constructing a reply:
  1. In the reply message, you'll want to prefix the Subject header with "Re: " if the prefix doesn't already exist in the message you are replying to (in other words, if you are replying to a message with a Subject of "Re: party tomorrow night!", you would not prefix it with another "Re: ").
  2. You will want to set the reply message's In-Reply-To header to the value of the Message-Id header in the original message.
  3. You will want to copy the original message's References header into the reply message's References header and then append the original message's Message-Id header.
That should make GMail and all other mail software properly thread your message.

New Post: How to properly generates a Reply message from a message received from IMapX

$
0
0
Thank you jstedfast,

This works pretty well!

Anyway, I'm wondering how to append with the message history in the body as Gmail or Outlook does.

I suppose, I'll need to manage that manually, dealing with HTML or plain text. Generating '>' at the beginning of each line and properly generates header Send By blah blah...

Any tip on that ?

New Post: How to properly generates a Reply message from a message received from IMapX

$
0
0
Right, you can just do something like this:
var quoted = new StringBuilder ();
using (var reader = new StringReader (text)) {
    string line;

    while ((line = reader.ReadLine ()) != null) {
        quoted.Append ("> ");
        quoted.AppendLine (line);
    }
}

New Post: How to properly generates a Reply message from a message received from IMapX

Viewing all 1144 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>