In the theme_mimemail_message function please add $mailkey to the body tag as a css class. This will allow you to change styling for different emails only through mail.css (or the main css file of theme) without overriding the theme_mimemail_message function. The class name should probably be prefixed with something like "mailkey-".
The mailkey would have to be sanitized so it is a safe css class name.
If you can figure the name of the module that called the mimemail function then that can also be added as a class (with a prefix like "module-").
A similar option would be to first try to load 'mail-'. $mailkey .'.css' and if that fails then next try 'mail.css'. Of course, only if mailkey is not NULL. If the module name is available, then here too you could do a two step trial, by having the module name part of the css file name.
For example, if simplenews is sending a mimemail with a mailkey set to "weekly" then the following css files are attempted:
- mail-simplenews-weekly.css
- mail-simplenews.css
- mail.css
And the body tag for this example would look like:
<body id="mimemail" class="module-simplenews mailkey-weekly">
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | mimemail.319384_03.patch | 1.27 KB | sgabe |
| #4 | mimemail.319384_02.patch | 1.41 KB | sgabe |
| #3 | mimemail.319384_01.patch | 714 bytes | sgabe |
Comments
Comment #1
sgabe commentedI have implemented this feature in #743150: Mime Mail 6.x-1.0-beta1?, I would appreciate it if you could test it and report back.
Comment #2
sgabe commented#768216: How to theme different mails marked as a duplicate.
@preper:
@RodrigoBalest:
In the actual state of things this feature depends on several issues that are need to get in before it can be implemented:
Here is the point, there is an
idelement in the$messagearray generated by drupal_mail().The #567594: $mailkey is not properly set in drupal_mail_wrapper() issue aims to set the
$mailkeywith the value of the$message['id']. Then we shall use that as another argument, and also themimemail_message__pattern in ourhook_theme()implementation, what will allow us to use custom CSS and template files likemail-[mailkey].cssandmimemail-message--[mailkey].tpl.php.Another issue that contributed modules e.g Simplenews, should use a proper
$mailkeywhen callingmimemail(), otherwise we won't be able to use this feature. Currently Simplenews (and other contributed modules) doesn't do that. Core modules like Actions and Contact uses mailkeys like system_action_send_email and contact_user_mail. In these cases the files would bemail-contact-user-mail.cssandmimemail-message--contact-user-mail.tpl.php. This goes for #501722: HTML mail actions for Rules which doesn't callmimemail()with proper mailkey either. However I'm planning to update that issue with this soon.In a nutshell, we have a lot to do before we could implement this in a general way. The good news as I posted before, I have implemented this functionality in #743150: Mime Mail 6.x-1.0-beta1?, so you can take a look at that if you would like to try.
Comment #3
sgabe commentedThe
$mailkeyvariable is already passed to the template, but it doesn't use it.Comment #4
sgabe commentedProcess $mailkey to be a proper CSS class.
Comment #5
sgabe commentedMove the whole thing to template_preprocess_mimemail_message().
Comment #6
sgabe commentedCommitted to HEAD.
Comment #8
-Mania- commentedShould this be working for 6.x? I can't seem to get the mailkey value printed. Every time I send a Simplenews email the body class prints as class="mail-".