Loading mailhandler.install +23 −0 Changes for mailhandler.install: 23 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -173,6 +173,29 @@ function mailhandler_update_6201() { return $ret; } /** * Add MailhandlerCommandsFiles and MailhandlerCommandsHeaders to existing * Feeds importers. * http://drupal.org/node/1147414 */ function mailhandler_update_6202() { $ret = array(); $result = db_query('SELECT * FROM {feeds_importer}'); while ($row = db_fetch_array($result)) { $row['config'] = unserialize($row['config']); if ($row['config']['parser']['plugin_key'] == 'MailhandlerParser') { $old_plugins = $row['config']['parser']['config']['command_plugin']; $new_plugins = array( 'MailhandlerCommandsFiles' => 'MailhandlerCommandsFiles', 'MailhandlerCommandsHeaders' => 'MailhandlerCommandsHeaders', ); $row['config']['parser']['config']['command_plugin'] = array_merge($old_plugins, $new_plugins); drupal_write_record('feeds_importer', $row, 'id'); } } return $ret; } /** * Check that the IMAP extension exists for PHP. */ Loading mailhandler_default/mailhandler_default.feeds_importer_default.inc +1 −0 Changes for mailhandler_default/mailhandler_default.feeds_importer_default.inc: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ function mailhandler_default_feeds_importer_default() { 'default_commands' => 'status: 1', 'command_plugin' => array( 'MailhandlerCommandsDefault' => 'MailhandlerCommandsDefault', 'MailhandlerCommandsHeaders' => 'MailhandlerCommandsHeaders', ), 'authenticate_plugin' => 'MailhandlerAuthenticateDefault', ), Loading mailhandler_default/mailhandler_default.info +0 −1 Changes for mailhandler_default/mailhandler_default.info: 0 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -7,4 +7,3 @@ features[feeds_importer][] = "mailhandler_nodes" name = "Mailhandler default" package = "Mailhandler" project = "Mailhandler" version = "6.x-2.0-dev" plugins/MailhandlerParser.inc +10 −74 Changes for plugins/MailhandlerParser.inc: 10 added lines, 74 removed lines. Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ class MailhandlerParser extends FeedsParser { 'if_auth_fails' => 'remove', 'default_commands' => 'status: 1', 'available_commands' => 'status', 'command_plugin' => 'MailhandlerCommandsDefault', 'command_plugin' => array('MailhandlerCommandsDefault', 'MailhandlerCommandsFiles', 'MailhandlerCommandsHeaders'), 'authenticate_plugin' => 'MailhandlerAuthenticateDefault', ); } Loading Loading @@ -55,7 +55,7 @@ class MailhandlerParser extends FeedsParser { '#multiple' => TRUE, '#default_value' => $this->config['command_plugin'], ); $options = array(); //$options[0] = t('None'); $options = array(); $plugins = mailhandler_get_plugins('mailhandler', 'authenticate_plugin'); foreach ($plugins as $key => $info) { $options[$key] = $info['name']; Loading Loading @@ -92,8 +92,6 @@ class MailhandlerParser extends FeedsParser { $messages = $fetched['messages']; if (!empty($messages)) { foreach ($messages as $mid => &$message) { $this->parseAttachments($message); $this->parseExtensions($message); $this->authenticate($message, $mailbox); if ($message['authenticated_uid'] == 0) { // User was not authenticated Loading @@ -120,85 +118,23 @@ class MailhandlerParser extends FeedsParser { } } /** * Parse attachments from message mimeparts. */ public function parseAttachments(&$message) { $message['attachments'] = array(); foreach ($message['mimeparts'] as $attachment) { // 'unnamed_attachment' files are not really attachments, but mimeparts like HTML or Plain Text. // We only want to save real attachments, like images and files. if ($attachment->filename !== 'unnamed_attachment') { $file = file_save_data($attachment->data, file_directory_temp() . '/' . $attachment->filename); $message['attachments'][] = new FeedsEnclosure($file, $attachment->filemime); } } // This otherwise breaks batch import. Attachments are handled above. // @TODO: Ensure it's ok to really trash this like so. unset($message['mimeparts']); } /* * Set known sources and parse additional sources from body. */ public function parseExtensions(&$message) { // Populate $message with all values from 'header' object. $parts = (array) $message['header']; foreach ($parts as $key => $value) { // Some keys are already taken, so do not overwrite them. if (!in_array($key, array('header', 'origbody', 'mimeparts', 'mailbox', 'attachments'))) { $message[$key] = $value; } } } /* * This defines sources which user's can select to map values to. */ public function getMappingSources() { $sources = parent::getMappingSources(); // Make all IMAP header keys available as selectable mapping sources. $parts = array( 'date', 'subject', 'message_id', 'toaddress', 'to', 'fromaddress', 'from', 'reply_toaddress', 'reply_to', 'senderaddress', 'sender', 'Recent', 'Unseen', 'Flagged', 'Answered', 'Deleted', 'Draft', 'Msgno', 'MailDate', 'Size', 'udate', 'origbody', 'mimeparts', 'attachments', ); foreach ($parts as $part) { $sources[$part] = array( 'title' => t($part), 'description' => t('IMAP header property.'), ); } $sources['authenticated_uid'] = array( 'name' => t('Authenticated UID'), 'description' => t('Authenticated UID'), ); $sources['taxonomy'] = array( 'name' => t('Taxonomy'), 'description' => t('Taxonomy terms (from commands)'), ); $plugins = $this->config['command_plugin']; foreach ($plugins as $plugin_name) { $plugin = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands_plugin', 'handler'); $sources = array_merge($sources, $plugin->getMappingSources()); } // @TODO Move the following code into MailhandlerCommandsDefault... need to // figure out how to store the config there first though. $available_commands = explode("\n", $this->config['available_commands']); foreach ($available_commands as $command) { $command = trim($command); Loading plugins/commands_plugin/MailhandlerCommands.class.php +4 −0 Changes for plugins/commands_plugin/MailhandlerCommands.class.php: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -50,4 +50,8 @@ abstract class MailhandlerCommands { */ abstract public function process(&$message, $source); public function getMappingSources() { return array(); } } Loading
mailhandler.install +23 −0 Changes for mailhandler.install: 23 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -173,6 +173,29 @@ function mailhandler_update_6201() { return $ret; } /** * Add MailhandlerCommandsFiles and MailhandlerCommandsHeaders to existing * Feeds importers. * http://drupal.org/node/1147414 */ function mailhandler_update_6202() { $ret = array(); $result = db_query('SELECT * FROM {feeds_importer}'); while ($row = db_fetch_array($result)) { $row['config'] = unserialize($row['config']); if ($row['config']['parser']['plugin_key'] == 'MailhandlerParser') { $old_plugins = $row['config']['parser']['config']['command_plugin']; $new_plugins = array( 'MailhandlerCommandsFiles' => 'MailhandlerCommandsFiles', 'MailhandlerCommandsHeaders' => 'MailhandlerCommandsHeaders', ); $row['config']['parser']['config']['command_plugin'] = array_merge($old_plugins, $new_plugins); drupal_write_record('feeds_importer', $row, 'id'); } } return $ret; } /** * Check that the IMAP extension exists for PHP. */ Loading
mailhandler_default/mailhandler_default.feeds_importer_default.inc +1 −0 Changes for mailhandler_default/mailhandler_default.feeds_importer_default.inc: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ function mailhandler_default_feeds_importer_default() { 'default_commands' => 'status: 1', 'command_plugin' => array( 'MailhandlerCommandsDefault' => 'MailhandlerCommandsDefault', 'MailhandlerCommandsHeaders' => 'MailhandlerCommandsHeaders', ), 'authenticate_plugin' => 'MailhandlerAuthenticateDefault', ), Loading
mailhandler_default/mailhandler_default.info +0 −1 Changes for mailhandler_default/mailhandler_default.info: 0 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -7,4 +7,3 @@ features[feeds_importer][] = "mailhandler_nodes" name = "Mailhandler default" package = "Mailhandler" project = "Mailhandler" version = "6.x-2.0-dev"
plugins/MailhandlerParser.inc +10 −74 Changes for plugins/MailhandlerParser.inc: 10 added lines, 74 removed lines. Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ class MailhandlerParser extends FeedsParser { 'if_auth_fails' => 'remove', 'default_commands' => 'status: 1', 'available_commands' => 'status', 'command_plugin' => 'MailhandlerCommandsDefault', 'command_plugin' => array('MailhandlerCommandsDefault', 'MailhandlerCommandsFiles', 'MailhandlerCommandsHeaders'), 'authenticate_plugin' => 'MailhandlerAuthenticateDefault', ); } Loading Loading @@ -55,7 +55,7 @@ class MailhandlerParser extends FeedsParser { '#multiple' => TRUE, '#default_value' => $this->config['command_plugin'], ); $options = array(); //$options[0] = t('None'); $options = array(); $plugins = mailhandler_get_plugins('mailhandler', 'authenticate_plugin'); foreach ($plugins as $key => $info) { $options[$key] = $info['name']; Loading Loading @@ -92,8 +92,6 @@ class MailhandlerParser extends FeedsParser { $messages = $fetched['messages']; if (!empty($messages)) { foreach ($messages as $mid => &$message) { $this->parseAttachments($message); $this->parseExtensions($message); $this->authenticate($message, $mailbox); if ($message['authenticated_uid'] == 0) { // User was not authenticated Loading @@ -120,85 +118,23 @@ class MailhandlerParser extends FeedsParser { } } /** * Parse attachments from message mimeparts. */ public function parseAttachments(&$message) { $message['attachments'] = array(); foreach ($message['mimeparts'] as $attachment) { // 'unnamed_attachment' files are not really attachments, but mimeparts like HTML or Plain Text. // We only want to save real attachments, like images and files. if ($attachment->filename !== 'unnamed_attachment') { $file = file_save_data($attachment->data, file_directory_temp() . '/' . $attachment->filename); $message['attachments'][] = new FeedsEnclosure($file, $attachment->filemime); } } // This otherwise breaks batch import. Attachments are handled above. // @TODO: Ensure it's ok to really trash this like so. unset($message['mimeparts']); } /* * Set known sources and parse additional sources from body. */ public function parseExtensions(&$message) { // Populate $message with all values from 'header' object. $parts = (array) $message['header']; foreach ($parts as $key => $value) { // Some keys are already taken, so do not overwrite them. if (!in_array($key, array('header', 'origbody', 'mimeparts', 'mailbox', 'attachments'))) { $message[$key] = $value; } } } /* * This defines sources which user's can select to map values to. */ public function getMappingSources() { $sources = parent::getMappingSources(); // Make all IMAP header keys available as selectable mapping sources. $parts = array( 'date', 'subject', 'message_id', 'toaddress', 'to', 'fromaddress', 'from', 'reply_toaddress', 'reply_to', 'senderaddress', 'sender', 'Recent', 'Unseen', 'Flagged', 'Answered', 'Deleted', 'Draft', 'Msgno', 'MailDate', 'Size', 'udate', 'origbody', 'mimeparts', 'attachments', ); foreach ($parts as $part) { $sources[$part] = array( 'title' => t($part), 'description' => t('IMAP header property.'), ); } $sources['authenticated_uid'] = array( 'name' => t('Authenticated UID'), 'description' => t('Authenticated UID'), ); $sources['taxonomy'] = array( 'name' => t('Taxonomy'), 'description' => t('Taxonomy terms (from commands)'), ); $plugins = $this->config['command_plugin']; foreach ($plugins as $plugin_name) { $plugin = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands_plugin', 'handler'); $sources = array_merge($sources, $plugin->getMappingSources()); } // @TODO Move the following code into MailhandlerCommandsDefault... need to // figure out how to store the config there first though. $available_commands = explode("\n", $this->config['available_commands']); foreach ($available_commands as $command) { $command = trim($command); Loading
plugins/commands_plugin/MailhandlerCommands.class.php +4 −0 Changes for plugins/commands_plugin/MailhandlerCommands.class.php: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -50,4 +50,8 @@ abstract class MailhandlerCommands { */ abstract public function process(&$message, $source); public function getMappingSources() { return array(); } }