Index: listhandler.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/listhandler/listhandler.module,v
retrieving revision 1.75.2.1
diff -u -p -r1.75.2.1 listhandler.module
--- listhandler.module	18 Dec 2007 21:25:05 -0000	1.75.2.1
+++ listhandler.module	20 Dec 2007 15:55:48 -0000
@@ -212,6 +212,7 @@ function listhandler_comment($edit = arr
 
 function listhandler_send_mail($edit) {
   global $user, $base_url;
+  $mid=array();
 
   if(!$user->uid) {
     $edit['name'] = variable_get('anonymous', 'Anonymous');
@@ -268,8 +269,8 @@ function listhandler_send_mail($edit) {
     $edit['pid']=0;
   }
   if($result) {// Parent was sent or received by listhandler
-    $mid = "References: ". $result->msgid ."\n";
-    $mid .= "In-Reply-To: ". $result->msgid ."\n";
+    $mid['References'] = $result->msgid;
+    $mid['In-Reply-To'] = $result->msgid;
   }
   //common headers
   $dir = str_replace("/", ".", substr(strchr(str_replace("http://", "", $base_url), "/"), 1));
@@ -279,7 +280,7 @@ function listhandler_send_mail($edit) {
     $edit["tid"] = $mbox[2];
     // We add tokens to the MID. Replies to comments sent by listhandler can thus be classified easier.
     $msgid = "<listhandler=". $edit["mid"] ."&site=". $dir . $_SERVER["SERVER_NAME"] ."&nid=". $edit["nid"] ."&pid=". $edit["pid"] ."&cid=".  $edit["cid"] ."&uid=". $user->uid ."&tid=".  $edit["tid"] ."&". md5($edit["nid"] . $edit["cid"]) ."@". $dir . strtolower($_SERVER["SERVER_NAME"]) .">";
-    $mid .= "Message-Id: ". $msgid ."\n";
+    $mid['Message-Id']=$msgid;
     // send mail
     $file = drupal_get_path('module', 'listhandler') .'/mail.inc';
     if (file_exists($file)) {
@@ -293,16 +294,44 @@ function listhandler_send_mail($edit) {
       $subject = strip_tags($edit['subject']);
       $body = strip_tags($edit['comment']);
     }
-
-    // OLD  $err = user_mail($address, $subject, $body, "From: ". $edit["name"] ." <". $edit["mail"] .">\n". $mid);
-
-    $err = drupal_mail($mid, $address, $subject, $body, $edit["mail"]);
+    $attachments = '';
+    $fragment = NULL;
+    $lfiles = false;
+    if ($edit['cid']) {
+      $fragment = 'comment-'.$edit['cid'];
+      //attachment comments are already created
+      if (function_exists('_comment_upload_load_files')) {
+	$lfiles = _comment_upload_load_files($edit['cid']);
+      }
+    } else {
+      $lfiles = $edit['files'];
+    }
+    if ($lfiles) {
+      foreach ($lfiles as $key => $ufile) {
+	$ufile = (object) $ufile;
+	$href = file_create_url((strpos($ufile->fid, 'upload') === FALSE ? $ufile->filepath : file_create_filename($ufile->filename, file_create_path())));
+	$href = str_replace(' ', '%20', $href);
+	$text = $ufile->description ? $ufile->description : $ufile->filename ;
+	$attachments .= "\n\n"." [".$text."]:\n".$href;
+      }
+      if (!empty($attachments)) {
+	$url = url ('node/'.$edit['nid'],NULL,$fragment,TRUE);
+	$body .= "\n\n".t('File attachments').":";
+	$body .= $attachments;
+	$body .= "\n----------\n".t("Original attachments can be found at:\n!u",array('!u' => $url));
+      }
+    }
+    $ok = drupal_mail('listhandler-mail', $address, $subject, $body, $edit["mail"],$mid);
 
     // save comment ids in listhandler table.
     // Not strictly needed, the same info is stored in the msgid.
     db_query("INSERT INTO {listhandler} (msgid, nid, cid, pid, uid, mid, tid) VALUES ('%s','%s','%s','%s','%s','%s','%s')", $msgid, $edit["nid"], $edit["cid"], $edit["pid"], $user->uid, $edit["mid"], $edit["tid"]);
     // call watchdog
-    watchdog('listhandler', t("'!s' sent to '!a'.", array("!s" => $edit["subject"], "!a" => $address)));
+    if ($ok) { 
+    	watchdog('listhandler', t("'!s' sent to '!a'.", array("!s" => $edit["subject"], "!a" => $address)));
+    } else {
+    	watchdog('listhandler', t("Error sending '!s' to '!a'.", array("!s" => $edit["subject"], "!a" => $address)));
+    }
   }
 }
 
