ddeboer / imap

Object-oriented, fully tested PHP IMAP library
MIT License
887 stars 253 forks source link

Messages: Add ability to native save mail content to file #556

Closed jakubboucek closed 1 year ago

jakubboucek commented 1 year ago

PR is adding ability to store raw Message (or their parts) to file directly via native imap_savebody() function.

Direct handling I/O is much more effective than fetch Message Body as string and than save it. Some messages may have huge size, it may waste process memory.

Example how to simple store Message content file:

$filename = 'message-content.eml';
$message->saveRawMessage($filename);

Streams

The imap_savebody() function supports Streams too, this provides the ability to connect elements with pipes for effective manipulating with mail content.

Example how to simple store Message content to compressed file with single atomic operation:

$file = gzopen('message-content.eml.gz', 'wb');
$message->saveRawMessage($file);
gzclose($file);
codecov[bot] commented 1 year ago

Codecov Report

Base: 94.76% // Head: 94.73% // Decreases project coverage by -0.04% :warning:

Coverage data is based on head (ce12e39) compared to base (a238641). Patch coverage: 92.30% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #556 +/- ## ============================================ - Coverage 94.76% 94.73% -0.04% - Complexity 356 360 +4 ============================================ Files 45 45 Lines 898 911 +13 ============================================ + Hits 851 863 +12 - Misses 47 48 +1 ``` | [Impacted Files](https://codecov.io/gh/ddeboer/imap/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=David+de+Boer) | Coverage Δ | | |---|---|---| | [src/Message/AbstractPart.php](https://codecov.io/gh/ddeboer/imap/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=David+de+Boer#diff-c3JjL01lc3NhZ2UvQWJzdHJhY3RQYXJ0LnBocA==) | `95.51% <88.88%> (-0.41%)` | :arrow_down: | | [src/Message.php](https://codecov.io/gh/ddeboer/imap/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=David+de+Boer#diff-c3JjL01lc3NhZ2UucGhw) | `85.84% <100.00%> (+0.25%)` | :arrow_up: | | [src/Message/EmbeddedMessage.php](https://codecov.io/gh/ddeboer/imap/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=David+de+Boer#diff-c3JjL01lc3NhZ2UvRW1iZWRkZWRNZXNzYWdlLnBocA==) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=David+de+Boer). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=David+de+Boer)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

jakubboucek commented 1 year ago

Really IDK how to meaningfully test \Ddeboer\Imap\Message\EmbeddedMessage::saveRawMessage().

Slamdunk commented 1 year ago

Really IDK how to meaningfully test \Ddeboer\Imap\Message\EmbeddedMessage::saveRawMessage().

Just add few meaningful lines to \Ddeboer\Imap\Tests\EmbeddedMessageTest I'd say, and we are ready to merge :muscle:

jakubboucek commented 1 year ago

@Slamdunk Thanks to merge 👍