An IMAP library for PHP

Related tags

Email Fetch
Overview

Fetch Build Status

License Latest Stable Version Coverage Status Total Downloads

Fetch is a library for reading email and attachments, primarily using the POP and IMAP protocols.

Installing

N.b. A note on Ubuntu 14.04 (probably other Debian-based / Apt managed systems), the install of php5-imap does not enable the extension for CLI (possibly others as well), which can cause composer to report fetch requires ext-imap

sudo ln -s /etc/php5/mods-available/imap.ini /etc/php5/cli/conf.d/30-imap.ini

Composer

Installing Fetch can be done through a variety of methods, although Composer is recommended.

Until Fetch reaches a stable API with version 1.0 it is recommended that you review changes before even Minor updates, although bug fixes will always be backwards compatible.

"require": {
  "tedivm/fetch": "0.7.*"
}

Pear

Fetch is also available through Pear.

$ pear channel-discover pear.tedivm.com
$ pear install tedivm/Fetch

Github

Releases of Fetch are available on Github.

Sample Usage

This is just a simple code to show how to access messages by using Fetch. It uses Fetch own autoload, but it can (and should be, if applicable) replaced with the one generated by composer.

use Fetch\Server;
use Fetch\Message;

$server = new Server('imap.example.com', 993);
$server->setAuthentication('username', 'password');

/** @var Message[] $message */
$messages = $server->getMessages();

foreach ($messages as $message) {
    echo "Subject: {$message->getSubject()}", PHP_EOL;
    echo "Body: {$message->getMessageBody()}", PHP_EOL;
}

License

Fetch is licensed under the BSD License. See the LICENSE file for details.

Comments
  •  iconv(): Detected an illegal character in input string

    iconv(): Detected an illegal character in input string

    Hello, on some messages I get this notice:

    ErrorException [ Notice ]: iconv(): Detected an illegal character in input string APPPATH/vendor/tedivm/fetch/src/Fetch/Message.php @ line 421:

    I debuged thesemessages, I see that the values during error are: $parameters['charset'] = utf-8; self::$charset = UTF-8//TRANSLIT;

    Any idea on how to fix it?

    opened by huglester 48
  • Check to see if message is already encoded in utf8

    Check to see if message is already encoded in utf8

    Adding requirement to if statement to check if message matches UTF-8 encoding via regex. This will prevent encoding errors when converting UTF-8 to UTF-8.

    opened by ghost 13
  • On returning HTML and plain text message bodies

    On returning HTML and plain text message bodies

    I notice Fetch will always return an HTML or plain text body when requested, even if the original message doesn't actually contain an HTML or plain text version. I have a need where I actually want to only return the HTML and/or plain text if the original message included it. Of course, I can extend Fetch for my needs, but it feels like this might be a general enough use that others would benefit. I'm happy to fork it, code it up (backwards-compatible, of course), and issue a pull request if you like, but I wanted to see if that's even something you want Fetch to do before I did anything.

    opened by kevinsmith 13
  • imap_savebody issue on Windows

    imap_savebody issue on Windows

    Method \Fetch\Attachment\saveAs, this line (about 221, latest pull):

    $result = imap_savebody($this->imapStream, $filePointer, $this->messageId, $this->partId ?: 1, FT_UID);

    ...on Windows (PHP 5.4.30 with XDebug, Apache 2.2.18) makes PHP crash. When the code reaches this line, the execution suddenly stops. No, errors, no lines in error.log, no HTTP status returned.

    This is obviously not related to Fetch code, but I could bypass this problem by inserting a line like this (before the one with imap_savebody):

    $temp = imap_fetchbody($this->imapStream, $this->messageId, $this->partId ?: 1, FT_UID);

    Would it be possible to put something like this in the next pull?

    Calling imap_fetchbody before imap_savebody seems to solve this strange issue. Here I read something about imap_fetchbody and Apache that crashes: http://www.tek-tips.com/viewthread.cfm?qid=1574115

    Thank you for your attention.

    opened by eleftrik 8
  • Implemented getting messages in an ordered fashion

    Implemented getting messages in an ordered fashion

    Hi,

    Thanks for a nice lib.

    I needed a way to get the newest messages in a folder, so I implemented this.

    Usage:

    $server->getOrdered(SORTDATE, true, 2); # => returns the 2 newest messages
    

    All the best.

    opened by nulpunkt 8
  • Dependency requirement (ext-imap) breaks Composer udpate

    Dependency requirement (ext-imap) breaks Composer udpate

    Hi,

    Commit 9334952ad2140ba08b81d3b525349709ac7e632d introduced the requirement for the PHP imap extension.

    Unfortunately, this makes composer update fail (I do have php5-imap installed on my Ubuntu):

    $ composer update
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - tedivm/fetch dev-master requires ext-imap * -> the requested PHP extension imap is missing from your system.
        - tedivm/fetch dev-master requires ext-imap * -> the requested PHP extension imap is missing from your system.
        - Installation request for tedivm/fetch dev-master -> satisfiable by tedivm/fetch[dev-master].
    

    Apparently, the same problem (where a commit enforces this dependency and breaks compsoer update) appeared in the past: https://github.com/tedious/Fetch/issues/28

    Thanks!

    opened by gredin 7
  • Making the sender address easily accessibly through Message::getAddresses

    Making the sender address easily accessibly through Message::getAddresses

    This patch makes fetching the sender address (as sent in the Sender header, or otherwise derived from the From header) easily accessibly through Message::getAddresses('sender').

    opened by AaronVanGeffen 7
  • option to specify FT_PEEK

    option to specify FT_PEEK

    currently, fetching messages automatically marks them as read. this is not always desirable behavior and there's currently no way to change this.

    it would be helpful to either add the option (FT_PEEK) flag to getMessages() or something similar.

    i think it makes sense to actually have it on by default.

    thanks!

    opened by leeoniya 6
  • Add utf8_encode to messageBody for utf8 conversion.

    Add utf8_encode to messageBody for utf8 conversion.

    I was having trouble with fetching messages due to an illegal character when it was running the iconv() function.

    [Symfony\Component\Debug\Exception\ContextErrorException]                                                                                  
      Notice: iconv(): Detected an illegal character in input string in /var/www/sites/cems2/vendor/tedivm/fetch/src/Fetch/Message.php line 430  
    

    Since the purpose of using iconv() in this circumstance appears to be to convert it from its existing character set to utf-8, encoding the messageBody with utf8_encode() seemed appropriate. All tests and builds passed for me locally.

    opened by haydenk 6
  • [WIP] Decode MIME-encoded subject and addresses

    [WIP] Decode MIME-encoded subject and addresses

    Haven't added tests for this yet (for the life of me, I can't get the Fetch test suite running), but in my real-world experience, these methods for decoding a message's subject and addresses have worked flawlessly.

    If you can help me get the test suite running, I'm happy to write tests for these.

    opened by kevinsmith 6
  • Proposal - Middleware

    Proposal - Middleware

    Hey! What would you think of adopting a "middleware" approach that would allow developers to add in middleware to messaging parsing.

    For example, it would be nice to have a middleware which handled the UTF-8 encoding of the subject, html and plaintext email. Another middleware might be to attempt to clean HTML emails, which often come with a lot of useless cruft which makes displaying an html email in the browser difficult.

    This helps in situations where more encoding or extra parsing is required by business logic. (You can likely wrap your business logic over/around this class, but the middleware approach makes for some interesting abilities).

    Some middleware ("core middleware"?) could be created by extracting current functionalities such as encoding and other things which aren't strictly email related functionalities (potentially allowing you to clear that code out from being "hard coded" into the email classes).

    Let me know what you think! (I can take constructive criticism :D )

    opened by fideloper 6
  • ErrorException: imap_savebody(): stream filter (convert.base64-decode): invalid byte sequence

    ErrorException: imap_savebody(): stream filter (convert.base64-decode): invalid byte sequence

    I have the following code

    $attachments = $message->getAttachments();

    $attachmentPath = "storage path";

    foreach ($attachments as $attachment) { $attachment->saveToDirectory($attachmentPath); }

    Now and then when I call saveToDirectory method I get the following error ErrorException: imap_savebody(): stream filter (convert.base64-decode): invalid byte sequence

    I can't solve the problem

    opened by Magnificent-Big-J 1
  • IMAP TLS on 143 with Plain Auth

    IMAP TLS on 143 with Plain Auth

    Hello,

    I have a case where I need to connect to a server running on port 143, with TLS and Plain U/P authentication I've modded the code to use TLS on 143, but not sure how to go about the Plain auth

    public function setAuthentication($username, $password, $tryFasterAuth=true) { $this->username = $username; $this->password = $password; if ($tryFasterAuth) { $this->setParam('DISABLE_AUTHENTICATOR', array('GSSAPI','NTLM')); } }

    Any suggestions please? Any way I can log verbatim errors to see what's going on?

    Thanks

    opened by julianmd 0
  • Unable to add multiple flags

    Unable to add multiple flags

    I'm trying to set two flags to connect to a shared inbox. However when I use following commands, Only one flag get set.

    $server = new Server($config->mailserver->host, $config->mailserver->port);
    $server->setAuthentication(USER_NAME, PASSWORD);
    $server->setFlag("authuser", "[email protected]");
    $server->setFlag("user", "[email protected]");
    

    The server string comes as {outlook.office365.com:993/ssl/[email protected]}

    The string I suppose to get is {outlook.office365.com:993/ssl/[email protected]/[email protected]}

    looks like this issue is caused by following piece of code in function setFlag() .

    $match = preg_grep('/' . $flag . '/', $this->flags);
    if (reset($match)) {
          $this->flags[key($match)] = $flag . '=' . $value;
    } else {
          $this->flags[] = $flag . '=' . $value;
    }
    

    Any idea?

    opened by vajiralasantha 1
  • Change setFileName() method from protected to public

    Change setFileName() method from protected to public

    If I want to change a filename of attachment, I must change method setFileName() visibility to public. I think that this method should be public defaultly.

    opened by kycaPL 0
Releases(v0.7.2)
  • v0.7.2(Nov 12, 2022)

    What's Changed

    • Minor fixes by @sergeyklay in https://github.com/tedious/Fetch/pull/185

    New Contributors

    • @sergeyklay made their first contribution in https://github.com/tedious/Fetch/pull/185

    Full Changelog: https://github.com/tedious/Fetch/compare/v0.7.1...v0.7.2

    Source code(tar.gz)
    Source code(zip)
  • v0.7.1(Aug 2, 2015)

  • v0.6.1(Jan 8, 2015)

    This update has a lot of bug fixes and optimizations, particularly around character encoding, that have been submitted by over a dozen contributors. This release also contains two new functions- listMailboxes and getOrderedMessages.

    Source code(tar.gz)
    Source code(zip)
  • v0.5.3(Mar 14, 2014)

    This release fixes some issues with the test suite when running through vagrant (the biggest being bugs with the automatic creation and resetting of the staging suite). It also enhances how Fetch handles certain types of encoding.

    Source code(tar.gz)
    Source code(zip)
  • v0.5.2(Jan 20, 2014)

    This update has no changes to Fetch itself, but does have an affect on it's test suite. The purpose of this update is to remove the Dovecot email setup out of the main package and into it's own development package. This will reduce the size of the production install of Fetch while also allowing other libraries to take advantage of the Dovecot/Vagrant/Travis email setup code.

    Source code(tar.gz)
    Source code(zip)
  • v0.5.1(Dec 19, 2013)

    With this latest release comes a whole new test suite, bringing the code coverage of the product from almost none to over 90%!

    This update represents a new life for Fetch. Previously it had been very difficult to manage external contributions, as testing was a mostly manually process. With new technology like Vagrant and Travis-CI things have become a lot easier. The new test suite sets up an actual IMAP server and populates it with preprepared emails.

    This is the first of many new updates, as Fetch will be getting a reworked API as well as some additional features. This update is backwards compatible with previous versions in order to provide a fully tested baseline.

    Source code(tar.gz)
    Source code(zip)
  • v0.4.5(Dec 1, 2013)

  • v0.4.4(Jul 28, 2013)

  • v0.4.3(Jul 14, 2013)

Owner
Tedious Developments
Libraries That Prevent Boredom
Tedious Developments
IMAP Library for PHP

IMAP Library for PHP Description PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled.

null 157 Jan 7, 2023
Fetch is a library for reading email and attachments, primarily using the POP and IMAP protocols

Fetch Fetch is a library for reading email and attachments, primarily using the POP and IMAP protocols. Installing N.b. A note on Ubuntu 14.04 (probab

Tedious Developments 501 Jan 4, 2023
Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)

PHP IMAP Initially released in December 2012, the PHP IMAP Mailbox is a powerful and open source library to connect to a mailbox by POP3, IMAP and NNT

Sergey 1.5k Jan 3, 2023
An AngularJS / Laravel app - Keyword Based Email forwarder | read/write emails through IMAP

@MailTree Simple mail forwarder. Based on the specific email body/subject keywords forward mails to the list of predefined users. Install Imap Install

Dren Kajmakchi 4 Aug 21, 2018
EmailReplyParser is a PHP library for parsing plain text email content, based on GitHub's email_reply_parser library written in Ruby

EmailReplyParser EmailReplyParser is a PHP library for parsing plain text email content, based on GitHub's email_reply_parser library written in Ruby.

William Durand 606 Dec 8, 2022
The classic email sending library for PHP

PHPMailer – A full-featured email creation and transfer class for PHP Features Probably the world's most popular code for sending email from PHP! Used

PHPMailer 19k Jan 1, 2023
PHP library for parsing plain text email content.

EmailReplyParser EmailReplyParser is a PHP library for parsing plain text email content, based on GitHub's email_reply_parser library written in Ruby.

William Durand 606 Dec 8, 2022
Small PHP library to valid email addresses using a number of methods.

Email Validator Small PHP library to valid email addresses using a number of methods. Features Validates email address Checks for example domains (e.g

James Jackson 154 Dec 31, 2022
📧 Handy email creation and transfer library for PHP with both text and MIME-compliant support.

?? Handy email creation and transfer library for PHP with both text and MIME-compliant support.

Nette Foundation 401 Dec 22, 2022
Library for using online Email providers

Stampie Stampie have been moved to the "Flint" organization in order to get a better collaborative flow. Stampie is a simple API Wrapper for different

Henrik Bjørnskov 32 Oct 7, 2020
Library for using online Email providers

Stampie Stampie is a simple API Wrapper for different email providers such as Postmark and SendGrid. It is very easy to use and to integrate into your

Stampie 288 Dec 31, 2022
Provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice

WP PHPMailer provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice.

Itineris Limited 61 Dec 6, 2022
This application (class) does the sending of emails used in the phpmailer library

emailsender - PHP Notification library via email using phpMailer This library has the function of sending email using the phpmailer library. Doing thi

Lucas Alcantara Rodrigues Volpati 1 Feb 9, 2022
Comprehensive mailing tools for PHP

Swift Mailer Swift Mailer is a component based mailing solution for PHP. It is released under the MIT license. Swift Mailer is highly object-oriented

Swiftmailer 9.6k Dec 29, 2022
Bounce Mail Handler for PHP | This is a "reboot" of PHPMailer-BMH from WorxWare.

PHP 7.0+ Support Composer & PSR-0 Support PHPUnit testing via Travis CI (TODO: more tests needed) PHP-Quality testing via SensioLabsInsight (TODO: mor

Lars Moelleken 43 Jan 7, 2023
Cypht: Lightweight Open Source webmail written in PHP and JavaScript

All your E-mail, from all your accounts, in one place. Cypht is not your father's webmail. Unless you are one of my daughters, in which case it is your father's webmail. Cypht is like a news reader, but for E-mail. Cypht does not replace your existing accounts - it combines them into one. And it's also a news reader.

Jason Munro 773 Dec 30, 2022
Crud PHP 8 com Form E-mail

Crud com PHP 8 PDO Login - Cadastro de Usuários - Edição - Deleção - Adição | Formulário envio de e-mail Para rodar o Crud é preciso instalar um servi

Isaias Oliveira 4 Nov 16, 2021
PHPMailer – A full-featured email creation and transfer class for PHP

PHPMailer – A full-featured email creation and transfer class for PHP Features Probably the world's most popular code for sending email from PHP! Used

PHPMailer 19.1k Jan 2, 2023
A ready-to-use PHP script for sending Emails with an HTML Template will use a Gmail account as the sender and you will not need any email server. Powered by PHPMailer.

Gmail Email Sender by PHP A ready-to-use PHP script for sending Emails with an HTML Template will use a Gmail account as the sender and you will not n

Max Base 4 Oct 29, 2022