Skip to content

Commit

Permalink
uid in appended message as return
Browse files Browse the repository at this point in the history
  • Loading branch information
piernik committed Nov 8, 2017
1 parent 3680d00 commit 8919812
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
16 changes: 10 additions & 6 deletions src/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function setFlag(string $flag, $numbers): bool
$numbers = \implode(',', $numbers);
}

return \imap_setflag_full($this->resource->getStream(), (string) $numbers, $flag, \ST_UID);
return \imap_setflag_full($this->resource->getStream(), (string)$numbers, $flag, \ST_UID);
}

/**
Expand All @@ -145,7 +145,7 @@ public function clearFlag(string $flag, $numbers): bool
$numbers = \implode(',', $numbers);
}

return \imap_clearflag_full($this->resource->getStream(), (string) $numbers, $flag, \ST_UID);
return \imap_clearflag_full($this->resource->getStream(), (string)$numbers, $flag, \ST_UID);
}

/**
Expand Down Expand Up @@ -210,11 +210,14 @@ public function getIterator(): MessageIteratorInterface
*
* @param string $message
*
* @return bool
* @return int sppended message UID
*/
public function addMessage(string $message): bool
public function addMessage(string $message): int
{
return \imap_append($this->resource->getStream(), $this->getFullEncodedName(), $message);
$status = $this->getStatus(SA_UIDNEXT);
if (\imap_append($this->resource->getStream(), $this->getFullEncodedName(), $message)) {
return $status->uidnext;
}
}

/**
Expand All @@ -224,7 +227,8 @@ public function addMessage(string $message): bool
*/
public function getThread(): array
{
\set_error_handler(function () {});
\set_error_handler(function () {
});

$tree = \imap_thread($this->resource->getStream());

Expand Down
4 changes: 2 additions & 2 deletions src/MailboxInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public function getIterator(): MessageIteratorInterface;
*
* @param string $message
*
* @return bool
* @return int
*/
public function addMessage(string $message): bool;
public function addMessage(string $message): int;

/**
* Returns a tree of threaded message for the current Mailbox.
Expand Down
34 changes: 22 additions & 12 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ddeboer\Imap\Exception\InvalidDateHeaderException;
use Ddeboer\Imap\Exception\MessageDoesNotExistException;
use Ddeboer\Imap\Exception\UnsupportedCharsetException;
use Ddeboer\Imap\Mailbox;
use Ddeboer\Imap\Message;
use Ddeboer\Imap\Message\EmailAddress;
use Ddeboer\Imap\Message\Parameters;
Expand Down Expand Up @@ -39,20 +40,24 @@ final class MessageTest extends AbstractTest
];

private static $charsets = [
'ASCII' => '! "#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
'GB18030' => " 、。〃々〆〇〈〉《》「」『』【】〒〓〔〕〖〗〝〞〡〢〣〤〥〦〧〨〩〾一\u{200b}\u{200b}丂踰\u{200b}\u{200b}\u{200b}",
'ISO-8859-6' => 'ءآأؤإئابةتثجحخدذرزسشصضطظعغـفقكلمنهوىي',
'ISO-8859-7' => 'ΆΈΉΊ»Ό½ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟ2ΠΡΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ',
'SJIS' => '。「」、・ヲァィゥェォャュョッBーアイウエオカキクケコサシスセソCタチツテトナニヌネノハヒフヘホマDミムメモヤユヨラリルレロワン゙゚',
'UTF-8' => '€✔',
'ASCII' => '! "#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
'GB18030' => " 、。〃々〆〇〈〉《》「」『』【】〒〓〔〕〖〗〝〞〡〢〣〤〥〦〧〨〩〾一\u{200b}\u{200b}丂踰\u{200b}\u{200b}\u{200b}",
'ISO-8859-6' => 'ءآأؤإئابةتثجحخدذرزسشصضطظعغـفقكلمنهوىي',
'ISO-8859-7' => 'ΆΈΉΊ»Ό½ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟ2ΠΡΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ',
'SJIS' => '。「」、・ヲァィゥェォャュョッBーアイウエオカキクケコサシスセソCタチツテトナニヌネノハヒフヘホマDミムメモヤユヨラリルレロワン゙゚',
'UTF-8' => '€✔',
'Windows-1251' => 'ЂЃѓЉЊЌЋЏђљњќћџЎўЈҐЁЄЇІіґёєјЅѕїАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя',
'Windows-1252' => 'ƒŠŒŽšœžŸªºÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ',
];

private static $iconvOnlyCharsets = [
'macintosh' => '†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈«»…ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔ',
'macintosh' => '†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈«»…ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔ',
'Windows-1250' => 'ŚŤŹśťźˇ˘ŁĄŞŻ˛łąşĽ˝ľż',
];
/**
* @var Mailbox
*/
protected $mailbox;

protected function setUp()
{
Expand All @@ -65,7 +70,7 @@ public function testCustomNonExistentMessageFetch()
$messageNumber = 98765;

$this->expectException(MessageDoesNotExistException::class);
$this->expectExceptionMessageRegExp(\sprintf('/E_WARNING.+%s/s', \preg_quote((string) $messageNumber)));
$this->expectExceptionMessageRegExp(\sprintf('/E_WARNING.+%s/s', \preg_quote((string)$messageNumber)));

new Message($connection->getResource(), $messageNumber);
}
Expand Down Expand Up @@ -236,6 +241,12 @@ public function provideIconvCharsets(): array
return $provider;
}

public function testAppendedMessageUid()
{
$uid = $this->mailbox->addMessage($this->getFixture('email_address'));
$this->assertEquals(1, $uid);
}

public function testEmailAddress()
{
$this->mailbox->addMessage($this->getFixture('email_address'));
Expand Down Expand Up @@ -473,8 +484,7 @@ public function testRawHeaders()
{
$headers = 'From: [email protected]' . "\r\n"
. 'To: [email protected]' . "\n"
. "\r\n"
;
. "\r\n";
$originalMessage = $headers . 'Content' . "\n";

$this->mailbox->addMessage($originalMessage);
Expand Down Expand Up @@ -643,9 +653,9 @@ public function testSignedMessage()
$this->assertCount(3, $attachments);

$expected = [
'data.xml' => 'PHhtbC8+',
'data.xml' => 'PHhtbC8+',
'postacert.eml' => 'test-content',
'smime.p7s' => 'MQ==',
'smime.p7s' => 'MQ==',
];

foreach ($attachments as $attachment) {
Expand Down

0 comments on commit 8919812

Please sign in to comment.