From 9e6a297391660f35b6ad5a8d20eeb1c3d5f5658d Mon Sep 17 00:00:00 2001
From: Sean Dague <sean@dague.net>
Date: Sun, 9 Oct 2011 11:28:04 -0400
Subject: [PATCH] add linkimages preference

---
 includes/mimemail.admin.inc |    7 +++++++
 mimemail.inc                |   13 ++++++++++++-
 2 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/includes/mimemail.admin.inc b/includes/mimemail.admin.inc
index a834ec6..5a8d8be 100644
--- a/includes/mimemail.admin.inc
+++ b/includes/mimemail.admin.inc
@@ -72,6 +72,13 @@ function mimemail_admin_settings() {
     '#disabled'      => $disable_sitestyle,
   );
 
+  $form['mimemail']['mimemail_linkimages'] = array(
+    '#type'          => 'checkbox',
+    '#title'         => t('Link Images in HTML instead of including them'),
+    '#default_value' => variable_get('mimemail_linkimages', 0),
+    '#description'   => t('Instead of mime encoding and including images in the email, convert images to links to the website. This makes emails much smaller')
+  );
+
   $filter_format = variable_get('mimemail_format', FILTER_FORMAT_DEFAULT);
   $form['mimemail']['mimemail_format'] =  filter_form($filter_format, NULL, array("mimemail_format"));
 
diff --git a/mimemail.inc b/mimemail.inc
index 4ef9df3..a4d8e4e 100644
--- a/mimemail.inc
+++ b/mimemail.inc
@@ -113,7 +113,7 @@ function _mimemail_replace_files($matches) {
  *   The actual file content.
  *
  * @return
- *   The Content-ID and/or an array of the files on success or the URL on failure. 
+ *   The Content-ID and/or an array of the files on success or the URL on failure.
  */
 function _mimemail_file($url = NULL, $content = NULL, $name = '', $type = '', $disposition = 'related') {
   static $files = array();
@@ -543,6 +543,17 @@ function _mimemail_url($url, $embed_file = NULL) {
   global $base_url;
   $url = urldecode($url);
 
+  // If the preference is set, make the image urls into absolute links
+  if (variable_get('mimemail_linkimages', 0)) {
+    if (preg_match('!\.(png|gif|jpg|jpeg)$!i', $url)) {
+      if (strpos($url, '://') === FALSE) {
+        $url = $base_url . $url;
+      }
+      $url = str_replace(' ', '%20', $url);
+      return $url;
+    }
+  }
+
   // If the URL is absolute or a mailto, return it as-is.
   if (strpos($url, '://') !== FALSE || preg_match('!mailto:!', $url)) {
     $url = str_replace(' ', '%20', $url);
-- 
1.7.4.1

