Giter Site home page Giter Site logo

geerlingguy / imap Goto Github PK

View Code? Open in Web Editor NEW
59.0 9.0 34.0 50 KB

Simple wrapper class for PHP's IMAP-related email functions.

Home Page: https://packagist.org/packages/geerlingguy/imap

License: MIT License

PHP 100.00%
php imap php-imap wrapper library packagist email mail

imap's Introduction

imap's People

Contributors

flash2over avatar geerlingguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imap's Issues

Don't use short tags

Woah, PHP short tags! (<?). It's been a while since I've seen you...

Those need to go. Already spent about half an hour debugging problem on live site when I realized the silly short tags were causing problems with PHP > 5.3.x.

Add method to clean up reply message bodies

I've had this need more than once in different mail-handling applications: I want to strip out extra email messages below a reply message body. For example, consider an email like:

Here's my reply to your message!

On Sep. 20, 2012, Jeff Geerling wrote:
> This is the original message.
>
> -Jeff

I want to remove the message below the 'On Sep. 20' line, at least, so I'm adding a new method, cleanReplyEmail(), which will implement a regex solution to remove any line beginning with a >. This method is mentioned here: http://stackoverflow.com/a/12611562/100134

There doesn't seem to be an easier method, unfortunately.

Use PSR-0 naming conventions

To allow Imap to be used with other applications more easily, I think I'll start using namespaces in my PHP libraries. I'm going to use JJG as the vendor (as I do for other languages).

Fatal error: Class 'Imap' not found

Fatal error: Class 'Imap' not found in /home/beezides/public_html/script_location on line 57

My code is here-

                        include("vp-includes/Imap.php");

                        if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                                $user = $row['email'];
                                $pass = $row['pass'];
                                $host = $row['host'];
                                $port = 993;
                                $ssl = 'ssl';
                                $folder = 'INBOX';
                            }
                        }

                        $mailbox = new Imap($host, $user, $pass, $port, $ssl, $folder);
                        $mailbox->getMailboxInfo();

Fatal error: Class 'JJG\Exception' not found in Imap.php on line 64

cool code. good work. not using ssl. any tips?
i upgraded to php 5.6
thank you
code is
include 'Imap.php';
$host = "localhost";
$user= "user";
$pass= "pass";
$port= "143";
$folder = "INBOX";

use \JJG\Imap as Imap;
$mailbox = new Imap($host, $user, $pass, $port, $folder);
$mailbox->getMailboxInfo();`

Fatal error: Class 'JJG\Exception' not found in Imap.php on line 64

also tried
$ssl = "false"; and $ssl = false;
$mailbox = new Imap($host, $user, $pass, $port, $ssl, $folder);

Detect Auto-Responders (Out of Office)

One of the most annoying things in the world is a system that pulls in the myriad of annoying and silly autoresponses from (almost always) Outlook. IMO, people should just forget about adding out of office replies, and others should simply presume that the person they emailed is either away or dead if they don't get a response within a few days.

Anyways, as it is, I have to deal with autoresponders, and they should, presumably, send back an 'Auto-Submitted' header in the email (see this answer on Stack Exchange). However, I've never gone deep into this area, so I need to do some research and see how the out of office replies work from different clients.

Here are some interesting tidbits I found when looking up various solutions to the autoresponder/vacation/away/out-of-office problem:

  • One of the methods for detection used by Exim: http://wiki.exim.org/EximAutoReply#Example_2 โ€” they seem to simply run a message's headers through a bunch of searches, and if any keywords are found, they mark the message accordingly.
  • (MailChimp built ReplyTo)[http://blog.mailchimp.com/introducing-replyto-omg-make-the-auto-replies-go-away/] to help people handle responses, but it's in private beta (as of this writing).
  • Microsoft has proposed an X-Auto-Response-Suppress header to indicate to mail servers whether the email should be responded to. See (X-Auto-Response-Suppress documentation)[http://msdn.microsoft.com/en-us/library/ee219609(v=exchg.80).aspx]. (Exchange, btw, also only sends one out-of-office reply per email sender... so that's a nice non-proliferation tool, at least).
  • CampaignMonitor has a (blog post)[http://www.campaignmonitor.com/blog/post/3677/handling-email-campaign-bounce-backs-and-autoreplies] with guidelines for handling bounces and out-of-office replies (more for end-users).
  • Joss Crowcroft heralds the (death of the no-reply box)[http://www.josscrowcroft.com/2011/random/death-to-the-noreply-mailbox/](and makes some good points!).

Better 7BIT message decoding

Right now, some messages that PHP IMAP passes through with 7BIT encoding still have characters like =A0 and = all over the place. Other messages are actually base64-encoded, and need decoding.

I'm adding some simple/manual rules and loops in the currently-empty decode7Bit() method to detect any bits of encoding and decode them properly.

Clean up code, change method names, normalize methods

Now that I'm using this class in an application, I'm finding that there are a few more quirks that need ironing out. For one, I need to list all mailboxes in the account, so I've added a getMailboxInfo() method to list all mailboxes by name.

I've also renamed the mailbox methods to getMailboxInfo() and getCurrentMailboxInfo().

I've also conformed to a more CRUD-style naming convention for messages: you can getMessage() and 'deleteMessage()` now.

I've also fixed the README file with updated method names.

Squelch warnings about 'Sequence out of range (errflg=2)'

I'm getting errors like:

Notice: Unknown: Sequence out of range (errflg=2) in main() (line of ).

This happens whenever I check for new messages and there are none. Which is quite annoying, in my logs :)

It looks like there's an open issue to add a note about this warning, but it's not documented yet in the PHP docs. Took me a while to track down the cause of the issue.

Handle 'From To Date Subject' blocks in cleanReplyEmail

Many emails from Yahoo web mail seem to have the following block of text above replies, which should be cut out (along with anything below, probably), as the emails also don't include > for quoted text...

From: [Sender]
To: [Person]
Sent: Tue, October 2, 2012 7:14:08 AM
Subject: [Subject here]

Automatically decode Base64 body text

It's annoying to have to detect Base64-encoded text in all the messages. Therefore, our getMessage() method should do this automatically, if the body is Base64...

Random Cleanups

I've been working on a bunch of little tweaks and fixes over the past few days while using the class on a live site. I'll post these in a commit to this issue.

Add method to move message into different mailbox

One of the main missing features I just noticed is the ability to move messages into different boxes. Right now, you can read and delete messages, but you can't move them into another box (for archival, sorting, etc.).

This will hopefully be pretty simple.

Clearing Error Stack to Remove Notices on error reporting

How come you don't call imap_errors() on your thrown exception instead of imap_last_error()?

I had an issue with notices being thrown because that doesn't clear the error stack like imap_errors() does. I hope i didn't miss something, what do you think?

More code cleanup - two spaces

Since I've changed probably 80% of the original forked repo, I might as well go the full length and apply Drupal coding standards to everything, including whitespace.

I'm going to switch from four to two spaces. Note that this is not in full compliance with PSR-1, but it's mostly there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.