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.
Related
I'm trying to run an MQTT broker and I want to store the published data, but I need to know which user sent the message so I can store payload for each user and study them later. The problem is when two different user try to publish message on same topic I can not tell whose data it is. Is there a way to figure out the publisher of a message? I'm using Mosquitto btw.
Short answer, you don't.
MQTT messages do not contain any information about the user or client that sent it, unless you choose to encode it in the message (as part of the payload for v3.x or alternatively in the header properties for v5.0)
Longer answer:
Some MQTT brokers have plugin APIs that may allow you access to more meta data for a message. You may be able to write a plugin that will take the message + the meta data and then store them. Last time I looked, mosquitto's plugin API was only for writing authentication plugins, and did not give access to the messages themselves. But a different broker may allow this.
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).
I'm trying to implement a webmail in PHP. I would like to write a PHP CLI script which is run on every email arrival to store some parts of (not all of) incoming email into database for search purposes. Then when the user finished searching and chose an email to show, a connection is made to mail server to retrieve the complete email. In order to implement this scenario I need to make some sort of connection among emails within database and mail server.
Since my knowledge of working with mail servers is limited to Zend Framework's API, what I believe I need in order to retrieve an email from an IMAP server is a message number or a message unique id (this later one seems not to be supported by all mail servers).
To this point, I've managed to find .forward (and some other ways) to introduce my PHP CLI script to MTAs to be run on every email arrival. This way I can store emails to database. But this won't do since message unique id is created by MDA so MTA do not know of it and they can not provide it to me. This means I can not find emails later when I want to retrieve them from mail server.
At last, here's my question: Is there a way to introduce a PHP CLI script to a MDA for emails' arrival? If this is dependent on the mail server, which servers do support this and how? My personal choice would be Dovecot or Courier, but any other mail server would do as well.
This is tricky -- there are many ways on how to setup delivery. Some of them work with the underlying mail store directly, bypassing your IMAP server altogether, while others use e.g. Dovecot's facilities.
Have you considered building on top of the notify plugin which ships with Dovecot?
It seems like it's impossible to introduce such a PHP CLI script to IMAP server (at least I'm sure of Dovecot). Anyway, the work around I found for this problem is to use my own PHP script to insert the new mails into IMAP server and retrieve their id's and then store the id in database for future references. To be clear, email are given to my PHP CLI script by MTA, not MDA. As I said before this is done easily using .forward file.
[UPDATE]
Unfortunately it seems this solution can not be implemented as well. The way to insert a new email to IMAP server is APPEND command, and to have the UID of the recently added mail server must support UIDPLUS extension. Neither Dovecot nor Courier supports this extension at the moment! If they did it seems the server would return the UID with a APPENDUID response.
[UPDATE]
It is my bad since Courier does support UIDPLUS. So this solution is valid and the one I'm going to implement.
I am retrieving emails using synapse in delphi, but the messages are being deleted from the server. How can I retrieve the message without deleting it? Maybe the header only?
Thanks,
Joe
Are you sure emails are deleted, but you do not used pop3.Dele(i)?
I use POP3 with SSL and if I want to delete message then I had to use pop3.Dele(i). In Synapse wiki: http://synapse.ararat.cz/doku.php/public:howto:pop3samplessl there is my sample code to receive POP3 messages.
Maybe you use other protocol than POP3 then show us your code.
I have no hands-on experience with Synapse, but looking at the code (sourceforge trunk) you should be fine as long as you don't explicitly call the Dele method (which maps onto the DELE POP3 command). None of the other methods seems to delete the messages, including List and Retr.
How exactly are you retrieving those messages? Could you show some code?
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.