Hello!

I'm not sure if I miss something here, but how do I put additional Variables to mimemail.tpl.php without altering mimemail_theme_theme()?
Besides the $body variable, I also need the $subject to put it in the email too.

I am aware that I could use the templatehook_preprocess_mimemail_message(&$variables) to add "own" variables,
but thats useless until I have no possibility to access $subject.

The only way I see, is that you alter mimemail_theme_theme(), to let it pass $subject as an extra argument to the template and then call theme('mimemail_message', $body, $mailkey, $subject); in mimemail.module.

I would provide a patch if needed!

Thanks in advance!!

Comments

sgabe’s picture

I think you are right, mimemail_theme_theme() should pass the $subject as argument to the template. I am willing to test and review your patch if you attach one.

sgabe’s picture

Status: Active » Needs review
StatusFileSize
new2.04 KB

Or maybe you can review mine.

dsms’s picture

Status: Needs review » Reviewed & tested by the community

Oh thanks, I really appreciate your fast work! I testet it against -alpha1 and it works well!

Please drop a line, when you'll have included the patch in -dev.

Hervé Saladin’s picture

Seems to work fine for me too.
Thanks :)

Mac Clemmens’s picture

Here's the same patch that allows the $recipient variable to be passed to the theme function as well. This is very helpful when theming in specific things for the $recipient. (Such as "Premium member" on the header of the e-mail, or "Edit your profile").

When I first started theming, I didn't get that $vars['user'] variable in theme_preprocess_mimemail_message($vars, $hook) was the user who triggered the e-mail to send (in some cases an anonymous user) not the actual recipient. So if user 1 ran cron.php which caused an e-mail to be sent to user 2, $vars['user']['uid'] would be 1. I made the mistake of assuming that $vars['user'] was the recipient, but that is not the case. (But appears to be the case when testing.)

Adding $recipient to the theme_preprocess_mimemail_message function solves that.

My 2 cents.

I don't have access to CVS at the moment, (sorry) but here is the patch:


--- mimemail.module (saved version)
+++ (current document)
@@ -124,8 +124,8 @@
       }
     }
   }
-  $subject = mime_header_encode(trim(drupal_html_to_text($subject)));
-  $body = theme('mimemail_message', $body, $mailkey);
+  $subject = trim(drupal_html_to_text($subject));
+  $body = theme('mimemail_message', $subject, $body, $mailkey, $recipient);
   foreach (module_implements('mail_post_process') as $module) {
     $function = $module .'_mail_post_process';
     $function($body, $mailkey);
@@ -137,7 +137,7 @@
   $headers   = array_merge($headers, $mail['headers']);
   $message   = array(
     'address' => mimemail_address($recipient),
-    'subject' => $subject,
+    'subject' => mime_header_encode($subject),
     'body'    => $mail['body'],
     'sender'  => $sender,
     'headers' => mimemail_headers($headers, $sender),

--- mimemail.theme.inc (saved version)
+++ (current document)
@@ -5,7 +5,7 @@
 
   return array(
     'mimemail_message' => array(
-      'arguments' => array('body' => NULL, 'mailkey' => NULL),
+      'arguments' => array('subject' => NULL, 'body' => NULL, 'mailkey' => NULL, 'recipient' => NULL),
       'template' => 'mimemail-message',
       'pattern' => 'mimemail__',
       'file' => 'mimemail.theme.inc',
Mac Clemmens’s picture

Status: Reviewed & tested by the community » Needs review
sgabe’s picture

Title: Add $subject to mimemail.tpl.php » Pass $subject to the template
Version: 6.x-1.0-alpha1 » 7.x-1.x-dev
StatusFileSize
new2.11 KB

@Mac Clemmens: Please open a new issue for your request, $recipient won't get in with this issue.

Attaching a new patch against current HEAD.

sgabe’s picture

Status: Needs review » Fixed

Committed to HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.