I'm using the PHP imap lib. I have no problems pulling e-mails and reading the plain body. ($mail->textPlain). However this takes the entire body (including the conversation/history). I want to filter the history and only keep the reply. I tried using regex and that works fine for Gmail but for other email clients it doens't work. Does someone knows a workaround or a library?
preg_replace('#(^\w.+:\n)?(^>.*(\n|$))+#mi', "", $mail->textPlain);
I'm aware that php imap does not provide a method for that but I'm want to know if there are libraries for it.
Related
So I have to build a browser extension that extracts all the emails with extensions. I am at a loss however, how to go about it. What I essentially need is for the extension to extract a list of emails with descriptions as to whether they have attachments with them.
Now I tried the gmail atom feed
but it only shows unread emails, and doesn't give a lot of information about the message either. Is there another method of doing it.
Is there like an API for gmail that allows all this to be done easily and seemlessly. I feel like I am missing something obvious. I know i am being vague here, but I really don't have clue how to do this.
It can be done using IMAP doing search for "has:attachment". Samples and description can be found under the following resource:
developers.google.com - Google Apps Platform - Google Developers
I know this is quite an old question but since this question was posted Google has released a
WEB API to work with gmail.
https://developers.google.com/gmail/api/
After searching for days on how to do this I came across this question:
Send email using the GMail SMTP server from a PHP page
Seems like exactly what I have been trying to achieve but I have had no success, maybe it's because I don't know how to do the HTML to work with this code?
for testing purposes I tried the code on the top voted question on the link I pasted and
made a button that when you click it, it would go to the PHP file (No success).
You can't do it with PHP only, because mail() doesn't support authentication. You have to use a mailing library.
I recommend SwiftMailer which is easy to use, supports many features (authentication, sending HTML mails, attachments, etc.), and is well documented.
You also need to send over tsl/ssl which is why your mail function is not working.
Solution with tsl/ssl already exists here: Using php's swiftmailer with gmail
Check http://neo22s.com/send-email-using-gmail-and-php/ and http://webcodingeasy.com/PHP-API039s/Send-email-from-Gmail-using-PHP
I am currently using Zend_Mail_Storage_Imap to read email messages using IMAP. I am able to read the email body (text and html) thanks to the documentation.
Now I'm trying to figure out how to save email attachments. I can't find anything that explains how to convert the raw content and save the attachments. How can I do this?
Try these:
http://macfoo.wordpress.com/2009/06/10/save-an-email-attachment-using-zend-mail/
http://www.electrictoolbox.com/function-extract-email-attachments-php-imap/
I found that reading emails using Zend_Mail can be a little buggy. Sometimes not all of the attachment files are recognized or in some cases imap can't even decode the body of the email .
We're using Sendgrid service to parse emails now, and it's working pretty well. They have a special api to decode emails. on the downside, it cost money, but I prefer better results.
I am trying to integrate IMAP email processing with another in house system that bases what it uses off of the subject line / email content.
We need to be able to change the text of the subject line before moving the email to a new folder. What/where would be a good place to start?
I've had a look around and it IS possible in a manual sense, via a thunderbird plugin or using outlook. I just can't seem to find a relevant example in PHP, or any other language for that matter. I also hear the idea is flakey at best as you need to modify the email content and upload it back to the imap server.
The outlook implementation seems to delete the original and save a new one to your IMAP folder on the server.
Side note: Yes I know it is a weird requirement, and although forwarding the email to ourselves then moving it is our fall back plan it is not much liked as it moves original headers useful for things like reply-all.
Any suggestions appreciated.
PS If I'm blind and there is something obvious I'm missing in the manual let me know.
Do you already have any code built to handle the email processing? IMAP subject line information is stored as a header so you would need to utilize the PHP functions of imap_headerinfo() and/or imap_fetchheader() depending on the functionality you're looking for to achieve this. You could have PHP check each message header and if it matches X format, remove the message, and create a new one with the appropriately modified header information.
I am looking for a solution that will enable me to connect to a mailbox, obtain an email, apply specific modifications to the email body (for example, change the content), and then forward the newly modified email to a new email address.
The trick is that such modification must not destroy the format and headers of the original email and I must not lose any attachments that were in the original email.
The sort of manipulation that will be performed will need to be done by an external process that knows the logic of my application.
The solution I am looking for can be an external software that can invoke some API for processing the content of the emails, or even API by itself that my code will invoke.
Our solution is currently based on PHP, but any other solution is also acceptable.
I started working with the Zend Mail library but I am running into problem having to understand the inner-workings of email formats. I wouldn't want to start messing around with the mime objects in the email format. I only want to alter the textual content of the message and keep the rest untouched.
http://php.net/manual/en/book.imap.php - functions that let you manipulate email systems.
What mail server are you using? In qmail its easy to process any incomming email. You can put any script in any language to process the lines of the email.
If you have IMAP access to your server you can use the php IMAP lib. http://www.php.net/manual/en/book.imap.php
I wrote a library as part of a larger open source app that may help you a bit. Its an object orientated wrapper around the PHP imap functions and can be found at google code.
Unfortunately this doesn't do exactly what you want. What in the message are you trying to change? I may be possible to just grab a raw version and specifically search out what you want to change, ignoring the whole mimetype processing altogether, and then just send the whole message along again.
Resending the email is simple enough, and this (small tutorial)* on sending email with attachments can refresh you on the basics (although most of what is in there you can skip as the attachments and mimetypes will already be built).
* I can't post the link because my reputation isn't high enough for two links in a single post, so I'll add it in a comment.