How to mark IMAP message as fetched? - imap

I am working on PHP project that should fetch emails from IMAP server, and store them in local database.
Same IMAP server can be used by other email clients, like outbox and so on.
The problem is how to know which messages I already fetched, and which I didn't? I am thinking to use search by datetime, but is it reliable(I would have cronjob, that would access user mail box every minute, and check for emails, but not sure if datetime can cause some issues, for example in case when at almost same time arrive short message and message with big attachment).
I was thinking about system tags, but user can modify them via email client, so I can rely on them, and don't want to modify them and confuse client.
Next I was thinking about custom tags, but not all IMAP servers support them(and our software need to be flexible as much as possible).
Any good idea how I could solve this problem?

Keep track of the currently highest synced UID of the folder you are syncing, and verify that the UIDVALIDITY value of the folder match.
Unique identifiers are assigned in a strictly ascending fashion in the mailbox; as each message is added to the mailbox it is assigned a higher UID than the message(s) which were added previously. Unlike message sequence numbers, unique identifiers are not necessarily contiguous.

Related

Mandrill personalized message to recipients with same email

In a NodeJs app I'm using Mandrill to send email reminders to people signed up to different kind of events. Every five minutes the app check for ready reminders and send these. The number or reminders can vary from zero to many at every check.
But here comes the problems:
If for example 3 ready reminder are found at a certain check, and two of these have the same recipient (same email), but different merge_vars because they are about different events. When sent only one (the first found?) set of merge_vars will be used to both of these recipients.
So, how do I keep unique merge_vars even to multiple recipients with the same email? I guess i could split duplicated email adresses into several different calls. But I would really like to do one call, and send one array of recipients. Is it possible?
At this time, Mandrill uses email addresses as a unique identifier for merge vars in API calls, so it's only possible to provide one set of merge values for an email address, even if you've specified that address multiple times in the messages.to parameter. If you have multiple unique emails to send to the same recipient, that should be handled in separate API calls at this time.
I found an easier workaround than multiple API calls, and confirmed it works. Append a unique identifier to each email address using the "+" symbol. Then multiple emails to the same person will technically be to different email addresses, so Mandrill's merge fields will work correctly. e.g.
example+event1#example.com
example+event2#example.com
example+event3#example.com
All three of these will be delivered with the correct merging to example#example.com, and the recipient can even filter by the exact addresses if they wish when searching for the messages later.
(I am having the same issue now in 2019, so assume the original problem hasn't been fixed on Mandrill.)
Edit: The above method will not work with #yahoo.com recipients, as they don't support sub-addressing. The emails will bounce as if the address doesn't exist. (I consider that a problem with Yahoo, not the answer, since it's standard. But anyway, if you are emailing a group with a lot of yahoos... erm, yahoo.com emails I mean, then this method won't help.)

Handling spam in JIRA

I have enabled email to Ticket feature of JIRA and any message sent to abc#company.com becomes an issue.
This is working as expected.
But there are times when I get several junk tickets from a single email address. I guess it creates separate tickets for each line in that mail. I do not know how a single message can create hundreds of tickets in Jira. Is there any way to stop it? Is it possible to filter out junk emails? I do not want to restrict it to the domain of company.com
We put a postfix server in front of JIRA together with a spam filter (there are a couple available)
if this doesn't suffice, you might
receive messages into an 'inbox' project.
when processing the messages you move it to the right project if appropriate.

Can an email be printed as soon as it enters the Inbox?

We are working on an online food ordering application. When the user orders something from any restaurant, an email is sent to the restaurant's email address mentioning the order details. However, our client wants that an order print out should be generated automatically as soon as a new order is received.
Is it feasible using ROR? If not, any alternate solution to the problem?
When my group wrote something like this we went a little lower tech, and had the system generate a fax and send it to a fax machine at the restaurant. Of course, that's mainly because this was a system working across many restaurants, with disparate IT infrastructures, and the one thing they had in common was each had a fax machine.
I would figure this could be done in 1 of two ways:
1- Outlook event-- Outlook has the ability to set up 'rules', one of which I think allows printing.
2- Create a script that runs every few minutes, checks the email (either through IMAP, or POP, depending on the account), and prints all of them out.
See this: http://ruby.about.com/od/tasks/a/pop3.htm for info on how to check POP3 mail with ruby on rails.
For printing, the links mentioned here seem useful: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/504a616bf3e28057/ff6cb91462dfe961?pli=1
Ensure that you have 'from' or 'subject' filters setup, otherwise there will be a lot of spam printing.
You can use software to print your order automatically when email is received, it supports also print attachment like pdf, word, etc...
It is used by a lot of restaurant to print online order:
http://www.automatic-email-manager.com/

How can I filter then modify emails using IMAP?

I have asked this question in a different post here on SO:
How can a read receipt be suppressed?
I have been doing some research of my own to try and solve this problem and accessing the email account via IMAP seems like it is going to be a good solution. I have successfully been able to access my own inbox and mark messages as read with no issue.
I have been asked to perform the same task on an inbox that contains over 23,000 emails. I would like to run the test on a small amount of emails from that inbox before letting the whole 23,000 get it.
Here is the code I have been running via telnet:
LOGIN user#mailserver.com password
SELECT Inbox
STORE 1:* flags \Seen 'this line marks all the emails as read
So my question is, how can I execute that STORE command on a specific group of emails ... say emails that are going to / coming from a specific account? Is there a way to concatenate the commands like a FETCH then the STORE? Or is there a better way to go about getting a collection of emails based on certain criteria and then modifying ONLY those emails that can be accomplished through IMAP?
Take a look at the IMAP SEARCH command. The syntax is really awful, but it'll let you search for recipients or senders, for certain words in the subject or the body of messages. It will give you a list of message ids and you can use those message ids in your call to STORE.

Newsletter: How is it possible to determine how many people opened the e-mail?

Exact duplicate of Is there a way to determine whether an e-mail reaches its destination?
Hi all,
I heard that it's possible to determine how many people opened a newsletter and analyze WHEN they opened the mail.
I just wanted to know how that's possible... is it necessary to generate a "read confirmation" or is such an analysis possible without letting the recipient know?
Thanks a lot for your input...
See also Is there a way to determine whether an e-mail reaches its destination?, my answer repeated below:
If you make the email HTML based, you
can include images in it which contain
URLs with information unique to the
recipient. You could structure your
application so that these URLs trigger
some code to mark that particular
email as read before returning the
required image data.
To be totally effective, the images
would have to form a key part of the
email, so that the recipient has to
make their email client grab the
images. You could also make the plain
text part of the email just contain a
URL to retrieve the full message,
again allowing you to track receipt.
How far you take these ideas depends on why you need to know it's been read
and to what extent you want to
potentially annoy the recipient with
an email they can't cut'n'paste, read
easily on mobile device, listen to
with a screenreader, etc...
There is no way to guarantee that someone has opened your newsletter e-mail. But you can get a clue of how many time it was opened by embedding a one pixel image in you mail and use the statistics of you web server to determine how often it was requested.

Resources