Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Multiples attachments on Windows duplicate #602

Closed
epschitz opened this issue Apr 18, 2015 · 10 comments
Closed

Multiples attachments on Windows duplicate #602

epschitz opened this issue Apr 18, 2015 · 10 comments

Comments

@epschitz
Copy link

Hello,

I'm trying attach multiple files with Swift_Attachment. On MAC, it's ok, but on Windows, the files are duplicated. If I send 3 files, sometimes the 3 files are equal, other times 2 files are equal and 1 different.

This only happens on Windows. The same code on MAC, it's ok.

Any idea? The last code that I tried:

(The paths are different)

$attachments[] = Swift_Attachment::fromPath($pathfile_1, 'application/pdf')->setFilename($_FILES['file_1']['name']);
$attachments[] = Swift_Attachment::fromPath($pathfile_2, 'application/pdf')->setFilename($_FILES['file_2']['name']);
$attachments[] = Swift_Attachment::fromPath($file_pdf, 'application/pdf')->setFilename($filename.'.pdf');
$attachments[] = Swift_Attachment::fromPath($file_xml, 'text/xml')->setFilename($filename.'.xml');

foreach ($attachments AS $attachment) {
$message->attach($attachment);
}

@jewome62
Copy link

I have the same problem :
Swift_Mailer Bundle :2.3
PHP 5.5.12
Windows 7

@xdecock
Copy link
Member

xdecock commented May 11, 2015

Looks Like a cache collision have you tried disabling the cache?

The interrestings parts might be the position where the keynames are
created.

On Sat, Apr 18, 2015 at 8:39 PM, Eduardo Schitz notifications@github.com
wrote:

Hello,

I'm trying attach multiple files with Swift_Attachment. On MAC, it's ok,
but on Windows, the files are duplicated. If I send 3 files, sometimes the
3 files are equal, other times 2 files are equal and 1 different.

This only happens on Windows. The same code on MAC, it's ok.

Any idea? The last code that I tried:

(The paths are different)

$attachments[] = Swift_Attachment::fromPath($pathfile_1,
'application/pdf')->setFilename($_FILES['file_1']['name']);
$attachments[] = Swift_Attachment::fromPath($pathfile_2,
'application/pdf')->setFilename($_FILES['file_2']['name']);
$attachments[] = Swift_Attachment::fromPath($file_pdf,
'application/pdf')->setFilename($filename.'.pdf');
$attachments[] = Swift_Attachment::fromPath($file_xml,
'text/xml')->setFilename($filename.'.xml');

foreach ($attachments AS $attachment) {
$message->attach($attachment);
}


Reply to this email directly or view it on GitHub
#602.

Xavier De Cock
GPG Fingerprint: 93CA EE3F 9F57 5BE1 AE4A 794D 3C74 CA9E E7A5 0C1B
GPG Id: 0xE7A50C1B

@jewome62
Copy link

How disable the cache ?
I'm on Sumfony 2.6 Project

With 10 files attachments, we are 10 files with the content of 3 files

@xdecock
Copy link
Member

xdecock commented May 11, 2015

No idea about how symfony works exactly

but this should do the trick :

Swift_Preferences::getInstance()->setCacheType('null')

On Mon, May 11, 2015 at 4:20 PM, Desjardins Jérôme <notifications@github.com

wrote:

How disable the cache ?
I'm on Sumfony 2.6 Project

With 10 files attachments, we are 10 files with the content of 3 files


Reply to this email directly or view it on GitHub
#602 (comment)
.

Xavier De Cock
GPG Fingerprint: 93CA EE3F 9F57 5BE1 AE4A 794D 3C74 CA9E E7A5 0C1B
GPG Id: 0xE7A50C1B

@jewome62
Copy link

Yep, It's work with \Swift_Preferences::getInstance()->setCacheType('null') before

@xdecock
Copy link
Member

xdecock commented May 11, 2015

Ok, so definitively looks like a cache Collision, our keys probably
collides on windows,

This might be tricky to get out of (uniqid collision probably)

On Mon, May 11, 2015 at 5:01 PM, Desjardins Jérôme <notifications@github.com

wrote:

Yep, It's work with
\Swift_Preferences::getInstance()->setCacheType('null') before


Reply to this email directly or view it on GitHub
#602 (comment)
.

Xavier De Cock
GPG Fingerprint: 93CA EE3F 9F57 5BE1 AE4A 794D 3C74 CA9E E7A5 0C1B
GPG Id: 0xE7A50C1B

@sstok
Copy link
Contributor

sstok commented May 14, 2015

uniqid() is anything but unique, second to that md5 is not very collision free either.

I think something like sha1(microtime().getmypid().mt_rand()); will produce something better, but even that will not help completely.

And looking at the code I actually found a serious bug!!

$this->_cacheKey = uniqid();
when cloning it uses only uniqueid() with no extra entropy!

@sstok
Copy link
Contributor

sstok commented May 14, 2015

I just realized something, the cacheKey is only used in this class, and only for the _bodyToString() method. So instead of creating it ever time in the constructor it should only be set when needed and not set previously. To increase the performance a bit :)

@xdecock
Copy link
Member

xdecock commented May 14, 2015

:) so, was creating ok result on "nux but problems on windows, were uniqid
is only a timestamp

On Thu, May 14, 2015 at 10:23 AM, Sebastiaan Stok notifications@github.com
wrote:

I just realized something, the cacheKey is only used in this class, and
only for the _bodyToString() method. So instead of creating it ever time in
the constructor it should only be set when needed and not set previously.
To increase the performance a bit :)


Reply to this email directly or view it on GitHub
#602 (comment)
.

Xavier De Cock
GPG Fingerprint: 93CA EE3F 9F57 5BE1 AE4A 794D 3C74 CA9E E7A5 0C1B
GPG Id: 0xE7A50C1B

@voku
Copy link

voku commented Sep 11, 2015

All this problems with non embedded images, images as attachments, re-downloading embedded images, ... are a result of this commit 45c2e4d ... maybe we can only use the "clone" of the objects if we need it - the fix is only for "MemorySpool"-Transport!?

makasim pushed a commit to formapro-forks/swiftmailer that referenced this issue Jul 26, 2017
…collection

Adds ability to cap log size in redis
@fabpot fabpot closed this as completed Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants