/[drupal]/contributions/modules/mass_contact/mass_contact.module
ViewVC logotype

Diff of /contributions/modules/mass_contact/mass_contact.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2.2.26, Tue Jul 29 22:48:06 2008 UTC revision 1.2.2.27, Fri Aug 1 06:58:14 2008 UTC
# Line 21  function mass_contact_help($section) { Line 21  function mass_contact_help($section) {
21    switch ($section) {    switch ($section) {
22      case 'admin/help#mass_contact':      case 'admin/help#mass_contact':
23        $output .= '<p><b>'. t('Related tasks:') .'</b><br /><ol>'.        $output .= '<p><b>'. t('Related tasks:') .'</b><br /><ol>'.
24          '<li>' . l('Set Permissions', 'admin/user/access', array(), NULL, 'module-mass_contact') .'</li>'.          '<li>'. l('Set Permissions', 'admin/user/access', array(), NULL, 'module-mass_contact') .'</li>'.
25          '<li>' . l('List current categories', 'admin/build/mass_contact') .'</li>'.          '<li>'. l('List current categories', 'admin/build/mass_contact') .'</li>'.
26          '<li>' . l('Add new category', 'admin/build/mass_contact/add') .'</li>'.          '<li>'. l('Add new category', 'admin/build/mass_contact/add') .'</li>'.
27          '<li>' . l('Configure the module', 'admin/build/mass_contact/settings') .'</li>'.          '<li>'. l('Configure the module', 'admin/build/mass_contact/settings') .'</li>'.
28          '<li>' . l('Send mass e-mail', 'mass_contact') .'</li></ol>';          '<li>'. l('Send mass e-mail', 'mass_contact') .'</li></ol>';
29        $output .= '<p>'. t('The Mass Contact module is simply a modified version of the core contact module. It works opposite the latter, in that it allows site moderators (or anyone with permission), to <a href="mass_contact">send mass e-mail</a> to a set role or group of roles or even to all registered users.') .'</p>';        $output .= '<p>'. t('The Mass Contact module is simply a modified version of the core contact module. It works opposite the latter, in that it allows site moderators (or anyone with permission), to <a href="mass_contact">send mass e-mail</a> to a set role or group of roles or even to all registered users.') .'</p>';
30        $output .= '<p>'. t("The sender's own address may be placed in the 'To:' field and all recipients placed in the 'BCC:' field, or the recipients simply placed in the 'To:' field. Note that the latter option leaves all recipients open to abuse due to their e-mail addresses being visible to all other recipients.") .'</p>';        $output .= '<p>'. t("The sender's own address may be placed in the 'To:' field and all recipients placed in the 'BCC:' field, or the recipients simply placed in the 'To:' field. Note that the latter option leaves all recipients open to abuse due to their e-mail addresses being visible to all other recipients.") .'</p>';
31        $output .= '<p>'. t("The e-mail may be sent as HTML or plain text, and may include a single binary file attachment (if permitted by admin).") .'</p>';        $output .= '<p>'. t("The e-mail may be sent as HTML or plain text, and may include a single binary file attachment (if permitted by admin).") .'</p>';
# Line 851  function mass_contact_mail_page() { Line 851  function mass_contact_mail_page() {
851      );      );
852      $form['tasklist']['list'] = array(      $form['tasklist']['list'] = array(
853        '#value' => '<p><ol>'.        '#value' => '<p><ol>'.
854          '<li>' . l('Set Permissions', 'admin/user/access', array(), NULL, 'module-mass_contact') .'</li>'.          '<li>'. l('Set Permissions', 'admin/user/access', array(), NULL, 'module-mass_contact') .'</li>'.
855          '<li>' . l('List current categories', 'admin/build/mass_contact') .'</li>'.          '<li>'. l('List current categories', 'admin/build/mass_contact') .'</li>'.
856          '<li>' . l('Add new category', 'admin/build/mass_contact/add') .'</li>'.          '<li>'. l('Add new category', 'admin/build/mass_contact/add') .'</li>'.
857          '<li>' . l('Configure the module', 'admin/build/mass_contact/settings') .'</li>'.          '<li>'. l('Configure the module', 'admin/build/mass_contact/settings') .'</li>'.
858          '<li>' . l('Help', 'admin/help/mass_contact') .'</li></ol>',          '<li>'. l('Help', 'admin/help/mass_contact') .'</li></ol>',
859      );      );
860    }    }
861    
# Line 892  function mass_contact_mail_page_validate Line 892  function mass_contact_mail_page_validate
892   *   The array of values returned by the form.   *   The array of values returned by the form.
893   */   */
894  function mass_contact_mail_page_submit($form_id, $form_values) {  function mass_contact_mail_page_submit($form_id, $form_values) {
895    global $user;    $bcc                 = $form_values['bcc'];
896      $nodecc              = $form_values['nodecc'];
897    $bcc                = $form_values['bcc'];    $send_error          = 0;
   $nodecc             = $form_values['nodecc'];  
   $send_error         = 0;  
898    // E-mail address of the sender: as the form field is a text field,    // E-mail address of the sender: as the form field is a text field,
899    // all instances of \r and \n have been automatically stripped from it.    // all instances of \r and \n have been automatically stripped from it.
900    $from               = $form_values['mail'];    $from                = $form_values['mail'];
901    $uid                = '';  
902    $ctype              = '';    $boundary_attachment = md5(uniqid(mt_rand()));
903    $headers            = array();    $boundary_html       = md5(uniqid(mt_rand()));
904    $message_attachment = array();    $character_set       = variable_get('mass_contact_character_set', '') ? variable_get('mass_contact_character_set', '') : 'UTF-8';
905    $character_set      = variable_get('mass_contact_character_set', 'UTF-8');    $headers             = array();
906    
907      $body_plain          = '';
908      $body_html           = '';
909      $message             = '';
910      $message_attachment  = array();
911    
   if (!$character_set) {  
     $character_set = 'UTF-8';  
   }  
912    
913    // Create the headers based on presence or absence of an attachment.    // Set the "Content-Type" header based on the presence or absence of an
914      // attachment and the HTML setting.
915    if ($_FILES['files']['size']['attachment'] > 0) {    if ($_FILES['files']['size']['attachment'] > 0) {
916      if (!module_exists('mimemail') || variable_get('mimemail_alter', 0) == 0) {      $headers['Content-Type'] = 'multipart/mixed; boundary="'. $boundary_attachment .'"';
917        $uid = md5(uniqid(time()));    }
918        $headers['Content-Type'] = 'multipart/mixed; boundary="'. $uid .'"';    elseif ($form_values['html']) {
919        $headers['Content-Type'] = 'multipart/alternative; boundary="'. $boundary_html .'"';
920      }
921      else {
922        $headers['Content-Type'] = 'text/plain; charset='. $character_set .'; format=flowed';
923      }
924    
925    
926        if ($form_values['html'] == 1) {    // Create the plain text body. We now always create a plain text body.
927          $ctype = 'Content-Type: text/html; charset='. $character_set .'; format=flowed';    if ($form_values['html']) {
928        // If this is supposed to be an HTML e-mail, we need to process the plain
929        // text part differently.
930        // Make this process better, by utilizing existing modules. This will
931        // become the norm, eliminating the need for the module check.
932        if (module_exists('html_to_text')) {
933          // Start with the message prefix.
934          if (module_exists('token')) {
935            $body_plain .= drupal_html_to_text(check_markup(token_replace(variable_get('mass_contact_message_prefix', '')))) ."\n";
936        }        }
937        else {        else {
938          $ctype = 'Content-Type: text/plain; charset='. $character_set .'; format=flowed';          $body_plain .= drupal_html_to_text(check_markup(variable_get('mass_contact_message_prefix', ''))) ."\n";
939        }        }
940    
941        $message[] = "\n--". $uid ."\n". $ctype ."\n\n";        // Add in the actual message.
942          $body_plain .= drupal_html_to_text(check_markup($form_values['message'])) ."\n";
943    
944          // End with the message suffix.
945          if (module_exists('token')) {
946            $body_plain .= drupal_html_to_text(check_markup(token_replace(variable_get('mass_contact_message_suffix', ''))));
947          }
948          else {
949            $body_plain .= drupal_html_to_text(check_markup(variable_get('mass_contact_message_suffix', '')));
950          }
951      }      }
952    }      else {
953    elseif ($form_values['html'] == 1) {        // Start with the message prefix.
954      $headers['Content-Type'] = 'text/html; charset='. $character_set .'; format=flowed';        if (module_exists('token')) {
955    }          $body_plain .= wordwrap(strip_tags(check_markup(token_replace(variable_get('mass_contact_message_prefix', ''))))) ."\n";
956    elseif ($character_set) {        }
957      $headers['Content-Type'] = 'text/plain; charset='. $character_set .'; format=flowed';        else {
958    }          $body_plain .= wordwrap(strip_tags(check_markup(variable_get('mass_contact_message_prefix', '')))) ."\n";
959          }
960    
961          // Add in the actual message.
962          $body_plain .= wordwrap(strip_tags(check_markup($form_values['message']))) ."\n";
963    
964    // Compose the body:        // End with the message suffix.
965    // Start with the message prefix.        if (module_exists('token')) {
966    if (module_exists('token')) {          $body_plain .= wordwrap(strip_tags(check_markup(token_replace(variable_get('mass_contact_message_suffix', '')))));
967      $message[]      = token_replace(variable_get('mass_contact_message_prefix', ''));        }
968      $node_message[] = token_replace(variable_get('mass_contact_message_prefix', ''));        else {
969            $body_plain .= wordwrap(strip_tags(check_markup(variable_get('mass_contact_message_suffix', ''))));
970          }
971        }
972    }    }
973    else {    else {
974      $message[]      = variable_get('mass_contact_message_prefix', '');      // Start with the message prefix.
975      $node_message[] = variable_get('mass_contact_message_prefix', '');      if (variable_get('mass_contact_message_prefix', '')) {
976    }        if (module_exists('token')) {
977            $body_plain .= wordwrap(token_replace(variable_get('mass_contact_message_prefix', ''))) ."\n\n";
978    if ($form_values['html'] == 1) {        }
979      // Add a spacer for HTML formatted messages.        else {
980      $message[]      = "<p>";          $body_plain .= wordwrap(variable_get('mass_contact_message_prefix', '')) ."\n\n";
981      $node_message[] = "<p>";        }
982        }
983    
984      // Add in the actual message.      // Add in the actual message.
985      $message[]      = check_markup(wordwrap($form_values['message']));      $body_plain .= wordwrap($form_values['message']) ."\n";
     $node_message[] = check_markup(wordwrap($form_values['message']));  
986    
987      // Add a spacer for HTML formatted messages.      // End with the message suffix.
988      $message[]      = "<p>";      if (variable_get('mass_contact_message_suffix', '')) {
989      $node_message[] = "<p>";        if (module_exists('token')) {
990            $body_plain .= wordwrap(token_replace(variable_get('mass_contact_message_suffix', '')));
991          }
992          else {
993            $body_plain .= wordwrap(variable_get('mass_contact_message_suffix', ''));
994          }
995        }
996    }    }
997    else {  
998    
999      // If this is an HTML message, create the HTML body part.
1000      if ($form_values['html']) {
1001        // Start with the message prefix.
1002        if (module_exists('token')) {
1003          $body_html .= check_markup(token_replace(variable_get('mass_contact_message_prefix', '')));
1004        }
1005        else {
1006          $body_html .= check_markup(variable_get('mass_contact_message_prefix', ''));
1007        }
1008    
1009        // Add a spacer.
1010        $body_html .= '<p>';
1011    
1012      // Add in the actual message.      // Add in the actual message.
1013      $message[]      = check_plain(wordwrap($form_values['message']));      $body_html .= check_markup($form_values['message']);
1014      $node_message[] = check_plain(wordwrap($form_values['message']));  
1015        // Add a spacer.
1016        $body_html .= '</p>';
1017    
1018        // End with the message suffix.
1019        if (module_exists('token')) {
1020          $body_html .= check_markup(token_replace(variable_get('mass_contact_message_suffix', '')));
1021        }
1022        else {
1023          $body_html .= check_markup(variable_get('mass_contact_message_suffix', ''));
1024        }
1025    }    }
1026    
1027    // End with the message suffix.  
1028    if (module_exists('token')) {    // Put it all together.
1029      $message[]      = token_replace(variable_get('mass_contact_message_suffix', ''));    // Check to see if we have either an attachment or an HTML message.
1030      $node_message[] = token_replace(variable_get('mass_contact_message_suffix', ''));    if (($_FILES['files']['size']['attachment'] > 0) || $form_values['html']) {
1031        // If we have either, we need the following.
1032        $message .= "\nThis is a multi-part message in MIME format.\n";
1033    
1034        // Add our boundary, based on the content.
1035        if ($_FILES['files']['size']['attachment'] > 0) {
1036          $message .= "\n--". $boundary_attachment ."\n";
1037        }
1038        else {
1039          $message .= "\n--". $boundary_html ."\n";
1040        }
1041    
1042        // If we have both an attachment and an HTML message, we need the following.
1043        if (($_FILES['files']['size']['attachment'] > 0) && $form_values['html']) {
1044          $message .= 'Content-Type: multipart/alternative; boundary="'. $boundary_html .'"'."\n";
1045          $message .= "\n--". $boundary_html ."\n";
1046        }
1047    
1048        // Add the plain text part to the message.
1049        $message .= "Content-Type: text/plain; charset=$character_set; format=flowed\n";
1050        $message .= "Content-Transfer-Encoding: 8bit\n\n";
1051        $message .= $body_plain;
1052    
1053        // If there is an HTML part, add it to the message.
1054        if ($form_values['html']) {
1055          $message .= "\n--". $boundary_html ."\n";
1056          $message .= "Content-Type: text/html; charset=$character_set; format=flowed\n";
1057          $message .= "Content-Transfer-Encoding: 8bit\n\n";
1058          $message .= $body_html;
1059        }
1060    }    }
1061    else {    else {
1062      $message[]      = variable_get('mass_contact_message_suffix', '');      // There is neither an attachment nor an HTML message, so this is not a
1063      $node_message[] = variable_get('mass_contact_message_suffix', '');      // multipart message, and we just add the plain text part.
1064        $message = $body_plain;
1065    }    }
1066    
1067    // Add attachment.  
1068      // For the node copy, we want to handle attachments differently, so we'll
1069      // save the message as it currently stands.
1070      if (variable_get('mass_contact_nodecc_d', 1)) {
1071        $node_message = $message;
1072      }
1073    
1074    
1075      // If there is an attachment, add it.
1076    if ($_FILES['files']['size']['attachment'] > 0) {    if ($_FILES['files']['size']['attachment'] > 0) {
1077        // Oy! If Mime Mail is installed and active, we have to do things
1078        // differently for it. (This may change when I refactor how attachments
1079        // are handled.)
1080      if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {      if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {
1081        $message_attachment = array(        $message_attachment = array(
1082          array(          array(
# Line 986  function mass_contact_mail_page_submit($ Line 1087  function mass_contact_mail_page_submit($
1087        );        );
1088      }      }
1089      else {      else {
1090        $message_attachment  = '--'. $uid ."\n";        $message_attachment  = "\n--". $boundary_attachment ."\n";
1091        $message_attachment .= "Content-Type: ". $_FILES['files']['type']['attachment'] ."; name=\"". basename($_FILES['files']['name']['attachment']) ."\"\n";        $message_attachment .= 'Content-Type: '. $_FILES['files']['type']['attachment'] .'; name="'. basename($_FILES['files']['name']['attachment']) .'"'."\n";
1092        $message_attachment .= "Content-Transfer-Encoding: base64\n";        $message_attachment .= "Content-Transfer-Encoding: base64\n";
1093        $message_attachment .= "Content-Disposition: attachment; filename=\"". basename($_FILES['files']['name']['attachment']) ."\"\n\n";        $message_attachment .= 'Content-Disposition: attachment; filename="'. basename($_FILES['files']['name']['attachment']) .'"'."\n\n";
1094        $message_attachment .= chunk_split(base64_encode(file_get_contents($_FILES['files']['tmp_name']['attachment'])));        $message_attachment .= chunk_split(base64_encode(file_get_contents($_FILES['files']['tmp_name']['attachment'])));
1095        $message_attachment .= "\n\n--". $uid ."--\n\n";        $message_attachment .= "\n--". $boundary_attachment ."--\n";
1096    
1097        $message[]           = $message_attachment;        $message .= $message_attachment;
1098      }      }
1099    }    }
1100    
1101    
1102    
1103    ///////////////////////////////////////////////////////////////////////////    ///////////////////////////////////////////////////////////////////////////
1104    //    //
1105    //  @TODO:  The whole rest of this function needs to be re-thought out and    //  @TODO:  The whole rest of this function needs to be re-thought out and
# Line 1007  function mass_contact_mail_page_submit($ Line 1109  function mass_contact_mail_page_submit($
1109    ///////////////////////////////////////////////////////////////////////////    ///////////////////////////////////////////////////////////////////////////
1110    
1111  /*  /*
   
1112    Task order:    Task order:
1113        Create the e-mail message, starting w/the header
1114      Get the list of categories      Get the list of categories
1115      Create the list of recipients      Create the list of recipients
1116      Compose the e-mail message, starting w/the header      Add the list of recipients to the e-mail message
   
1117   */   */
1118    
1119    
1120    
1121    // Load the category information.    // Load the category information.
1122    foreach ($form_values['cid'] as $cid) {    foreach ($form_values['cid'] as $cid) {
1123      $cids .= $cid;      $cids .= $cid;
# Line 1035  function mass_contact_mail_page_submit($ Line 1137  function mass_contact_mail_page_submit($
1137      }      }
1138    
1139      // Prepare the body.      // Prepare the body.
1140      $body      = implode("\n\n", $message);      $body      = $message;
1141      $node_body = implode("\n\n", $node_message);      $node_body = $node_message;
1142      $uidooa    = array();      $uidooa    = array();
1143    
1144      // Check for opt-out unless overridden by admin.      // Check for opt-out unless overridden by admin.
# Line 1054  function mass_contact_mail_page_submit($ Line 1156  function mass_contact_mail_page_submit($
1156        }        }
1157      }      }
1158    
1159        global $user;
1160    
1161      // Create the recipient list.      // Create the recipient list.
1162      $recipientouta = array();      $recipientouta = array();
1163      $roles = explode(',', $contact->recipients);      $roles = explode(',', $contact->recipients);
# Line 1127  function mass_contact_mail_page_submit($ Line 1231  function mass_contact_mail_page_submit($
1231    
1232            // Send the e-mail to the recipients:            // Send the e-mail to the recipients:
1233            if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {            if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {
1234              if ($form_values['html'] == 1) {              if ($form_values['html']) {
1235                $success = mimemail($from, $to, $subject, $body, NULL, $headers, NULL, $message_attachment);                $success = mimemail($from, $to, $subject, $body_html, NULL, $headers, $body_plain, $message_attachment, 'mass-contact-page-mail');
1236              }              }
1237              else {              else {
1238                $success = mimemail($from, $to, $subject, $body, TRUE, $headers, $body, $message_attachment);                $success = mimemail($from, $to, $subject, $body_html, TRUE, $headers, $body_plain, $message_attachment, 'mass-contact-page-mail');
1239              }              }
1240            }            }
1241            else {            else {
# Line 1171  function mass_contact_mail_page_submit($ Line 1275  function mass_contact_mail_page_submit($
1275    
1276          // Send the e-mail to the recipients:          // Send the e-mail to the recipients:
1277          if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {          if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {
1278            if ($form_values['html'] == 1) {            if ($form_values['html']) {
1279              $success = mimemail($from, $to, $subject, $body, NULL, $headers, NULL, $message_attachment);              $success = mimemail($from, $to, $subject, $body_html, NULL, $headers, $body_plain, $message_attachment, 'mass-contact-page-mail');
1280            }            }
1281            else {            else {
1282              $success = mimemail($from, $to, $subject, $body, TRUE, $headers, $body, $message_attachment);              $success = mimemail($from, $to, $subject, $body_html, TRUE, $headers, $body_plain, $message_attachment, 'mass-contact-page-mail');
1283            }            }
1284          }          }
1285          else {          else {
# Line 1216  function mass_contact_mail_page_submit($ Line 1320  function mass_contact_mail_page_submit($
1320    
1321        // Send the e-mail to the recipients.        // Send the e-mail to the recipients.
1322        if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {        if (module_exists('mimemail') && variable_get('mimemail_alter', 0) == 1) {
1323          if ($form_values['html'] == 1) {          if ($form_values['html']) {
1324            $success = mimemail($from, $to, $subject, $body, NULL, $headers, NULL, $message_attachment);            $success = mimemail($from, $to, $subject, $body_html, NULL, $headers, $body_plain, $message_attachment, 'mass-contact-page-mail');
1325          }          }
1326          else {          else {
1327            $success = mimemail($from, $to, $subject, $body, TRUE, $headers, $body, $message_attachment);            $success = mimemail($from, $to, $subject, $body_html, TRUE, $headers, $body_plain, $message_attachment, 'mass-contact-page-mail');
1328          }          }
1329        }        }
1330        else {        else {

Legend:
Removed from v.1.2.2.26  
changed lines
  Added in v.1.2.2.27

  ViewVC Help
Powered by ViewVC 1.1.2