For those of you familiar with IMAP - If I retrieve a draft message (or any message for that matter), and I wish to update it / edit it, what commands should I use?
The only command i've come across is Append, which appears to only insert, meaning I would have to delete the previous draft from the mailbox?
IMAP is designed for server-side management of mailboxes, not for editing messages. So yes, you would have to retrieve the contents of the desired message (FETCH), then delete that message from the server (STORE a \Deleted flag on the message and then EXPUNGE deleted messages), and then upload the updated message to the server (APPEND). There are no IMAP commands for editing the contents of an existing message, only for updating flags related to existing messages (STORE).
Remy's answer is correct. On top of that, you could optimize the process a bit if the server supports the CATENATE extension via APPEND CATENATE (so that you could save yourself uploading the existing attachments, etc).
Related
Using: Delphi XE2, latest Indy snapshot from SVN (10.6.0.4997)
In the case of IMAP there are 2 properties - UID and MsgID which can be used to uniquely identify a message in a mailbox.
I'm writing an email client, and need to know which is the more reliable or recommended of the two to store everytime the client connects and retrieves the message list.
What sequence of steps are needed to check for new emails? I'm specifically looking for the correct sequence and set of Indy IdIMAP4 commands to get new emails.
Unlike POP3/SMTP, IMAP defines flags on emails. The TIdMessage.Flags property has mfRecent and mfSeen flags available (amongst others). Your client can look for emails that have mfRecent set on them, then update the flags on the server to clear mfRecent and set mfSeen as needed.
I am dealing with a bad connection to an external IMAP server. I need my application to download messages from this mail server periodically. On many occasions, my code has already downloaded message using javamail and has executed message.getContent and is then processing individual body parts (attachments). While it is in the process of doing this, the connection can drop.
I need to thus make sure that messages are not marked as SEEN automatically on doing message.getContent, which is how Javamail behaves, as described in this reply here:
https://stackoverflow.com/a/7679091/303106
Is there any way to make sure messages that were not downloaded are not marked as SEEN?
Message msg = ...;
((IMAPMessage)msg).setPeek(true);
Yes, use the BODY.PEEK instead of just BODY when fetching the data, and/or use EXAMINE instead of SELECT to open a mailbox. I'll leave it as an excercise to the reader to read the javamail's documentation to see how these options relate to the features provided by the havamail.
What's the best general technique for creating an IMAP client and keeping its local message store in sync with the server?
I guess I'm looking for the right way to figure out what's changed in an IMAP folder on the server since the last time I checked, and download those changes, to persist them to my local database... This would include messages no longer in the folder (deleted or moved), new messages, and changed messages...
I guess new messages is easy, I can grab the highest UID i have for a folder and then find messages since that UID. I'm not so sure about detecting messages that were deleted or moved though, or changed (maybe some flags changed on a message).
Thanks!
For sync, probably you need each folder all messages UID and flags.
You can compare local cached UIDs to server returned, with this you can dedect new messages and deleted(
Probably you should use some kind of hastable for search/compare, this will speed up all.
I would like to create an email client that can access multiple IMAP mailboxes. I'd also like a copy of all emails for processing. What is the best way to do this using IMAP commands?
Right now I have a script that iterates over the folders, FETCHing FLAGS on 1:* to see what's been read and if any previously read messages have been marked as new, then FETCH BODY.PEEK on all of the messages I don't have in my database. Is there a better way?
A better way would be to fetch UIDs of all messages (UID FETCH 1:* FLAGS), compare the resulting UID list with your database and then download any messages you don't have and remove any messages you have but the server doesn't (deleted by other IMAP clients or using a web interface, for example). This is the only reliable method to duplicate an IMAP folder, AFAIK.
(And don't forget to take UIDVALIDITY into account as well!)
Your original method would not work correctly if other IMAP clients were accessing the mailbox in addition to your application. In theory, it would work OK if you can stay connected to the IMAP server continuously, using NOOP and IDLE to check new and deleted messages, but this is never possible in practice - even GMail doesn't have 100% uptime :-)
An ultimate IMAP client would combine both these approaches.
I am writing a Lua script that works with IMAPfilter (http://imapfilter.hellug.gr/), that is able to change the names of MIME attachments
for example:
Content-Type: application/pdf;
name="Final Fäntäsy.pdf"
is converted to
Content-Type: application/pdf;
name="FinalFantasy.pdf"
Currently, this is done via exporting the mail to the file system and manipulating. My question is, can I manipulate the file directly on the IMAP server via IMAPfilter? I've checked the documentation, but haven't found anything for manipulating files on the server, beyond moving/deleting/etc.
According to the its description IMAPFilter issues search requests to the IMAP server and does something with the results (copy, fetch, delete etc.). In order to change the name/content type of the attachments you will need to fetch the message, parse it, make your corrections and append it back to the mailbox (and delete the original one).
IMAP does not support changing the content of mail messages in-place (so you can't for example fetch only the attachment part, change it and upload it back). APPEND command only works with a complete message, not any part of it.
I'm not familiar with that specific product, however, the IMAP protocol does not offer something like this.
In the IMAP world, you would have to fetch the message, modify your content, Append it back to the folder, and delete the original.