Trying to implement a temp workaround to deal with this weird SwiftMailer bug:
https://github.com/swiftmailer/swiftmailer/issues/762
When reading a file that has a length of exactly n*8192 bytes (n >= 1), the last > value of $bytes is an empty string which triggers the error.
@raffomania's comment on GitHub:
we found that the following adaption of AbstractFilterableInputStream.write would fix the problem for us:
public function write($bytes)
{
$this->_writeBuffer .= $bytes;
if (empty($this->_writeBuffer)) {
return;
}
foreach ($this->_filters as $filter) {
if ($filter->shouldBuffer($this->_writeBuffer)) {
return;
}
}
$this->_doWrite($this->_writeBuffer);
return ++$this->_sequence;
}
I'd like to extend the AbstractFilterableInputStream class and call this modified write method when AbstractFilterableInputStream is called by SwiftMailer.
I'm using the Laravel framework.
The best way to solve this is to have the swiftmailer forked and fixed and you use your own forked version of swiftmailer. However if you do not want to do this, this fix is rather lengthy but it should work. Give it a shot. If there is any issue do let me know.
1. Create
app/Mail/CustomFileByteStream.php
: This is to have your own version ofwrite
.2. Create
app/Mail/CustomSwiftAttachment.php
: So that it uses the customFileByteStream
3. Create
app/Mail/CustomSwiftImage.php
: So that it uses the customFileByteStream
4. Create
app/Mail/Message.php
: So that it uses your own customSwift_Image
andSwift_Attachment
5. Create
app/Mail/Mailer.php
: So it uses your customMessage
class6. Create
app/Mail/MailServiceProvider.php
: So it uses your customMailer
class7. Edit
config/app.php
Illuminate\Mail\MailServiceProvider::class,
App\Mail\MailServiceProvider::class,
So this will use your custom
MailServiceProvider
. At any point of time if you wish to revert this, just delete all the files above and reverse this edit.Calling sequence:
So here you go. This should hijack the
MailServiceProvider
to use your own customSwift_ByteStream_FileByteStream
. Hopefully no typos!