Access only current portion of email - php

I am using the imap_xxxx functions to read the emails body. My problem is to find out only the current portion of the email body not the complete email. When user reply for an email it not only contains the his response but the complete mail chain. I know that facebook does it (or may be many other sites also) but how...

Related

Sending webforms: envelope sender not allowed

I have a website with a webform which users can use to contact a company. The webform internally creates an email in PHP using PHPMailer and is sending this email via SMTP to the company.
The company has a customer-management-system which identifies the user by looking at the sender of the email. Which means I couldn't send the email from the form from "form#example.com" to "customer-relations#example.com", but need to send it from "customeremail#customerdomain.com" to "customer-relations#example.com".
This worked for some years now, but since some time, we get the error-message:
"envelope sender not allowed customeremail#customerdomain.com"
for example from emails from #gmail.com. Other domains still work.
I understand that it is not good practice to "fake" the sender of the email to make the identification of the customer-management-system work. The developer of the customer-management-systems are not able to offer a solution yet (no comment on that...), so perhaps there are any ideas here which we could try to make this work?

php imap: can't see actual recipient if bcc

I'm working with PHP IMAP functions to poll an inbox and process the emails. Sometimes the emails are received via bcc -- this email was bcc'd by the sender. I need to be able to retrieve the actual email bcc'd -- but imap_fetchheader and imap_rfc822_parse_headers don't provide that if the recipient is bcc'd (even though it's in the return spec).
The issue is that I'm using plus addressing (myemail+value#domain.com) as part of my script, so it's not sufficient to know the email landed in my inbox -- I need to know the specific version of the address it was emailed to.
I understand the whole purpose of bcc is to be hidden. But I would think that there should be something in the header of the bcc-recipient to indicate the email was sent to them.
The "bcc address" that message is sent to is not part of the message itself, it is part of the message exchange protocol. It is used on the protocol level of smtp whilst handing over the message to the receiving server. The content that is handed over, so the message payload itself, is something different. There is no way to read that address from a received message by means of a protocol like imap4 or pop3. You'd have to scan and parse the smtp servers log files for that.
You can easily check that yourself: open the source code of a message received. So the original, technical payload including everything. That looks ugly, but it shows all information actually contained in the data. You will not see any mentioning of "bcc" or a "bcc address" in there.

Retrieving forwarded original email message

Is there a way to retrieve original body of the email that was forwarded without writing your own parser?
People will forward suitable emails to our service and we will have to parse some information from those emails.
The problem is that every email provider/client marks forwarded part differently: gmail marks with "--- Forwarded Message ---", outlook just adds "from:..., to:..., subject:..." part before the forwarded message and so on.
There is no such a special entity like a "forwarded email".
It is just an ordinary email that a particular email client decorated in some arbitrary way and sent to someone.
Based on what I've stated above - there is no a generic solution, since a "forwarded message" may be composed any way the client wants.

Know if email was a reply using IMAP in PHP

I am not sure if it is in the headers or not, but I am looking for a way to tell if an email I receive is a response to an email I sent, and if so, to only grab the new text, not "quoted text"
A little background: I am creating a script that will send out emails automatically. I am creating a cron job to run at periodic intervals to check to see if there were any replies. If there were replies, I only want to grab the new stuff, and not the old stuff.
In the past, I would send out emails with the id in the subject (You have a new response [1234]), and would then check the subject for the stuff in between the [ and ]. Then I would grab all the message and store it since every web browser/email uses a different character or style for quoted-text. Some do ">" some do a horizontal rule, some do absolutely nothing.
Anyways, I am just looking for something in the email header that would indicate they are replying and what the new text might be. If it's not possible, I will just keep on doing what I am doing.
You can know if an email is the reply of another email or not by using the combination of In-Reply-To and References.
Every email has a unique ID in its header called Message-ID, according to this RFC 1, you can track the ancestors of any email.
I have checked it and it is working in all clients (Outlook, Thunderbird)
I will give an example to use.
1- In the header of the email you send for the first time, you (your mail server or you in code) send an ID (Message-ID), if you open source of the email you will see it like this in top section:
... // You (your code) send:
Message-ID: <1#your-domain-mandatory.com>
...
You just need to keep this Message-ID in your program. any subsequent reply will refer to this ID.
2- Client will reply email 1 to you. Client will send a crucial header for you to tell you for which email this reply is in addition to its own Message-ID.
... // Client(Thunderbird) send:
Message-ID: <2#your-domain-mandatory.com>
In-Reply-To: <1#your-domain-mandatory.com>
...
When you receive the second email, it will be easy for you to keep track of the previous email you have sent because the ID of mail(1) is in the In-Reply-To header of the mail(2).
3- if you want to reply back this email again inside your code, you just need to put the Message-ID of the mail(2) in In-Reply-To header and Message-ID of mail(1) and mail(2) in References header. So the client will understand the chain correctly.
... // You (your code) send:
Message-ID: <3#your-domain-mandatory.com>
In-Reply-To: <2#your-domain-mandatory.com>
References: <1#your-domain-mandatory.com> <2#your-domain-mandatory.com>
...
By this header, you are telling the client that this email is a reply to the mail(2) and the ancestors are mail(1) and mail(2).
I have worked with them and read about them and it is working, my problem now is to just get the text of the last email and not the quoted text from the replies. (we are running our own Ticketing system, we create a comment for each email)
Unfortunately, e-mail clients can essentially do whatever they want with your message, and there is no reliable standard for determining how a received message originated at the client. In addition, IMAP doesn't really have anything to do with it. E-mails can be sent a number of different ways, including webmail.
The best you can do is look for an ID number in the subject line (assuming folks don't change it, which they rarely do). You can also do what Google does... fuzzy match the reply text to e-mail you sent to that address. If it matches, consider it part of the reply. This takes great effort though.

Reply to thread via email

I am writing an app to let users reply to a post or thread straight from their email similar to Facebook. Users can already add new posts via email and it is working fine.
When a new post is generated an email alert is sent to specific users and a unique reply address is created containing an encoded string with the original post/thread ID. This is working fine. The emails are sent and the system picks up the reply using the unique reply address.
My problem is trying to isolate the comment/reply in the email, from the quoted original email underneath. Here is an example of an email body received:
reply text
(Origional Email Header)On 10 March 2011 16:35, Example SIte
<pwKVb1BVUITY4Ai-fKR8ioPrR8Zki9cKBmAA0njXi8Y#example.us= > wrote:
I have thought of using identifying characters or strings but each email provider displays the original email in a reply differently.
Does anyone have any ideas how I can isolate the reply text from the original email's header and body?
Thank you,
Chris.
For a support ticket system I wrote, I focused on using the References email header concatenating previous message ids onto that. Many systems will hold onto that, but, of course, not all. Plus, my system is organic, ie, attempts to process emails with any subject and body in less of a controlled environment. A work in progress.
Since different email servers are going to format headers differently in replies, I don't think there is any way to reliably catch all of them. But if you're dealing with a relatively small number of users, you can just use regex matching to catch some of the most common header formats and strip those.

Categories