Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
If use one image more than once, mime module process all image, and attach to mail.
I modify the function _mimemail_file and solve this problem, but need more testing.
The modified function:
function _mimemail_file($url = NULL, $name = '', $type = '', $disposition = 'related') {
static $files = array();
static $filenames = array(); // this modifycation, store all filenames with full path
if ($url) {
$url = _mimemail_url($url, 'TRUE');
// If the $url is absolute, we're done here.
if (strpos($url, '://') || preg_match('!mailto:!', $url)) {
return $url;
}
else {
// The $url is a relative file path, continue processing.
$file = $url;
}
}
if ($file && file_exists($file)) {
if (isset($filenames[$file])) return 'cid:'. $filenames[$file]; // this modifycation, if key exists, return old value
$content_id = md5($file) .'@'. $_SERVER['HTTP_HOST'];
if (!$name) $name = substr($file, strrpos($file, '/') + 1);
$new_file = array(
'name' => $name,
'file' => $file,
'Content-ID' => $content_id,
'Content-Disposition' => $disposition,
);
$new_file['Content-Type'] = _mimemail_mimetype($file, $type);
$files[] = $new_file;
$filenames[$file] = $content_id; // this modifycation, store filename to key, content_id to value
return 'cid:'. $content_id;
}
$ret = $files;
$files = array();
return $ret;
}
Comment | File | Size | Author |
---|---|---|---|
#5 | mimemail-358439-5.patch | 254 bytes | folkertdv |
#2 | mimemail-358439-2.patch | 959 bytes | folkertdv |
Comments
Comment #1
jerdavisThanks for submitting code, but please read http://drupal.org/patch/create and provide a patch, it's much much easier for us to work with and saves everyone time.
Thanks!
Jer
Comment #2
folkertdv CreditAttribution: folkertdv commentedCame across this bug months ago as well and fixed it but somehow never submitted a patch.
The suggested patch looks clean and I've created a patch file for submission. Great work DTB :)
Comment #3
jerdavisCommitted!
This should show up in the next development snapshot. Thanks for creating the patch folkertdv and thanks for submitting the code DTB.
Jer
Comment #5
folkertdv CreditAttribution: folkertdv commentedReopening this issue because the patch above introduces new problems (an additional patch file is provided).
Problem:
If the mimemail function is called, certain files are embedded and their cid's are stored in the filenames array (to prevent duplicates).
Subsequent calls of the mimemail function will not embed files that have been embedded in previous mails.
Cause:
The static filenames array isn't emptied at the end of the _mimemail_file function like the static files array.
Adding the single line in the attached patch file has fixed the problem for me.
Cheers!
Comment #6
folkertdv CreditAttribution: folkertdv commentedBumping this issue before it closes, this (minor) patch still needs reviewing :)
Comment #7
eikes CreditAttribution: eikes commented@folkertdv patch in #5 works
thanks a lot!
i was wondering why only the latest subscriber got the attachments...
Comment #8
makr CreditAttribution: makr commentedThanks, this also resolves issue http://drupal.org/node/453334, where only the first recipient receives the email-newsletter containing pictures (simplenews + mimemail).
Comment #9
askibinski CreditAttribution: askibinski commentedHas this already been commited to the latest dev?
Comment #10
miro_dietikersubscribing & reviewing
Comment #11
miro_dietikerWorks just perfect. Please commit.
Comment #12
zoo33 CreditAttribution: zoo33 commentedThe fix suggested in #5 would just undo the static nature of the $filenames variable, wouldn't it? In that case, a better solution would be to just remove the "static" keyword. Or rather, revert the original patch.
By the way, the $files variable has the same problem, it shouldn't be static if that means it has to be reset each time the function executes. Static variables are for data that should be preserved between function calls.
Comment #13
Frans CreditAttribution: Frans commentedsubscribe
Comment #14
hanoiiThe patch on #5 does work and fixes the issue and I agree with #12, although I rather have this one reviewed and tested so it might get committed soon rather than holding it.
If I have some time, I'll look more into this and submit a patch with the static removed or something, will look at this a little bit deeper, but otherwise, having it static, even if it's not really used as static, does not harm that much, but this bug does.
Comment #15
folkertdv CreditAttribution: folkertdv commentedActually, the static prefix wasn't introducted by the patch. It was there already for the files variable and duplicated for the filenames variable.
I suggest the code is carefully analyzed, since the static variable serves a purpose and is there for a reason (notice the function can return before the static variable is reset at the bottom).
Comment #16
NicP CreditAttribution: NicP commentedWhen you see code like this you understand why objects are better.
The design seems to rely on the static variable being static for the duration of an email. The desired result of the function is delivered when the function is finally called with no parameters, at that time the statics can be cleared.
So #5 is correct, I wish I had found this issue before I fixed it myself.
Comment #17
Sutharsan CreditAttribution: Sutharsan commentedDuplicated by #506182: Attachment only sent to one email from list email subscribe and #453334: simplenews and mimemail combination, pictures only got send to first registered email adres.
jerdavis, Allie Micka, what is needed to get this patch committed?
Comment #18
sbogner@insightcp.com CreditAttribution: sbogner@insightcp.com commentedJust came across this issue too - looks like patches have been made & reviewed; what is needed to commit this?
Comment #19
folkertdv CreditAttribution: folkertdv commentedA more active maintainer by the looks of it. I provided the patch almost a year ago!
Since this module affects a lot of other modules (eg. simplenews), I consider this a serious bug.. pity it's been open for so long.
Comment #20
Eric_A CreditAttribution: Eric_A commentedI have not tested alpha2 yet, but the added line is in.
I'm not sure why jerdavis has not mentioned his February 23, 2009 commit in this issue.
http://drupal.org/cvs?commit=174768
Comment #21
sgabe CreditAttribution: sgabe commentedThe fix for this is in #5 which is not committed so far.
Comment #22
Eric_A CreditAttribution: Eric_A commentedEDIT: I stand corrected. The commit message references this issue, but the committed line of code has a small but very important difference. Sigh.
The fix for this is in #5 which is not committed so far.
Please follow the link in #20 to the commit message and click on the link to the 1.40 diff. You'll see the code from the patch in #5. In fact, that line of code is there both in HEAD and DRUPAL-6--1-0-ALPHA2.Comment #23
sgabe CreditAttribution: sgabe commentedChanging title to a more descriptive one.
Comment #24
Eric_A CreditAttribution: Eric_A commentedI just sent a newsletter with images and all emails seem fine. (Mime Mail alpha2 + Newsletter 1.1 with the Hotmail patch in http://drupal.org/node/372710#comment-2796702)
EDIT: and sending 4 e-mails in one cron run (Poormanscron 6.x-2.2).
Could someone please rephrase when problems occur and exactly what problems, since I forgot how to reproduce this...
Comment #25
sgabe CreditAttribution: sgabe commented@Eric_A: If you send a newletter with an embedded image for multiple e-mail addresses, only the first message will contain the image. The rest will have the
cid:
in the source, but no encoded attachment in the message.To reproduce:
Comment #26
acb CreditAttribution: acb commentedI too can confirm bug in #25; it occurs with RELATIVE vs. absolute path.
Comment #27
jerdavisThis has been committed to HEAD, once a few of the other critical fixes have been tested and committed we'll be rolling a new alpha release.
Jer
Comment #29
benone CreditAttribution: benone commentedsubscribe
Comment #30
Stijn Vanhandsaeme CreditAttribution: Stijn Vanhandsaeme commentedIn fact the line
$filenames = array();
needs to be added on line 156 in mimemail.inc,v 1.41 2010/03/24
I have no knowhow of submitting a patch, sorry.
Comment #31
Stijn Vanhandsaeme CreditAttribution: Stijn Vanhandsaeme commentedsorry, set to active again.
Comment #32
sgabe CreditAttribution: sgabe commentedThis has been already committed to HEAD. Closing again.
Comment #33
roball CreditAttribution: roball commentedHurray - finally this fix is in a release for the first time (6.x-1.0-alpha3). The first release that works with Simplenews out of the box.