--- /var/www/jodila/modules/mailhandler/mailhandler.module.old	2006-03-03 13:36:12.000000000 -0400
+++ /var/www/jodila/modules/mailhandler/mailhandler.module	2006-03-07 01:56:25.000000000 -0400
@@ -51,6 +51,7 @@
       mailhandler_switch_user($node->uid);
 
       // modules may override node elements before submitting. they do so by returning the node.
+      if (user_access('post by mail to '.$mailbox['mail'], $mail_user)) {
       foreach (module_list() as $name) {
         if (module_hook($name, "mailhandler")) {
           $function = $name. "_mailhandler";
@@ -66,14 +67,37 @@
           mailhandler_comment_submit($node, $header, $mailbox, $origbody);
         }
         else {
-          mailhandler_node_submit($node, $header, $mailbox, $origbody);
+	          if (mailhandler_node_submit($node, $header, $mailbox, $origbody)) 
+	          	mailhandler_set_message(
+	          		t(
+	          			variable_get('mailhandler_successful_post',
+	          		'The following message has been succesfully processed.<br/>'.
+	          			'You can edit that message by following this link : %link <br/><br/>'.
+	          			'Thank you for using %site services.<br/><br/>'),
+	          			array(
+	          				'%link' => url("node/$node->nid",NULL,NULL,TRUE),
+	          				'%site' => variable_get("site_name", "Drupal"), 
+	          				'%message_body' => $origbody
+	          			)
+	          		)
+	          	);
+	          			
+	        }
         }
       }
+      else if ($node->uid) { // no need to send an email to an unknown user, right ?
+        drupal_set_message(t('You are not allowed to post via email from this address'));
+        mailhandler_set_message(t('You are not allowed to post via email from this address'), 'error');
+      }
+      
       // don't delete while we're only getting new messages
       if($mailbox["delete_after_read"]) {
         imap_delete($result, $i);
       }
 
+      // send email response if warranted
+      mailhandler_email_response($header, $mailbox, $origbody);
+
       // switch back to original user
       mailhandler_switch_user();
     }
@@ -272,12 +296,13 @@
     watchdog('error', $txt);
     return array(t('Submission failed'), $txt);
   }
+  return $user;
 }
 
 /**
  * Create the node.
  */
-function mailhandler_node_submit($node, $header, $mailbox, $origbody) {
+function mailhandler_node_submit(&$node, $header, $mailbox, $origbody) {
 
   $fromaddress = mailhandler_get_fromaddress($header, $mailbox);
 
@@ -296,7 +321,7 @@
     }
     else {
       if (node_access("create", $node)) {
-        node_save($node);
+        $node->nid = node_save($node);
         watchdog("special", "Mailhandler: Added '$node->title' by $fromaddress");
       }
       else {
@@ -319,7 +344,63 @@
       $headers = "From: $sitemail\nReply-to: $sitemail\nX-Mailer: Drupal\nReturn-path: $sitemail\nErrors-to: $sitemail";
       user_mail($fromaddress, t("Email submission to %sn failed - %subj", array ("%sn" => variable_get("site_name", "Drupal"), "%subj" => $node->title)), $errortxt, $headers);
     }
+    
+    return FALSE;
   }
+  
+  return TRUE;
+}
+
+/**
+ * Get comment from body.
+ *
+ */
+function _mailhandler_process_commands(&$node,$commands,$sep) {
+
+    // process the commands and the body
+  $lines = explode("\n", $commands);
+  for ($i = 0; $i < count($lines); $i++) {
+    $line = trim($lines[$i]);
+
+    if ($line=='') continue; // get rid of empty lines
+    	    
+    // $words = explode(" ", $line);
+
+    $pattern = '/(\w+)\s*:\s*(.+)/'; // something like "truc<some space>:<some space> bidule"
+
+    // look for a command line. if not present, note which line number is the boundary
+    if (is_null($endcommands) && preg_match($pattern, $line, $data) ) {
+      // Looks like a name: value pair
+      // $data = explode(": ", $line, 2);
+
+      //TODO: allow for nested arrays in commands ... Possibly trim() values after explode().
+      // if needed, turn this command value into an array
+      if (substr($data[2], 0, 1) == "[" && substr($data[2], -1, 1) == "]") {
+        $data[2] = rtrim(ltrim($data[2], "["), "]"); //strip brackets
+        $data[2] = explode(",", $data[2]);
+      }
+      $data[1] = strtolower(str_replace(" ", "_", $data[1]));
+      // if needed, map term names into IDs. this should move to taxonomy_mailhandler()
+      if ($data[1] == "taxonomy" && !is_numeric($data[2][0])) {
+        array_walk($data[2], 'mailhandler_term_map');
+      }
+      $node->$data[1] = $data[2];
+    }
+    else if (is_null($endcommands)) {
+	      $endcommands = $i;
+    }
+
+    // stop when we encounter the sig. we'll discard all remaining text.
+    $start = substr($line, 0, strlen($sep)+3);
+    if ($sep && strstr($start, $sep)) { // mail clients sometimes prefix replies with ' >'
+      break;
+    }
+  }
+
+  $tmp = array_slice($lines, $endcommands, $i - $endcommands);
+  // return text without commands
+  return implode("\n", $tmp);
+
 }
 
 /**
@@ -353,47 +434,24 @@
 
   // prepend the default commands for this mailbox
   if ($mailbox["commands"]) {
-    $body = trim($mailbox["commands"]). "\n". $body;
+//    $body = trim($mailbox["commands"]). "\n". $body;
+	_mailhandler_process_commands($node,trim($mailbox["commands"]),$sep);
   }
 
   // process the commands and the body
-  $lines = explode("\n", $body);
-  for ($i = 0; $i < count($lines); $i++) {
-    $line = trim($lines[$i]);
-    $words = explode(" ", $line);
-    // look for a command line. if not present, note which line number is the boundary
-    if (substr($words[0], -1) == ":" && is_null($endcommands)) {
-      // Looks like a name: value pair
-      $data = explode(": ", $line, 2);
-
-      //TODO: allow for nested arrays in commands ... Possibly trim() values after explode().
-      // if needed, turn this command value into an array
-      if (substr($data[1], 0, 1) == "[" && substr($data[1], -1, 1) == "]") {
-        $data[1] = rtrim(ltrim($data[1], "["), "]"); //strip brackets
-        $data[1] = explode(",", $data[1]);
-      }
-      $data[0] = strtolower(str_replace(" ", "_", $data[0]));
-      // if needed, map term names into IDs. this should move to taxonomy_mailhandler()
-      if ($data[0] == "taxonomy" && !is_numeric($data[1][0])) {
-        array_walk($data[1], 'mailhandler_term_map');
-      }
-      $node->$data[0] = $data[1];
-    }
-    else {
-      if (is_null($endcommands)) $endcommands = $i;
-    }
+  $tmp= _mailhandler_process_commands($node,$body,$sep);
 
-    // stop when we encounter the sig. we'll discard all remaining text.
-    $start = substr($line, 0, strlen($sep)+3);
-    if ($sep && strstr($start, $sep)) { // mail clients sometimes prefix replies with ' >'
-      break;
-    }
+  // process mandatory commands
+  if ($mailbox["mandatory_commands"]) {
+//    $body = trim($mailbox["commands"]). "\n". $body;
+	_mailhandler_process_commands($node,trim($mailbox["mandatory_commands"]),$sep);
   }
 
   // isolate the body from the commands and the sig
-  $tmp = array_slice($lines, $endcommands, $i - $endcommands);
+  //$tmp = array_slice($lines, $endcommands, $i - $endcommands);
   // flatten and assign the body to node object. note that filter() is called within node_save() [tested with blog post]
-  $node->body = implode("\n", $tmp);
+  //$node->body = implode("\n", $tmp);
+  $node->body = $tmp;
 
   if (!$node->teaser) $node->teaser = node_teaser($node->body);
   if (!$node->type) $node->type = "blog";
@@ -430,14 +488,14 @@
 
   // $fromaddress really refers to the mail header which is authoritative for authentication
   $fromaddress = mailhandler_get_fromaddress($header, $mailbox);
-  if ($from_user = mailhandler_user_load($fromaddress, $node->pass)) {
+  if ($from_user = mailhandler_user_load($fromaddress, $node->pass,$node->code, $mailbox)) {
     $node->uid = $from_user->uid; // success!
     $node->name = $from_user->name;
   }
   else if (function_exists("mailalias_user")) { // since $fromaddress failed, try e-mail aliases
     $result = db_query("SELECT mail FROM {users} WHERE data LIKE '%". $fromaddress. "%'");
     while ($alias = db_result($result)) {
-      if ($from_user = mailhandler_user_load($alias, $node->pass)) {
+      if ($from_user = mailhandler_user_load($alias, $node->pass,$node->code, $mailbox)) {
         $node->uid = $from_user->uid; // success!
         $node->name = $from_user->name;
         break;
@@ -483,20 +541,23 @@
  * Retrieve user information from his email address.
  *
  */
-function mailhandler_user_load($mail, $pass) {
+function mailhandler_user_load($mail, $pass, $code, $mailbox) {
 
   if ($mailbox["security"] == 1) {
-    $theuser= user_load(array ("mail" => $mail, "pass" => $pass));
+    $loaded = user_load(array ("mail" => $mail, "pass" => $pass));
+    if (!$loaded) mailhandler_set_message(t('The password is not valid for this email.'),'error');
+    return $loaded;
+  }
+  else if ($mailbox["security"] == 2) { // check antispam code
+    $loaded= user_load(array ("mail" => $mail));
+    if ($loaded->mailhandler_antispam_code != $code ) {
+    	if ($code) mailhandler_set_message(t('The AntiSpam code is not valid for this email.\nPlease go to your account to check the AntiSpam code.'),'error');
+    	return FALSE;
+    } else return $loaded;
   }
   else {
-    $theuser= user_load(array ("mail" => $mail));
-  }
-  
-  if ($theuser) {
-  	if (user_access("access mailhandler",$theuser)) return $theuser;
+    return user_load(array ("mail" => $mail));
   } 
-  
-  return FALSE;
 }
 
 /**
@@ -575,23 +636,148 @@
   return "TEXT/PLAIN";
 }
 
+/*
+ * Initialize a globally scoped array to hold messages.
+ * Each set of messages will only exist for the amount of
+ * time it takes to process a mail message.
+ */
+$_mailhandler_messages = array();
+
+/**
+ * Set a message for the mail sender to see.
+ *
+ * The message is stored in the globally scoped $_mailhandler_messages array.
+ *
+ * If called with no arguments, this function returns all set messages without
+ * clearing them.
+ *
+ * @param $message The text message to send to the user
+ * @param $type    The message type, typically 'info', 'error' or 'debug'
+ *
+ * @return The current array of all message arrays.
+ */
+function mailhandler_set_message($message = NULL, $type = 'info') {
+  global $_mailhandler_messages;
+  
+  if (isset($message)) {
+    if (!is_array($_mailhandler_messages)) {
+      $_mailhandler_messages = array();
+    }
+
+    if (!isset($_mailhandler_messages[$type])) {
+      $_mailhandler_messages[$type] = array();
+    }
+
+    $_mailhandler_messages[$type][] = $message;
+  }
+
+  return $_mailhandler_messages;
+}
+
+/**
+ * Return all messages that have been set.
+ *
+ * As a side effect, this function clears the message queue.
+ */
+function mailhandler_get_messages() {
+  global $_mailhandler_messages;
+  
+  $messages = mailhandler_set_message();
+  $_mailhandler_messages = array();
+
+  return $messages;
+}
+
+/**
+ * Sends an email to the sender indicating errors that occurred and/or
+ * information about processing that went on.
+ *
+ * @param header   A string of headers to add to the email
+ * @param mailbox  The mailbox currently being processed
+ * @param origbody The original body of the message that was processed (just the first text part)
+ *
+ * @return nothing
+ */
+function mailhandler_email_response($header, $mailbox, $origbody) {
+  global $user;
+  $msg = '';
+  $errs = false;
+  
+  $messages = mailhandler_get_messages();
+  if (count($messages)) {
+    if($user->alternate_mailhandler_email && valid_email_address($user->alternate_mailhandler_email)) {
+      $recipient = $user->alternate_mailhandler_email;
+    }
+    else {
+      $recipient = mailhandler_get_fromaddress($header, $mailbox);
+    }
+    $sitemail = variable_get("site_mail", ini_get("sendmail_from"));
+    $headers = "From: $sitemail\nReply-to: $sitemail\nX-Mailer: Drupal\nReturn-path: $sitemail\nErrors-to: $sitemail";
+    
+    // send errors to anonymous posters who encountered errors or any valid user who enabled send_mailhandler_errors checkbox
+    if (isset($messages['error']) && is_array($messages['error']) && (!$user->uid || $user->send_mailhandler_errors)) {
+      // $recipient really refers to the mail header which is authoritative for authentication
+      $error_body = implode('\n', $messages['error']);
+      $msg .= variable_get("mailhandler_error_title", t('There were errors with your post'))."\n".$error_body."\n";
+      $errs = true;
+    }
+    
+    if (isset($messages['info']) && is_array($messages['info']) && $user->send_mailhandler_info) {
+      // $recipient really refers to the mail header which is authoritative for authentication
+      $info_body = implode("\n", $messages['info']);
+      $msg .= variable_get("mailhandler_info_title", t('Here is info about your post'))."\n".$info_body."\n";
+    }
+    
+    if($msg) {
+      $msg .= t("\n\nYou sent:\n\nFrom: %f\nSubject: %t\nBody:\n%b", array ("%f" => $recipient, "%t" => $header->subject, "%b" => $origbody));
+    
+      if($errs) {
+        watchdog('mailhandler', "Sending error email to sender $recipient");
+        user_mail($recipient, t(variable_get("mailhandler_error_subject", "Email submission to %site_name failed - %subj"), array ("%site_name" => variable_get("site_name", "Drupal"), "%subj" => $header->subject)), $msg, $headers);
+      }
+      else {
+        watchdog('mailhandler', "Sending info email to sender $recipient");
+        user_mail($recipient, t(variable_get("mailhandler_info_subject", "Email submission to %site_name information - %subj"), array ("%site_name" => variable_get("site_name", "Drupal"), "%subj" => $header->subject)), $msg, $headers);
+      }
+    }
+  }
+}
+
 //
 // MODULE HOOKS
 //
-function mailhandler_user($type, &$edit, &$user) {
+function mailhandler_user($type, $edit, &$user, $category = NULL) {
   // for now, just show the first mailbox address to user.
+  $data = "";
+  
+  if (user_access("mailhandler settings") && $category == 'account') {
   switch ($type) {
-    case "view_private":
-      if (user_access("maintain personal blog")) {
-        $result = db_fetch_array(db_query("SELECT * FROM {mailhandler} WHERE enabled = '1' ORDER BY mail"));
+      case "view":
+        $result = db_fetch_array(db_query("SELECT mail,security FROM {mailhandler} WHERE enabled = '1' ORDER BY mail"));
         if ($result["security"] == 1) {
-          return form_item(t("Mail Handler"), t("You may post to <i>%sn</i> by sending an e-mail to <i>%e</i>. Be sure to include your password at the top of your e-mail body (e.g. <i>pass=mypassword</i>).", array ("%sn" => variable_get("site_name", "Drupal"), "%a" => url("blog/$user->uid"), "%e" => $result["mail"])));
+          $data .= form_item(t("Mail Handler Usage"), t("You may post to <i>%sn</i> by sending an e-mail to <i>%e</i>. Be sure to include your password at the top of your e-mail body (e.g. <i>pass=mypassword</i>).", array ("%sn" => variable_get("site_name", "Drupal"), "%a" => url("blog/$user->uid"), "%e" => $result["mail"])));
         }
         else {
-          return form_item(t("Mail Handler"), t("You may post to <i>%sn</i> by sending an e-mail to <i>%e</i>.", array ("%sn" => variable_get("site_name", "Drupal"), "%a" => url("blog/$user->uid"), "%e" => $result["mail"])));
+          $data .= form_item(t("Mail Handler Usage"), t("You may post to <i>%sn</i> by sending an e-mail to <i>%e</i>.", array ("%sn" => variable_get("site_name", "Drupal"), "%a" => url("blog/$user->uid"), "%e" => $result["mail"])));
+        }
+        break;
+        
+      case "form":
+        $data .= form_textfield(t('AntiSpam code'), 'mailhandler_antispam_code', $edit['mailhandler_antispam_code'] ? $edit['mailhandler_antispam_code'] : $user->alternate_mailhandler_email, 10, 10, t('Code that will be check on messages to avoid flooding the website with junk mail.'));
+        $data .= form_checkbox(t('Send Error Replies'), 'send_mailhandler_errors', 1, $user->send_mailhandler_errors, t('Should error messages from processing posts by email be sent to the sending email address?'));
+        $data .= form_checkbox(t('Send Info Replies'), 'send_mailhandler_info', 1, $user->send_mailhandler_info, t('Should informational messages from processing posts by email be sent to the sending email address?'));
+        $data .= form_textfield(t('Alternate Email Address'), 'alternate_mailhandler_email', $edit['alternate_mailhandler_email'] ? $edit['alternate_mailhandler_email'] : $user->alternate_mailhandler_email, 50, 255, t('If specified, send all error/informational messages to this address instead of the address they came from.'));
+        break;
+        
+      case "validate":
+        if (strlen($edit['alternate_mailhandler_email']) > 0 && !valid_email_address($edit['alternate_mailhandler_email'])) {
+          form_set_error('alternate_mailhandler_email', t('The e-mail address %mail is not valid.', array('%mail' => "<em>".$edit['alternate_mailhandler_email']."</em>")));
         }
+        break;
       }
+    $data_items[] = array('title' => t('Mail Handler'), 'data' => $data, 'weight' => 2);
   }
+  return $data_items;
 }
 
 /**
@@ -610,7 +796,17 @@
 }
 
 function mailhandler_perm() {
-  return array("administer mailhandler","access mailhandler");
+	// 'post by mail to '.$mailbox['mail']
+  $perms=array();
+  $perms[] = "administer mailhandler";
+  $perms[] = "mailhandler settings";
+
+    $result = db_query("SELECT mail FROM {mailhandler} ORDER BY mail");
+  while ($mailbox = db_fetch_array($result)) {
+	  $perms[]='post by mail to '.$mailbox['mail'];
+  }
+
+  return $perms;
 }
 
 function mailhandler_menu($may_cache) {
@@ -742,13 +938,15 @@
     if ($edit["mid"]) {
       // Includes fields to allow administrators to add extra IMAP commands,
       // and select the format of saved nodes/comments
-      db_query("UPDATE {mailhandler} SET mail = '%s', mailto = '%s', domain = '%s', port = '%s', folder = '%s', name = '%s', pass = '%s', extraimap = '%s', mime = '%s', imap = '%s', security = '%s', replies = '%s', fromheader = '%s', commands = '%s', sigseparator = '%s', enabled = '%s', delete_after_read = '%d', format = '%s' WHERE mid = '%s'", $edit["mail"], $edit["mailto"], $edit["domain"], $edit["port"], $edit["folder"], $edit["name"], $edit["pass"], $edit["extraimap"], $edit["mime"], $edit["imap"], $edit["security"], $edit["replies"], $edit["fromheader"], $edit["commands"], $edit["sigseparator"], $edit["enabled"], $edit["delete_after_read"], $edit["format"], $edit["mid"]);
+      db_query("UPDATE {mailhandler} SET mail = '%s', mailto = '%s', domain = '%s', port = '%s', folder = '%s', name = '%s', pass = '%s', extraimap = '%s', mime = '%s', imap = '%s', security = '%s', replies = '%s', fromheader = '%s', commands = '%s', mandatory_commands = '%s', sigseparator = '%s', enabled = '%s', delete_after_read = '%d', format = '%s' WHERE mid = '%s'", 
+      		$edit["mail"], $edit["mailto"], $edit["domain"], $edit["port"], $edit["folder"], $edit["name"], $edit["pass"], $edit["extraimap"], $edit["mime"], $edit["imap"], $edit["security"], $edit["replies"], $edit["fromheader"], $edit["commands"], $edit["mandatory_commands"], $edit["sigseparator"], $edit["enabled"], $edit["delete_after_read"], $edit["format"], $edit["mid"]);
       drupal_set_message(t("Mailbox updated"));
     }
     else {
       // Includes fields to allow administrators to add extra IMAP commands,
       // and select the format of saved nodes/comments
-      db_query("INSERT INTO {mailhandler} (mail, mailto, domain, port, folder, name, pass, extraimap, mime, imap, security, replies, fromheader, commands, sigseparator, enabled, delete_after_read, format) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s')", $edit["mail"], $edit["mailto"], $edit["domain"], $edit["port"], $edit["folder"], $edit["name"], $edit["pass"], $edit["extraimap"], $edit["mime"], $edit["imap"], $edit["security"], $edit["replies"], $edit["fromheader"], $edit["commands"], $edit["sigseparator"], $edit["enabled"], $edit["delete_after_read"], $edit["format"]);
+      db_query("INSERT INTO {mailhandler} (mail, mailto, domain, port, folder, name, pass, extraimap, mime, imap, security, replies, fromheader, commands, mandatory_commands, sigseparator, enabled, delete_after_read, format) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s')", 
+      	$edit["mail"], $edit["mailto"], $edit["domain"], $edit["port"], $edit["folder"], $edit["name"], $edit["pass"], $edit["extraimap"], $edit["mime"], $edit["imap"], $edit["security"], $edit["replies"], $edit["fromheader"], $edit["commands"], $edit["mandatory_commands"], $edit["sigseparator"], $edit["enabled"], $edit["delete_after_read"], $edit["format"]);
       drupal_set_message(t("Mailbox added"));
     }
     $output = mailhandler_display();
@@ -786,10 +984,11 @@
   // Allow administrators to configure the mailbox with extra IMAP commands (notls, novalidate-cert etc.)
   $output .= form_textfield(t("Extra commands"), "extraimap", $edit["extraimap"], 50, 100, t("Optional. In some circumstances you need to issue extra commands to connect to your mail server (e.g. \"/notls\", \"/novalidate-cert\" etc.). See documentation for <a href=\"http://php.net/imap_open\">imap_open</a>. Begin the string with a \"/\", separating each subsequent command with another \"/\""));
   $output .= form_select(t("Mime preference"), "mime", $edit["mime"], array("TEXT/HTML,TEXT/PLAIN" => "HTML", "TEXT/PLAIN,TEXT/HTML" => t("Plain text")), t("When a user sends an e-mail containing both HTML and plain text parts, use this part as the node body."));
-  $output .= form_radios(t('Security'), 'security', $edit['security'], array(t('Disabled'), t('Require password')), t('Disable security if your site does not require a password in the Commands section of incoming e-mails. Note: Security=Enabled and Mime preference=HTML is an unsupported combination.'));
+  $output .= form_radios(t('Security'), 'security', $edit['security'], array(t('Disabled'), t('Require password'), t('Require AntiSpam code')), t('Disable security if your site does not require a password in the Commands section of incoming e-mails. Note: Security=Enabled and Mime preference=HTML is an unsupported combination.'));
   $output .= form_radios(t('Send error replies'), 'replies', $edit['replies'], array(t('Disabled'), t('Enabled')), t('Send helpful replies to all unsuccessful e-mail submissions. Consider disabling when a listserv posts to this mailbox.'));
   $output .= form_textfield(t("From header"), "fromheader", $edit["fromheader"], 50, 125, t("Use this e-mail header to determine the author of the resulting node. Admins usually leave this field blank (thus using the <b>From</b> header), but <b>Sender</b> is also useful when working with listservs."));
   $output .= form_textarea(t("Default commands"), "commands", $edit["commands"], 50, 5, t("A set of commands which are added to each message. One command per line. See %link.", array ("%link" => l(t("Commands"), "admin/mailhandler/help/#commands"))));
+  $output .= form_textarea(t("Mandatory commands"), "mandatory_commands", $edit["mandatory_commands"], 50, 5, t("A set of commands which are added to each message. One command per line. These commands override those that might be provided in the message. See %link.", array ("%link" => l(t("Commands"), "admin/mailhandler/help/#commands"))));
   $output .= form_textfield(t("Signature separator"), "sigseparator", $edit["sigseparator"], 50, 125, t("All text after this string will be discarded. A typical value is <b>\"-- \"</b> that is two dashes followed by a blank in an otherwise empty line. Leave blank to include signature text in nodes."));
   $output .= form_checkbox(t("Delete messages after they are processed?"), "delete_after_read", 1, $edit["delete_after_read"], t("Uncheck this box to leave read messages in the mailbox.  They will not be processed again unless they become marked as unread."));
   $output .= form_radios(t('Cron processing'), 'enabled', $edit['enabled'], array(t('Disabled'), t('Enabled')), t('Select disable to temporarily stop cron processing for this mailbox.'));
@@ -1026,4 +1225,23 @@
   }
 }
 
+function mailhandler_settings() {
+  $frmout = form_checkbox(t('Use Node Type in Link'), 'mailhandler_antispam', 1, variable_get('forward_link_type', FALSE), t('If checked, the link will read &quot;email this <em>nodetype</em>&quot;; if not, it will just read &quot;email this page&quot;'));
+
+  $frmout = form_textfield(t('Error Reply Subject'), "mailhandler_error_subject", variable_get("mailhandler_error_subject", t('Email submission to %site_name failed - %subj')), 50, 255, t("This is the email subject line used when system reply emails are sent reporting processing errors. <br /><strong>%site_name</strong> and <strong>%subj</strong> are replaced by your site's name and the subject of the originally posted email."));
+  $frmout .= form_textarea(t('Error Reply Title'), "mailhandler_error_title", variable_get("mailhandler_error_title", t('There were errors with your post')), 55, 5, t("This is the title of the errors section used when system reply emails are sent reporting processing errors."));
+  $out = form_group(t('Errors'), $frmout);
+  
+  $frmout = form_textfield(t('Information Reply Subject'), "mailhandler_info_subject", variable_get("mailhandler_info_subject", t('Email submission to %site_name information - %subj')), 50, 255, t("This is the email subject line used when system reply emails sent containing reporting processing information. <br /><strong>%site_name</strong> and <strong>%subj</strong> are replaced by your site's name and the subject of the originally posted email."));
+  $frmout .= form_textarea(t('Information Reply Title'), "mailhandler_info_title", variable_get("mailhandler_info_title", t('Here is info about your post')), 55, 5, t("This is the title of the information section used when system reply emails sent containing reporting processing information."));
+  $frmout .= form_textarea(t('Successfull post message'), "mailhandler_successful_post", variable_get("mailhandler_successful_post",
+  	t('The following message has been succesfully processed.<br/>'.
+	          			'You can edit that message by following this link : %link <br/><br/>'.
+	          			'Thank you for using %site services.<br/><br/>')
+	         ), 55, 5, t("This is the content of the email sent to the user upon successful post."));
+// mailhandler_successful_post
+    $out .= form_group(t('Information'), $frmout);
+  
+  return $out;
+}
 ?>
