Git Product home page Git Product logo

imap's Introduction

PHP IMAP library

Latest Stable Version Downloads Integrate Code Coverage

A PHP IMAP library to read and process e-mails over IMAP protocol, built with robust Object-Oriented architecture.

This library requires PHP >= 8.2 with IMAP, iconv and Multibyte String extensions installed.

Installation

The recommended way to install the IMAP library is through Composer:

$ composer require ddeboer/imap

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage

Connect and Authenticate

use Ddeboer\Imap\Server;

$server = new Server('imap.gmail.com');

// $connection is instance of \Ddeboer\Imap\Connection
$connection = $server->authenticate('my_username', 'my_password');

You can specify port, flags and parameters to the server:

$server = new Server(
    $hostname, // required
    $port,     // defaults to '993'
    $flags,    // defaults to '/imap/ssl/validate-cert'
    $parameters
);

Mailboxes

Retrieve mailboxes (also known as mail folders) from the mail server and iterate over them:

$mailboxes = $connection->getMailboxes();

foreach ($mailboxes as $mailbox) {
    // Skip container-only mailboxes
    // @see https://secure.php.net/manual/en/function.imap-getmailboxes.php
    if ($mailbox->getAttributes() & \LATT_NOSELECT) {
        continue;
    }

    // $mailbox is instance of \Ddeboer\Imap\Mailbox
    printf('Mailbox "%s" has %s messages', $mailbox->getName(), $mailbox->count());
}

Or retrieve a specific mailbox:

$mailbox = $connection->getMailbox('INBOX');

Delete a mailbox:

$connection->deleteMailbox($mailbox);

You can bulk set, or clear, any flag of mailbox messages (by UIDs):

$mailbox->setFlag('\\Seen \\Flagged', ['1:5', '7', '9']);
$mailbox->setFlag('\\Seen', '1,3,5,6:8');

$mailbox->clearFlag('\\Flagged', '1,3');

WARNING You must retrieve new Message instances in case of bulk modify flags to refresh the single Messages flags.

Messages

Retrieve messages (e-mails) from a mailbox and iterate over them:

$messages = $mailbox->getMessages();

foreach ($messages as $message) {
    // $message is instance of \Ddeboer\Imap\Message
}

To insert a new message (that just has been sent) into the Sent mailbox and flag it as seen:

$mailbox = $connection->getMailbox('Sent');
$mailbox->addMessage($messageMIME, '\\Seen');

Note that the message should be a string at MIME format (as described in the RFC2045).

Searching for Messages

use Ddeboer\Imap\SearchExpression;
use Ddeboer\Imap\Search\Email\To;
use Ddeboer\Imap\Search\Text\Body;

$search = new SearchExpression();
$search->addCondition(new To('[email protected]'));
$search->addCondition(new Body('contents'));

$messages = $mailbox->getMessages($search);

WARNING We are currently unable to have both spaces and double-quotes escaped together. Only spaces are currently escaped correctly. You can use Ddeboer\Imap\Search\RawExpression to write the complete search condition by yourself.

Messages can also be retrieved sorted as per imap_sort function:

$today = new DateTimeImmutable();
$thirtyDaysAgo = $today->sub(new DateInterval('P30D'));

$messages = $mailbox->getMessages(
    new Ddeboer\Imap\Search\Date\Since($thirtyDaysAgo),
    \SORTDATE, // Sort criteria
    true // Descending order
);

Unknown search criterion: OR

Note that PHP imap library relies on the c-client library available at https://www.washington.edu/imap/ which doesn't fully support some IMAP4 search criteria like OR. If you want those unsupported criteria, you need to manually patch the latest version (imap-2007f of 23-Jul-2011 at the time of this commit) and recompile PHP onto your patched c-client library.

By the way most of the common search criteria are available and functioning, browse them in ./src/Search.

References:

  1. https://stackoverflow.com/questions/36356715/imap-search-unknown-search-criterion-or
  2. imap-2007f.tar.gz: ./src/c-client/mail.c and ./docs/internal.txt

Message Properties and Operations

Get message number and unique message id in the form <...>:

$message->getNumber();
$message->getId();

Get other message properties:

$message->getSubject();
$message->getFrom();    // Message\EmailAddress
$message->getTo();      // array of Message\EmailAddress
$message->getDate();    // DateTimeImmutable
$message->isAnswered();
$message->isDeleted();
$message->isDraft();
$message->isSeen();

Get message headers as a \Ddeboer\Imap\Message\Headers object:

$message->getHeaders();

Get message body as HTML or plain text (only first part):

$message->getBodyHtml();    // Content of text/html part, if present
$message->getBodyText();    // Content of text/plain part, if present

Get complete body (all parts):

$body = $message->getCompleteBodyHtml();    // Content of text/html part, if present
if ($body === null) { // If body is null, there are no HTML parts, so let's try getting the text body
    $body = $message->getCompleteBodyText();    // Content of text/plain part, if present
}

Reading the message body keeps the message as unseen. If you want to mark the message as seen:

$message->markAsSeen();

Or you can set, or clear, any flag:

$message->setFlag('\\Seen \\Flagged');
$message->clearFlag('\\Flagged');

Move a message to another mailbox:

$mailbox = $connection->getMailbox('another-mailbox');
$message->move($mailbox);

Deleting messages:

$mailbox->getMessage(1)->delete();
$mailbox->getMessage(2)->delete();
$connection->expunge();

Message Attachments

Get message attachments (both inline and attached) and iterate over them:

$attachments = $message->getAttachments();

foreach ($attachments as $attachment) {
    // $attachment is instance of \Ddeboer\Imap\Message\Attachment
}

Download a message attachment to a local file:

// getDecodedContent() decodes the attachment’s contents automatically:
file_put_contents(
    '/my/local/dir/' . $attachment->getFilename(),
    $attachment->getDecodedContent()
);

Embedded Messages

Check if attachment is embedded message and get it:

$attachments = $message->getAttachments();

foreach ($attachments as $attachment) {
    if ($attachment->isEmbeddedMessage()) {
        $embeddedMessage = $attachment->getEmbeddedMessage();
        // $embeddedMessage is instance of \Ddeboer\Imap\Message\EmbeddedMessage
    }
}

An EmbeddedMessage has the same API as a normal Message, apart from flags and operations like copy, move or delete.

Timeouts

The IMAP extension provides the imap_timeout function to adjust the timeout seconds for various operations.

However the extension's implementation doesn't link the functionality to a specific context or connection, instead they are global. So in order to not affect functionalities outside this library, we had to choose whether wrap every imap_* call around an optional user-provided timeout or leave this task to the user.

Because of the heterogeneous world of IMAP servers and the high complexity burden cost for such a little gain of the former, we chose the latter.

Mock the library

Mockability is granted by interfaces present for each API. Dig into MockabilityTest for an example of a mocked workflow.

Contributing: run the build locally

Docker is needed to run the build on your computer.

First command you need to run is make start-imap-server, which starts an IMAP server locally.

Then the local build can be triggered with a bare make.

When you finish the development, stop the local IMAP server with make stop-imap-server.

imap's People

Contributors

abhinavkumar940 avatar arwinvdv avatar boekkooi avatar burci avatar cabloo avatar daredzik avatar ddeboer avatar dependabot[bot] avatar flashws avatar jakubboucek avatar krzysiekpiasecki avatar leadtechvisas avatar mvar avatar nikoskip avatar oskarstark avatar particleflux avatar pedrofornaza avatar pepamartinec avatar pyatnitsev avatar racztiborzoltan avatar rsplithof avatar slamdunk avatar thelfensdrfer avatar tolstoydotcom avatar tomsommer avatar trizz avatar trungpv1601 avatar trungpv93 avatar wujku avatar xelan 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imap's Issues

EmailAddress::__toString() fails if there the sender/recipient name contains a colon

Consider following From: header of a message From: Something: Somewhere <[email protected]>. When this kind of message is read, PHP Catchable fatal error: Method Ddeboer\Imap\Message\EmailAddress::__toString() must return a string value is thrown.

It seems that PHP's native imap_headerinfo() parses this kind of address line incorrectly. When putting print_r($value) to the header parsing script vendor/ddeboer/imap/src/Message/Headers.php the output is:

Array
(
    [0] => stdClass Object
        (
            [mailbox] => Something
        )

    [1] => stdClass Object
        (
            [personal] => Somewhere
            [mailbox] => example
            [host] => example.com
        )

    [2] => stdClass Object
        (
        )

)

Installation problem

Hello,

I'm getting this problem when do a composer update

  Problem 1
    - Installation request for ddeboer/imap dev-master -> satisfiable by ddeboer/imap[dev-master].
    - ddeboer/imap dev-master requires ext-imap * -> the requested PHP extension imap is missing from your system.

I'm using MAMP PRO with PHP 7.0.3 and IMAP library is installed.

I'll appreciate any help.

$message->getAttachments() does not return anything, even though a message has at least one attachment

Hey

When calling getAttachments, i don't get anything back
Upon doing some research, i saw that the function getParts() is not returning the parts as instance of Message\Attachments, but the getAttachments() function is looking for that
Looking further in the getParts function i saw that my parts don't show up a disposition ( which is why the parts are returned as a Part instead of an Attachment instance )

Here's a gist with the array returned by parseStructure() for all the elements of my email:
https://gist.github.com/raulp/ce7236054284e751f713

Let me know if you need any other info ...
Thank you

delete messages

Is there a way to delete messages (or move them to another folder?)

imap_open with timeout

Would it be possible to setup a timeout on

$connection = $server->authenticate('my_username', 'my_password');

Sometimes (and no idea why) it takes too long to authenticate and I'd rather retry. How do I stop (and debug) php when doing imap_open. Code snippet from https://github.com/ddeboer/imap/blob/master/src/Server.php below:

    public function authenticate($username, $password)
    {
        // Wrap imap_open, which gives notices instead of exceptions
        set_error_handler(
            function ($nr, $message) use ($username) {
                throw new AuthenticationFailedException($username, $message);
            }
        );

        $resource = imap_open(
            $this->getServerString(),
            $username,
            $password,
            null,
            1,
            $this->parameters
        );

        if (false === $resource) {
            throw new AuthenticationFailedException($username);
        }

        restore_error_handler();

        $check = imap_check($resource);
        $mailbox = $check->Mailbox;
        $this->connection = substr($mailbox, 0, strpos($mailbox, '}')+1);

        // These are necessary to get rid of PHP throwing IMAP errors
        imap_errors();
        imap_alerts();

        return new Connection($resource, $this->connection);
    }

Subject and other texts are decoded incorrectly

Current result: test 123 ir lietuviškos raid�s
Expected: test 123 ir lietuviškos raidės

Possible solution (partly tested):

    /**
     * Decodes IMAP encoded string (RFC2047)
     *
     * @param string $string
     *
     * @return string
     */
    public function decodeImapString($string)
    {
        $result = array();
        $parts = imap_mime_header_decode($string);

        foreach ($parts as $part) {
            if ($part->charset == 'default') {
                $result[] = $part->text;
            } else {
                $result[] = mb_convert_encoding($part->text, 'UTF-8', $part->charset);
            }
        }

        return implode($result);
    }

This logic should be applied to header lines (including attachment names)

Email objects visibility

Right now I need to save the private properties of Ddeboer\Imap\Message\EmailAddress.
But I cannot access the object properties due the private attribution.
I know we can take the 'sender' key from header, but,
May we change the properties to public?

imap_open error

I have this error using on laravel:

Authentication failed for user xxxxxx with error imap_open() expects at most 5 parameters, 6 given

Add tests

How should we go about testing this library (preferably on Travis CI)? As much code in the library calls PHP’s \imap functions directly, mocking doesn't seem to make much sense.

Does anyone know of a fake IMAP server that we can use in unit tests? Or should we perhaps use a GMail test account for integration tests?

mb_convert_encoding breaks code

On this code

$messages = $mailbox->getMessages();

        foreach ($messages as $message) {
            // $message is instance of \Ddeboer\Imap\Message
            echo "\ngetting Message...";
            echo "\n".$message->getSubject();
        }

it breaks at a certain point...

getting Message...PHP Warning 'yii\base\ErrorException' with message 'mb_convert_encoding(): Unable to detect character encoding'
in /var/www/myhost.com/vendor/ddeboer/imap/src/Ddeboer/Imap/Message/Headers.php:20

// Decode subject, as it may be UTF-8 encoded
    if (isset($headers->subject)) {
        $subject = '';
        foreach (\imap_mime_header_decode($headers->subject) as $part) {
            // $part->charset can also be 'default', i.e. plain US-ASCII
            $charset = $part->charset == 'default' ? 'auto' : $part->charset;
            $subject .= \mb_convert_encoding($part->text, 'UTF-8', $charset);
        }
        $this->array['subject'] = $subject;
    }

File Attachments don't show up

Message::getAttachments() returns null.

However, the messages do have attachments. This behaviour was tested on messages sent from MS Outlook through MS Exchange, and from GMail through the web application.

Should iconv be a requirement?

I've just run into the below error:

PHP Fatal error:  Uncaught Ddeboer\Transcoder\Exception\ExtensionMissingException: iconv in /home/chris/Projects/Dashboard/vendor/ddeboer/transcoder/src/IconvTranscoder.php:16
Stack trace:
#0 /home/chris/Projects/Dashboard/vendor/ddeboer/transcoder/src/Transcoder.php(62): Ddeboer\Transcoder\IconvTranscoder->__construct('UTF-8')
#1 /home/chris/Projects/Dashboard/vendor/ddeboer/imap/src/Parameters.php(41): Ddeboer\Transcoder\Transcoder::create()
#2 /home/chris/Projects/Dashboard/vendor/ddeboer/imap/src/Parameters.php(20): Ddeboer\Imap\Parameters->decode('multipart_alter...')
#3 /home/chris/Projects/Dashboard/vendor/ddeboer/imap/src/Message/Part.php(236): Ddeboer\Imap\Parameters->add(Array)
#4 /home/chris/Projects/Dashboard/vendor/ddeboer/imap/src/Message.php(329): Ddeboer\Imap\Message\Part->parseStructure(Object(stdClass))
#5 /home/chris/Projects/Dashboard/vendor/ddeboer/imap/src/Message.php(34): Ddeboer\Imap\Message->loadStructure()
#6 /home/chris/Projects/Dashboard/vendor/ddeboer/imap/src/MessageIterator.php(29): Ddeboer\Imap\ in /home/chris/Projects/Dashboard/vendor/ddeboer/transcoder/src/IconvTranscoder.php on line 16
<?php
require "vendor/autoload.php";

use Ddeboer\Imap\Server;

$server = new Server('abc', 993);

$connection = $server->authenticate('abcxyz', 'abcxyz');

$inbox = $connection->getMailbox("INBOX");
$messages = $inbox->getMessages();

foreach ($messages as $message){
    echo $message->getSubject() . PHP_EOL;
}

KeepUnseen doen't work

Hi

$server = new Server($config['mail']['server'], 993, '/imap/ssl/novalidate-cert');
$connection = $server->authenticate($config['mail']['username'], $config['mail']['password']);

$mailboxes = $connection->getMailboxes();
$mailbox = $connection->getMailbox('INBOX');
if(isset($_GET['id'])){
    $message = $mailbox->getMessage($_GET['id']);
    $message->keepUnseen();
    $message->getSubject(); //etc
}

Really this message has flag seen
how i can add flag unseen and star to this message ?

Prevent setting SEEN flag

Is it possible to add option to not mark messages automatically as read. This can be useful if you want user to see little snippet of message text before open it f.e. It can be done by setting option FT_PEEK in imap_fetchbody function.

Iconv Exception

Hello,
I get the attachments from the mailbox's unread messages using $attachment->getDecodedContent() and I'm having some trouble with them. They are UTF-8 XML. The transcode method is causing an Exception on iconv function saying it has an illegal character.
https://github.com/ddeboer/imap/blob/master/src/Message/Part.php#L185-L188
I just changed this to:
https://github.com/darit/imap/blob/master/src/Message/Part.php#L185-L189
This change works fine for me.
darit@3ba77f1?diff=unified

encoding issue

sorry to post here, new using your lib, but got this and something related on how to atleast fix it: php-mime-mail-parser/php-mime-mail-parser#26

the bad part is that i got this exception while the message is being initialized, so no other operations can be performed on it (move delete), using getMessages() is not safe.

Encoding from ks_c_5601-1987' toUTF-8' is unsupported on this platform: iconv(): Wrong charset, conversion from ks_c_5601-1987' toUTF-8' is not allowed#0 [internal function]: Ddeboer\Transcoder\IconvTranscoder->Ddeboer\Transcoder{closure}(8, 'iconv(): Wrong ...', '/var/www/releas...', 38, Array)
#1 /vendor/ddeboer/transcoder/src/IconvTranscoder.php(38): iconv('ks_c_5601-1987', 'UTF-8', '[SUSPECTED SPAM...')

PHP Fatal error Failed to parse time string in ddeboer/imap/src/Message.php

Exception detected at line 385 in /var/www/app/test.php :
exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (Fri, 24 Jul 2015 20:36:59 -0-100 -0700) at position 33 (-): Double timezone specification' in /var/www/app/vendor/ddeboer/imap/src/Message/Headers.php:56
Stack trace:
#0 /var/www/app/vendor/ddeboer/imap/src/Message/Headers.php(56): DateTime->__construct('Fri, 24 Jul 201...')
#1 /var/www/app/vendor/ddeboer/imap/src/Message/Headers.php(23): Ddeboer\Imap\Message\Headers->parseHeader('date', 'Fri, 24 Jul 201...')
#2 /var/www/app/vendor/ddeboer/imap/src/Message.php(185): Ddeboer\Imap\Message\Headers->__construct(Object(stdClass))
#3 /var/www/app/vendor/ddeboer/imap/src/Message.php(56): Ddeboer\Imap\Message->getHeaders()
#4 /var/www/app/vendor/emailapi/inboxwatch/src/InboxWatch.php(383): Ddeboer\Imap\Message->getFrom()
#5 /var/www/app/test.php(44): MyApp->imap_retrieve()

Problem on production server

I've my system working fine on my dev machine but I've an issue on my prod server.

I've the same PHP version on both and I'm completely sure that authentication data is correct.

Imap extension it's installed and activated on both machines.

I receive this error on prod server:

[Ddeboer\Imap\Exception\AuthenticationFailedException]
  Authentication failed for user my_user with error imap_open(): Couldn't ope
  n stream {localhost:143}

I've tried to do a telnet localhost 143 and I can login without any problems.

Anybody know what's happening?

$message->getAttachments() doesn't recognize some attachments

Delivered-To: [email protected]
Received: by 10.202.195.68 with SMTP id t65csp871342oif;
        Sun, 15 Feb 2015 02:21:54 -0800 (PST)
X-Received: by 10.236.209.35 with SMTP id r23mr13006152yho.26.1423995713978;
        Sun, 15 Feb 2015 02:21:53 -0800 (PST)
Return-Path: <[email protected]>
Received: from mail-yk0-x245.google.com (mail-yk0-x245.google.com. [2607:f8b0:4002:c07::245])
        by mx.google.com with ESMTPS id h70si1767496yhq.9.2015.02.15.02.21.52
        for <[email protected]>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 15 Feb 2015 02:21:53 -0800 (PST)
Received-SPF: pass (google.com: domain of [email protected] designates 2607:f8b0:4002:c07::245 as permitted sender) client-ip=2607:f8b0:4002:c07::245;
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of [email protected] designates 2607:f8b0:4002:c07::245 as permitted sender) [email protected];
       dkim=pass [email protected]
Received: by mail-yk0-f197.google.com with SMTP id 19sf76654028ykq.0
        for <[email protected]>; Sun, 15 Feb 2015 02:21:52 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=yyy.cz; s=google;
        h=sender:mime-version:message-id:date:subject:from:to:content-type
         :content-disposition:content-transfer-encoding:x-original-sender
         :x-original-authentication-results:precedence:mailing-list:list-id
         :list-help:reply-to;
        bh=CplHfCqscVv63ZCvirQ+kOAnaGy+fQ75nMYfE7lYq9k=;
        b=DPypTwmlwUGYaPk2qqgJqjKDY8Ep3k9qefc6KQQC86Eah/OGM/Garig6jT13iLwyET
         FtYsvRn2T8w64BnJyOPecm78M8L2huzBewNvoelkeWJ/iOy7Q6aBvs6QRfSlofEj5h6J
         fY+smO5ygB3vV83l940XlOny+DBIqVpOEbMHY=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=sender:x-gm-message-state:mime-version:message-id:date:subject:from
         :to:content-type:content-disposition:content-transfer-encoding
         :x-original-sender:x-original-authentication-results:precedence
         :mailing-list:list-id:list-help:reply-to;
        bh=CplHfCqscVv63ZCvirQ+kOAnaGy+fQ75nMYfE7lYq9k=;
        b=PsyED0jEeSUp2AIAVSDPml90JG3aUJohwjIW25jlclqk1URF/aE8cqXQ18ZRXb+aN0
         NrQMYWpzaTH7Lhm8P4zhx4RwSpg/5ARF3DcBn1sq3pvrbyq+EPb8VVCRaNzFfBDgvyhy
         PzjAOcj+ePn5JHgF72Vcwe1otXzrNjdwmOlac8InvAXB7o3m9BJSJDRXDr1njey6nTrs
         rxkRG/m00hudFhUfS8mIOcBDzRQlxhv2Qyieqx9MOD5GWx3yahNIdOlxGMp2aKygIjdi
         Ido74o8k7Toxg9+i8ezRe0u2PPPXKvcvS6C3jfDFur3itznWrigANhKx72579XfwwUG5
         hBGw==
Sender: [email protected]
X-Gm-Message-State: ALoCoQk7KfRa8eCPbeV/RdlsyKq6gQuK7klaYSAFQPzgRNVhuflMuZp/M0VpRUca9zwJDjYrEv/u
X-Received: by 10.236.36.39 with SMTP id v27mr16650675yha.24.1423995712566;
        Sun, 15 Feb 2015 02:21:52 -0800 (PST)
X-BeenThere: [email protected]
Received: by 10.107.170.129 with SMTP id g1ls1295636ioj.69.gmail; Sun, 15 Feb
 2015 02:21:52 -0800 (PST)
X-Received: by 10.107.168.207 with SMTP id e76mr22648201ioj.60.1423995712409;
        Sun, 15 Feb 2015 02:21:52 -0800 (PST)
Received: from mail-ie0-f201.google.com (mail-ie0-f201.google.com. [209.85.223.201])
        by mx.google.com with ESMTPS id s10si8220288igg.4.2015.02.15.02.21.52
        for <[email protected]>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 15 Feb 2015 02:21:52 -0800 (PST)
Received-SPF: pass (google.com: domain of [email protected] designates 209.85.223.201 as permitted sender) client-ip=209.85.223.201;
Received: by iecrl12 with SMTP id rl12so7777265iec.0
        for <[email protected]>; Sun, 15 Feb 2015 02:21:52 -0800 (PST)
MIME-Version: 1.0
X-Received: by 10.182.50.161 with SMTP id d1mr16824193obo.28.1423995711904;
 Sun, 15 Feb 2015 02:21:51 -0800 (PST)
Message-ID: <[email protected]>
Date: Sun, 15 Feb 2015 10:21:51 +0000
Subject: Report domain: yyy.cz Submitter: google.com Report-ID: 2244696771454641389
From: noreply-dmarc-support via xxx <[email protected]>
To: [email protected]
Content-Type: application/zip; 
    name="google.com!yyy.cz!1423872000!1423958399.zip"
Content-Disposition: attachment; 
    filename="google.com!yyy.cz!1423872000!1423958399.zip"
Content-Transfer-Encoding: base64
X-Original-Sender: [email protected]
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of [email protected] designates 209.85.223.201 as
 permitted sender) [email protected];       dkim=pass
 [email protected];       dmarc=pass (p=REJECT dis=NONE) header.from=google.com
Precedence: list
Mailing-list: list [email protected]; contact [email protected]
List-ID: <xxx.yyy.cz>
X-Google-Group-Id: 98899750969
List-Help: <http://support.google.com/a/yyy.cz/bin/topic.py&topic=25838>, <mailto:[email protected]>
X-Original-From: [email protected]
Reply-To: [email protected]

UEsDBAoAAAAIABRPT0bdJB+DSwIAALgKAAAuAAAAZ29vZ2xlLmNvbSFzdW5mb3guY3ohMTQyMzg3
MjAwMCExNDIzOTU4Mzk5LnhtbO1WwY6bMBC971dEuQcDIQSQQ3rqF7RnZIwh7oJt2WY32a+viQ2h
u9moqnarqOop8Gbmjd/4OQbuj127eCJSUc52y8DzlwvCMK8oa3bL79++rpLlYp8/wJqQqkT4MX9Y
LKAkgktddESjCmk0YAblsikY6kjecN60xMO8g2ACbQ7pEG1zxg1De1pVHZJ4pXox0H2Zl9k8V3PU
EhWYM42wLiireX7QWmQAuErvUgkQKCkDiKlnIj1x2tunXRjF8SbxDfFbMtvFaaJVHoZRFKfxdhtE
myiOgnWSQnAJ23SjmxQSscYpM1BJGsryIArXyTb0fdPMImOcsOocTTfJOjWUw7slA7+yTd3mA4aC
txSfCtGXLVUHMi2Em1GxXPVGytHDL4bMIjaMqkfa5RIC++BAJeozNvxaSOSS/CBYQyAcoi6QGjGB
dR4MyoaH80qvrcrMEnM5LlDy52kEivcSk4KKPIz9bVYnpZ9Fvr/OsB9kWbgOTa8pZSzCvGemLQT2
YYRdZ/KE2t6MrxoDw0yoElxRbTxtvMaImckMmeUNIxFIKZMwTceJr11gGtFM7aueZr9GjZBWhGla
U3OiprIDQRWRRS15N9+nOex43lRD1OtDIYnqW30hfLXY2xZw7h4YnCT3Mqma08GZ3g+gvhgMvFYy
JI82+R3HpL4XbDdesIm84SB/tE9Gr99wSm3+k646xQbu0Sl/uptW0Sfu5tXzH6b3dP7vd1f/+vl/
KU83eRnpzbX6uY5JzMeJZ25PLwji920S/r8m/tVrAoLLR+hPUEsBAgoACgAAAAgAFE9PRt0kH4NL
AgAAuAoAAC4AAAAAAAAAAAAAAAAAAAAAAGdvb2dsZS5jb20hc3VuZm94LmN6ITE0MjM4NzIwMDAh
MTQyMzk1ODM5OS54bWxQSwUGAAAAAAEAAQBcAAAAlwIAAAAA

"undisclosed-recipients" throws error

When receiving an email whose recipient was set in BCC, an "Undefined property" error is thrown because the "host" is undefined. This happens in Headers.php line 51.

Use utf8_encode() function to encode content

This issue is related with this #39

Now we use utf8_encode() function to encode conent.

 \utf8_encode( \quoted_printable_decode($this->getContent()));

But this function only encodes an ISO-8859-1 string to UTF-8, so we should use iconv() function instead.

mb_convert_encoding(): Illegal character encoding specified

Hello,

On one of my messages I get:

exception 'ErrorException' with message 'mb_convert_encoding(): Illegal character encoding specified' in /var/www/vhosts/archive/vendor/ddeboer/imap/src/Ddeboer/Imap/Message/Headers.php:20

Any ideas on how to fix that?

Thank you!

Authentication failed for a Gmail account

Hi everybody,

I was testing your library with my professional Office 365 account, it's working fine (at least, I can get a listing of all my emails).

But when I want to do some tests with my personal Gmail account (with exactly the same code), I get stuck with the error :
Fatal error: Uncaught exception 'Ddeboer\Imap\Exception\AuthenticationFailedException' with message 'Authentication failed for user [email protected] ...

on the line :

$connection = $server->authenticate( ... );

I checked my Gmail settings, IMAP enabled, "Less secure apps" turned on, ... I don't understand.
I was thinking, maybe it's because my password contains some "fancy" characters ( / , `, ' , and others) but Gmail always accepted it.

Do you have any idea? Thanks.

"date" header is not reliable

Sometimes date header is not in a proper format, for example, mail.ru returns this for date header: =?utf-8?B?0fAsIDQg4OLjIDIwMTAgMTM6MDE6NDAgKzAzMDA=?=
This makes library fail in file Header.php on line 33. Using maildate from headers array instead solved it for me, but I'm not sure if this is a right way to do this.

Garbled e-mail body encoding

Hi, when I download messages with encoding other than UTF-8, the message body content gets garbled.

What helped me resolve this issue is replace mb_encode_string with iconv.

SearchExpression with new OrConditions

Hi guys,

I used the SearchExpression parameter on getMessages() func.

With telnet cmd write (OR SUBJECT "lien" BODY "lien") to get mails with these criterias:

d search OR SUBJECT "lien" BODY "lien"
* SEARCH 17 24 33 77 83 84 88 89 91 103 104 106 115 117 118 120 122 124 133 135 136 138 139 143 147 181 186 187 194 199 209 210 213 214 220 254 261 264 266 267 269 274 283 291 296 309 312 335 361 366 371 378 386 409 412 425 427 435 436 440 448 462 467 476 479 480 491 497 502 506 520 523 545 555 557 567 571 572 581 608 612 614 618 619 621 627 642 649 654 661 673 678 680 690 695 699 733 734 744 758 767 773 809 818 823 831 836 838 843 882 895 916 932 938 1011 1031 1036 1095 1106 1115 1143 1146 1159 1161 1179 1185 1186 1204 1211 1216 1222 1287 1322 1328 1332 1344 1345 1350 1369 1385 1389 1433 1444 1474 1487 1563 1631
d OK SEARCH done.

And it work !

In my controller I use my own service for instantiate mailboxes connection and I have any other route and she works but for my question only show you the search route :

<?php

namespace WM\API\MailsBundle\Controller;

use Doctrine\Common\Collections\ArrayCollection;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController as Controller;
use FOS\RestBundle\Request\ParamFetcher;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Ddeboer\Imap\Server;
use Ddeboer\Imap\Mailbox;
use Ddeboer\Imap\SearchExpression;
use Ddeboer\Imap\Search;
use WM\API\MailsBundle\Representation\Email;

/**
 * @Route("/emails")
 */
class InboxController extends Controller
{
/**
     * @Rest\Get("/search", name="search_inbox_emails")
     *
     * @Rest\QueryParam(
     *   name="page",
     *   default=1,
     *   nullable=true,
     *   description="Page number"
     * )
     *
     * @Rest\QueryParam(
     *   name="limit",
     *   default=25,
     *   nullable=true,
     *   description="Emails per pages"
     * )
     *
     * @ApiDoc(
     *   section="Inbox",
     *   description="Search emails from inbox."
     * )
     */
    public function searchInboxEmailsAction(ParamFetcher $paramFetcher)
    {
        $connection = $this->getConnection();
        $inbox = $connection->getMailbox('INBOX');

        $search = new SearchExpression();
        $search
            ->addCondition(new Search\LogicalOperator\OrConditions())
            ->addCondition(new Search\Text\Subject('lien'))
            ->addCondition(new Search\Text\Body('lien'))
        ;
        echo $search;

        $emails = new ArrayCollection();

        $currentIds = $this->sortIds($inbox, $paramFetcher, $search);

        foreach($currentIds as $id) {
            $emails->add(new Email($inbox->getMessage($id)));
        }
        return $emails;
    }

    /**
     * @return \Ddeboer\Imap\Connection
     * @ApiDoc(
     *   section="Inbox",
     *   description="Get mailboxes connection from Connectator service."
     * )
     */
    private function getConnection()
    {
        $connectator = $this->get('wmapi_mails.connectator');
        return $connectator->getConnection();
    }

    /**
     * @param Mailbox $mailBox
     * @param ParamFetcher $paramFetcher
     * @param SearchExpression|null $search
     * @return array
     *
     * @ApiDoc(
     *   section="Inbox",
     *   description="Reverse Mailbox emails and return limit mails for each pages"
     * )
     */
    private function sortIds(Mailbox $mailBox, ParamFetcher $paramFetcher, SearchExpression $search=null)
    {
        $currentIds = array_slice(
            array_reverse($mailBox->getMessages($search)->getArrayCopy()),
            ($paramFetcher->get('page')-1) * $paramFetcher->get('limit'),
            $paramFetcher->get('limit')
        );

        return $currentIds;
    }

}

An echo of $search give me :

echo $search;

// -->OR SUBJECT "lien" BODY "lien"

This not work !

Obviously when give one condition or more without OrConditions() it work great !

Please help me because I've not found any results with my best friend google ...

Thanks.

imap_header doesn't work with message uid

Hi,

nothing is working anymore for me.

ErrorException
imap_header(): Bad message number

my research has shown me that
imap_header()
http://us1.php.net/manual/en/function.imap-headerinfo.php doesn't work with uid ...

think a decision is needed if the slower imap_fetchheader should be used within the getHeaders function

This is a comment on php.net:
"I typically use UID's to identify messages, and recently discovered that the headers I had been pulling using this function and a message-number didn't match the UID's. Instead of worrying about it, I just began using imap_fetchheader() and imap_ rfc822_ parse_ headers() on its output. The only significant difference I immediately noticed was that there is no "udate" property, so I assigned one with the result of strtotime() on the 'date' property.

Dustin"

keepUnseen not working correctly with Hotmail

Trying to use the following sample code with hotmail:
$message->keepUnseen()->getBodyHtml();

It is not keeping the messages as unread. Tried forcing a boolean in keepUnseen
$message->keepUnseen(true)->getBodyHtml();

Did not work. Tried forcing the class variable to be true by default on line 21 of Message.php, This also did not work.

Travis tests allways fail?

I've noticed my PR failed on Travis with this error:

  1. Ddeboer\Imap\Tests\ConnectionTest

RuntimeException: Please set environment variable EMAIL_USERNAME before running functional tests

I've seen that in other PR, so I guess it happens to everyone. Can that be fixed? Repo would be easier to maintain, right? 😃

Message::move() doesn't work.

I'm trying to move email to another mailbox. Library does not return any error. Looks like success, but email isn't moved.

$message->move($this->mailboxProcessed);
$this->mailboxProcessed->expunge();

Also another issue is, that emails cannot be moved in a loop. Strange, but this issue occurs even when emails doesn't get moved:

[Ddeboer\Imap\Exception\MessageDoesNotExistException]
Message 4 does not exist: imap_fetchstructure(): Bad message number

I'm trying to move email on Bluehost email server.

Deleting a message isn't working

Hello, I've got the problem that it always delete the wrong email

My code:
$message = $mailbox->getMessage(233);
$message->delete();
$mailbox->expunge();

Instead of message 223 it deletes one out of ~775

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.