--- /old/mailsave_to_imagefield.module +++ mailsave_to_imagefield.module @@ -16,6 +16,55 @@ return $output; } } +/** + * Implementation of hook_menu + */ +function mailsave_to_imagefield_menu($may_cache) { + $items = array(); + + if ($may_cache) { + + $items[] = array( + 'path' => 'admin/settings/mailsave-to-imagefield', + 'title' => ('Mailsave to Imagefield'), + 'callback' => 'drupal_get_form', + 'callback arguments' => array('mailsave_to_imagefield_admin_settings'), + 'access' => user_access('administer mailsave'), + 'type' => MENU_NORMAL_ITEM, + 'description' => t('Choose which mailbox to apply imagefield mapping to..'), + ); + } + + return $items; +} + +/** + * Admin settings form + */ +function mailsave_to_imagefield_admin_settings() { + $form['mailsave_to_imagefield_mailbox'] = array( + '#title' => t('Mailhandler Inbox'), + '#type' => 'select', + '#options' => mailsave_to_imagefield_mailbox_list(), + '#required' => TRUE, + '#default_value' => variable_get('mailsave_to_imagefield_mailbox', ''), + '#description' => t('The mailhandler box which mailsave to imagefield will use.'), + ); + + return system_settings_form($form); +} + +/** + * Get list of available mailboxes + */ +function mailsave_to_imagefield_mailbox_list() { + $list = array(); + $result = db_query('SELECT mid, mail FROM {mailhandler} ORDER BY mail'); + while ($mailbox = db_fetch_object($result)) { + $list[$mailbox->mid] = $mailbox->mail; + } + return $list; +} /** * Implementation of hook_perm @@ -31,10 +80,14 @@ * Try to convert images to imagefields */ function mailsave_to_imagefield_mailsave($node, $result, $i, $header, $mailbox) { - - // See if conversion to image is needed - _mailsave_to_imagefield_attempt_image($node); - + $mailbox_mid=variable_get('mailsave_to_imagefield_mailbox', ''); + $mailbox=mailhandler_get_mailbox($mailbox_mid); + $mailbox_name=$mailbox['mail']; + //check if this is the mailbox for imagefields mailsave to be performed... + if ($header->toaddress == $mailbox_name) { + // See if conversion to image is needed + _mailsave_to_imagefield_attempt_image($node); + } // Return the (possibly updated!) updated node return $node; }