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.
for some reason unknown to me, sending mail with images didn't work for me.
the preg_replace expression always got me \-escaped double-quotes around the image src-attribute, which resulted in no image displayed ...
changing mimemail.inc a bit with the following got rid of the problem for me:
function mimemail_extract_files($html, $name) {
$pattern = '/(<link[^>]+href="?|<object[^>]+codebase="?|@import |src="?)\/?([^"]+)("?)/mis';
$html = preg_replace_callback($pattern, '_mimemail_extract_files_rep_cb', $html);
$document = array(array(
'Content-Type' => 'text/html; charset=utf-8',
'Content-Transfer-Encoding' => 'base64',
'content' => chunk_split(base64_encode($html)),
));
$files = _mimemail_file();
return array_merge($document, $files);
}
function _mimemail_extract_files_rep_cb(&$m) {
return "$m[1]"._mimemail_file($m[2]).$m[3];
}
and I got 2 more questions:
- is it necessary to always encode the html body with base64?
- wouldn't it be a good idea to have an option to not send the images inline, but convert the links to absolute server references?
smaller mails would be a nice thing sometimes ...
Comment | File | Size | Author |
---|---|---|---|
#23 | mimemail.114312_01.patch | 509 bytes | sgabe |
Comments
Comment #1
ray007 CreditAttribution: ray007 commentedno idea what went wrong yesterday, but just 2 minutes ago the old preg_replace() call also worked out right.
which only leaves the change to the 'Content-Type' line, that one seems to be necessary:
'Content-Type' => 'text/html; charset=utf-8',
and no name at the end.Comment #2
ray007 CreditAttribution: ray007 commentedI just got to another problem with attaching images to the mail:
We have an installation at a subdirectory of httpdocs, so the url for the drupal-installation is http://hostname.com/d5/
When generating a newsletter with tinyMCE and inserting an image, the src-attribute of the image is "/d5/files/myimage.jpg".
Since this is no path relative to the drupal-installtion, the file_exists() check in _mimemail_file() fails and the mail only contains a broken image, since "/d5/files/myimage.jpg" is no valid remote url.
I'll try to come up with a fix soon, if nobody else beats me to it.
Comment #3
ray007 CreditAttribution: ray007 commentedhere a little patch that seems to do the right thing:
Comment #4
ray007 CreditAttribution: ray007 commentedNobody else experiencing problem with sending images, when drupal is installed in a subdirectory of a site?
Comment #5
Allie MickaI don't doubt that you're experiencing this issue, and your solution looks correct.
I think that the number of people who run Drupal in a subdirectory AND have mimemail installend AND are sending images AND have the wherewithal to notice these things. Well, I think that number is pretty small.
I don't have the time to test this right away, but if someone else can RTBC this I would be most grateful.
Comment #6
ray007 CreditAttribution: ray007 commented*Bump*
Is there anything I can do to make you more comfortable with this patch?
Comment #7
kingandy CreditAttribution: kingandy commentedI'd just like to add my voice to this, and add the thought that perhaps any links to files that aren't found should be converted to absolute server references as well (assuming they aren't already absolute URIs). In theory it should be as simple as prepending it with a $_SERVER['SERVER_NAME'] or something, whenever there's no '://' in the link string ... shouldn't it?
Comment #8
kingandy CreditAttribution: kingandy commentedOh, wait, that already happens in _mimemail_file. Never mind. I still agree the option to switch off image encoding, though!
Comment #9
kingandy CreditAttribution: kingandy commentedWait, no it doesn't.
Note to self, finish reading code before commenting. Sorry...
Comment #10
kingandy CreditAttribution: kingandy commentedFWIW - if you'll forgive me adding yet another followup to this issue - I installed the above patch on my drupal install and initially it appears to work perfectly. Thanks!
Comment #11
yurtboy CreditAttribution: yurtboy commentedwhat is the proper way to apply this?
Sorry if I should know.
My drupal 5x install is doing the same thing. Send html but no images. BUT if you look at the source of the email there is not even a reference to the image even though the page it makes online is fine.
Thanks. Below is the source code to the email if it helps?
Also I believe I set all the needed "Input" setting to Non-filtered html if that matters?
Alfred Nutile
----------------start email source-------------------------------
Return-Path:
X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on
server1.rivervalleywebhosting.com
X-Spam-Level: *
X-Spam-Status: No, score=1.2 required=2.2 tests=AWL,HTML_IMAGE_ONLY_12,
HTML_MESSAGE,NO_RELAYS,UPPERCASE_25_50 autolearn=no version=3.1.8
X-Original-To: alfred@rivervalleytechsupport.com
Delivered-To: web4_alfred@server1.rivervalleywebdesign.com
Received: by server1.rivervalleywebhosting.com (Postfix)
id 7617DB293B1; Sun, 10 Jun 2007 19:00:38 -0400 (EDT)
Delivered-To: web1_alfred@server1.rivervalleywebdesign.com
Received: by server1.rivervalleywebhosting.com (Postfix)
id 6DFA2B293B5; Sun, 10 Jun 2007 19:00:38 -0400 (EDT)
Delivered-To: web5_alfred@server1.rivervalleywebdesign.com
Received: by server1.rivervalleywebhosting.com (Postfix, from userid 33)
id 54883B293B2; Sun, 10 Jun 2007 19:00:38 -0400 (EDT)
To: alfred@rivervalleytechsupport.com
Subject: [The End of money newsletter] Testing HTML with and Image
Errors-To: support@theendofmoney.com
From: "The End of money"
X-Security: MIME headers sanitized on server1.rivervalleywebhosting.com
See http://www.impsec.org/email-tools/sanitizer-intro.html
for details. $Revision: 1.138 $Date: 2003-01-26 11:25:54-08
X-Security: The postmaster has not enabled quarantine of poisoned messages.
Content-Type: multipart/alternative;
charset=utf-8;
boundary="878090a81d585f97f05e9edd170a486e"
Reply-To: support@theendofmoney.com
X-Mailer: Drupal
MIME-Version: 1.0
Message-Id: <20070610230038.54883B293B2@server1.rivervalleywebhosting.com>
Date: Sun, 10 Jun 2007 19:00:38 -0400 (EDT)
This is a multi-part message in MIME format.
--878090a81d585f97f05e9edd170a486e
Content-Type: multipart/alternative; boundary="0098ff8b7897d880a02b918484ae2205"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
--0098ff8b7897d880a02b918484ae2205
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
The End of money newsletter: Testing HTML with and Image
THIS IS THE DEFAULT HEADER
TESTING HTML WITH AND IMAGE
============================================================
image is to the left
THIS IS THE DEFAULT FOOTER
--
Footer will be appended here
--0098ff8b7897d880a02b918484ae2205
Content-Type: text/html; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: base64
PCFET0NUWVBFIGh0bWwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEgVHJhbnNpdGlvbmFs
Ly9FTiI+CjxIVE1MPgo8SEVBRD4KPE1FVEEgSFRUUC1FUVVJVj0iQ29udGVudC1UeXBlIiBDT05U
RU5UPSJ0ZXh0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+PC9UUj48L1RBQkxFPgo8
L0JPRFk+CjwvSFRNTD4KCi0tIApGb290ZXIgd2lsbCBiZSBhcHBlbmRlZCBoZXJl
--0098ff8b7897d880a02b918484ae2205--
--878090a81d585f97f05e9edd170a486e--
Comment #12
jsloan CreditAttribution: jsloan commentedI was having the same problem and this patch works fine on my install of 5.1 and I do use clean url's and sites as subdirectories.
Also; today I posted a patch that fixes the _mimemail_url bug [ http://drupal.org/node/133107 ]
can somebody test and then can these patches be applied to HEAD?
... thanks for the patch ray007!
Comment #13
ShutterFreak CreditAttribution: ShutterFreak commentedJust an update: the patch posted in #3 is not yet complete.
I get a file_get_contents(.) error when clicking on "Request new password" when I apply that patch.
What seems to solve the problem for me (and in addition stops sending zero-length file attachments to email messages), is the following version of
_mimemail_file()
:Best regards,
Olivier
Comment #14
ray007 CreditAttribution: ray007 commentedIt doesn't make sense to try to attach a file '.' - as it doesn't make sense to try to attach any directory.
But I think this check should come earlier and not in
_mimemail_file()
.And the check should probably be
is_file()
or!is_dir()
...Comment #15
ShutterFreak CreditAttribution: ShutterFreak commentedMaybe the checks should go into a new function
file_is_valid_attachment()
?Comment #16
jerdavisIf someone can roll a final version of the patch based on the comments on this issue I can test it.
Comment #17
Allie MickaWe had a pile of path-related changes last winter, and there's no longer any traffic on this issue. I'm optimistically marking this as closed.
Please re-open if you can confirm it's still an issue and/or provide a patch.
Thanks!
Comment #18
allartk CreditAttribution: allartk commentedhi,
I have drupal in a subdirectory and and... I think this bug is still in the current version.
The path to the image in the mail send is
file://drupal/sites/vogeldagboek.nl/files/image/test/PICT0016.JPG
of course that's not correct..
Greetings
Comment #19
allartk CreditAttribution: allartk commentedHi,
adding
below
fixes this issue. Otherwise file_exist will fail and the file is not attached.
Comment #20
jerdavisThis should be fixed with changes committed to HEAD in http://drupal.org/cvs?commit=141336.
Please test on this version or re-test once a new release is built. If you still have issues, please let us know!
Comment #21
allartk CreditAttribution: allartk commentedalso in alpha 2 this is an issue
add
$file = str_replace(ltrim($base_path,"/"),"",$file);
below
$file = $url;
in the function _mimemail_file in mimemail.inc
Comment #22
allartk CreditAttribution: allartk commentedComment #23
sgabe CreditAttribution: sgabe commentedChanging title to a more descriptive one.
Attached patch applies to 6.x-1.0-alpha2.
Comment #24
allartk CreditAttribution: allartk commentedIt seems I was confused by another issue as described here: http://www.ecitadel.net/blog/2010/01/06/drupal-mimemail-missing-embedded...
Anyhow I reverted the above change I made to alpha 2.
Comment #25
sgabe CreditAttribution: sgabe commented@allartk: So, is this issue still valid or not (or duplicate)? Please change the status, if needed.
Comment #26
ikeigenwijs CreditAttribution: ikeigenwijs commentedsubscribe
Comment #27
sgabe CreditAttribution: sgabe commentedNo activity and it seems to be fixed. Closing issue.