Index: mailhandler.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/Attic/mailhandler.admin.inc,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 mailhandler.admin.inc
--- mailhandler.admin.inc	26 Jan 2011 23:48:13 -0000	1.1.2.16
+++ mailhandler.admin.inc	27 Jan 2011 14:49:21 -0000
@@ -281,43 +281,49 @@
 
 
 /**
- * Confirm/Delete Mailbox
+ * Display a confirmation form before deleting a Mailbox.
  */
-function mailhandler_admin_delete_confirm($form_state, $mid) {
+function mailhandler_admin_delete_confirm($form_state, $mailbox = NULL) {
+  $form = array();
 
-  $info = db_fetch_object(db_query("SELECT mid, mail FROM {mailhandler} WHERE mid = %d", $mid));
-
-  // $mid parameter is expected to be a valid mailbox or NULL. If mid is defined
-  // but no mailbox is found for this id, then return a 404, as the only way to
-  // reach this situation is by a wrong link.
-  if ($mid && !isset($info->mid)) {
+  // $mailbox parameter is expected to be a valid mailbox or NULL.
+  if (!$mailbox) {
     drupal_not_found();
     return;
   }
 
-  $form['mid'] = array(
-    '#type' => 'hidden',
-    '#value' => $mid,
+  // Save the mailbox for the confirm_form.
+  $form['mailbox'] = array(
+    '#type' => 'value',
+    '#value' => $mailbox,
   );
 
+  // Build a confirmation form to delete this entry.
   return confirm_form(
-      $form,
-      t('Do you wish to delete mailbox %mailbox?', array('%mailbox' => $info->mail)),
-      'admin/content/mailhandler',
-      t('This action cannot be undone.'),
-      t('Delete'),
-      t('Cancel')
-    );
+    $form,
+    t('Do you wish to delete mailbox %mailbox?', array('%mailbox' => $mailbox['mail'])),
+    'admin/content/mailhandler',
+    t('This action cannot be undone.'),
+    t('Delete'),
+    t('Cancel')
+  );
 }
 
 
+/**
+ * Submit hook for mailhandler_admin_delete_confirm form.
+ *
+ * This function assumes that $form_state['values']['mailbox'] is present and it
+ * is a valid mailbox (verified at mailhandler_admin_delete_confirm_form).
+ */
 function mailhandler_admin_delete_confirm_submit($form, &$form_state) {
-  $info = db_fetch_object(db_query("SELECT mid, mail FROM {mailhandler} WHERE mid = %d", $form_state['values']['mid']));
-  db_query("DELETE FROM {mailhandler} WHERE mid = %d", $form_state['values']['mid']);
-  watchdog('mailhandler', 'Mailhandler: Mailbox %mailbox deleted', array('%mailbox' => $info->mail), WATCHDOG_INFO);
-  drupal_set_message(t('Mailbox %mailbox deleted', array('%mailbox' => $info->mail)));
+  $mailbox = $form_state['values']['mailbox'];
+
+  watchdog('mailhandler', 'Mailhandler: Mailbox %mailbox deleted', array('%mailbox' => $mailbox['mail']), WATCHDOG_INFO);
+  drupal_set_message(t('Mailbox %mailbox deleted', array('%mailbox' => $mailbox['mail'])));
   $form_state['redirect'] = 'admin/content/mailhandler';
-  return;
+  
+  mailhandler_mailbox_delete($mailbox['mid']);
 }
 
 
Index: mailhandler.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/Attic/mailhandler.module,v
retrieving revision 1.96.2.33
diff -u -r1.96.2.33 mailhandler.module
--- mailhandler.module	27 Jan 2011 13:17:40 -0000	1.96.2.33
+++ mailhandler.module	27 Jan 2011 14:46:51 -0000
@@ -100,7 +100,7 @@
     'file' => 'mailhandler.admin.inc',
   );
 
-  $items['admin/content/mailhandler/delete/%'] = array(
+  $items['admin/content/mailhandler/delete/%mailhandler_mailbox'] = array(
     'title' => 'Delete mailbox',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('mailhandler_admin_delete_confirm', 4),
@@ -285,6 +285,19 @@
 }
 
 /**
+ * Delete a Mailhandler Mailbox from the database.
+ *
+ * When $mailbox has 'mid' attribute defined, the database entry with this ID
+ * will be updated, otherwise a new mailbox will be created.
+ *
+ * @param $mid
+ *   mailbox ID to be deleted.
+ */
+function mailhandler_mailbox_delete($mid) {
+  db_query("DELETE FROM {mailhandler} WHERE mid = %d", $mid);
+}
+
+/**
  * Return mailhandler mailbox default attributes.
  *
  * @return

