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

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.

getSubject()}", PHP_EOL; echo "Body: {$message->getMessageBody()}", PHP_EOL; }">
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
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
An IMAP library for PHP

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 500 Dec 25, 2022
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
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
SendPortal - Open-source self-hosted email marketing, subscriber and list management, email campaigns and more

SendPortal includes subscriber and list management, email campaigns, message tracking, reports and multiple workspaces/domains in a modern, flexible and scalable application.

Mettle 1.2k Jan 4, 2023
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Laravel Verify New Email Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When

Protone Media 300 Dec 30, 2022
Magento 2 Email Catcher or Email Logger Module.

Magento 2 Module Experius email catcher / - logger

Experius 49 Dec 16, 2021
Cross-language email validation. Backed by a database of over 38 000 throwable email domains.

Cross-language temporary (disposable/throwaway) email detection library. Covers 38038+ fake email providers.

Francois-Guillaume Ribreau 1.4k Jan 9, 2023
Mail Api for fetch or send mails

flux-mail-api Mail Api for fetch or send mails Installation Native Download RUN (mkdir -p /%path%/libs/flux-mail-api && cd /%path%/libs/flux-mail-api

null 2 Dec 12, 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
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
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
Send email across all platforms using one interface

Send email across all platforms using one interface. Table Of Content Requirements Installation Providers AmazonSES Mailgun Mailjet Mandrill Postmark

Omnimail 329 Dec 30, 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
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
Mail sending module for Mezzio and Laminas MVC with support for file attachment and template email composition

This module provides an easy and flexible way to send emails from Mezzio and Laminas MVC applications (formerly known as Zend Expressive and Zend MVC). It allows you to pre-configure emails and transports, and then send those emails at runtime.

null 82 Jan 16, 2022
Omnisend: Ecommerce Email Marketing and SMS Platform

Omnisend Omnisend: Ecommerce Email Marketing and SMS Platform Version v1.x Support all PHP Version >=5.6 v2.x Support all PHP Version >=7.0 Installati

Hung Nguyen 3 Jan 6, 2022