class MailhandlerParser in Mailhandler 6.2
Same name and namespace in other branches
- 7.2 plugins/feeds/plugins/MailhandlerParser.class.php \MailhandlerParser
Parses an IMAP stream.
Hierarchy
- class \FeedsConfigurable
- class \FeedsPlugin implements FeedsSourceInterface
- class \FeedsParser
- class \MailhandlerParser
- class \FeedsParser
- class \FeedsPlugin implements FeedsSourceInterface
Expanded class hierarchy of MailhandlerParser
6 string references to 'MailhandlerParser'
- MailhandlerParser.inc in plugins/
feeds/ plugins/ MailhandlerParser.inc - mailhandler_default_feeds_importer_default in modules/
mailhandler_default/ mailhandler_default.feeds_importer_default.inc - Implementation of hook_feeds_importer_default().
- mailhandler_help in ./
mailhandler.module - Implementation of hook_help().
- mailhandler_update_6202 in ./
mailhandler.install - Adds new command plugins to existing Feeds importers.
- mailhandler_update_6207 in ./
mailhandler.install - Changes 'Body' importer mapping source to 'Body (HTML)'.
File
- plugins/
feeds/ plugins/ MailhandlerParser.class.php, line 10 - MailhandlerParser class.
View source
class MailhandlerParser extends FeedsParser {
/**
* Override parent::configDefaults().
*/
public function configDefaults() {
return array(
'available_commands' => 'status',
'authenticate_plugin' => 'MailhandlerAuthenticateDefault',
'auth_required' => TRUE,
'default_commands' => 'status: 1',
'commands_failed_auth' => 'status: 0',
);
}
/**
* Define defaults.
*/
public function sourceDefaults() {
return array(
'auth_required' => $this->config['auth_required'],
'default_commands' => $this->config['default_commands'],
'commands_failed_auth' => $this->config['commands_failed_auth'],
);
}
public function sourceForm($source_config) {
$form['auth_required'] = array(
'#type' => 'checkbox',
'#title' => t('Skip messages that fail authentication'),
'#default_value' => isset($source_config['auth_required']) ? $source_config['auth_required'] : '',
'#description' => t('If checked, only messages that belong to an authenticated user will be imported.'),
);
$plugins = mailhandler_get_plugins('mailhandler', 'commands');
foreach ($plugins as $plugin_name => $plugin) {
if ($class = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands', 'handler')) {
$class
->sourceForm($form, $source_config);
}
}
return $form;
}
/**
* Build configuration form.
*/
public function configForm(&$form_state) {
$form = array();
ctools_include('plugins');
$form['authenticate_plugin'] = array(
'#type' => 'select',
'#title' => t('Authentication plugin'),
'#description' => t('Choose an authentication plugin'),
'#options' => _mailhandler_build_options(mailhandler_get_plugins('mailhandler', 'authenticate')),
'#default_value' => $this->config['authenticate_plugin'],
'#required' => FALSE,
);
$plugins = mailhandler_get_plugins('mailhandler', 'commands');
foreach ($plugins as $plugin_name => $plugin) {
if ($class = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands', 'handler')) {
$class
->configForm($form, $form_state, $this->config);
}
}
return $form;
}
/**
* Implementation of FeedsParser::parse().
*/
public function parse(FeedsImportBatch $batch, FeedsSource $source) {
$fetched = $batch
->getRaw();
$mailbox = $fetched['mailbox'];
$messages = $fetched['messages'];
if (!empty($messages)) {
foreach ($messages as $mid => &$message) {
$this
->authenticate($message, $mailbox);
if ($class = mailhandler_plugin_load_class('mailhandler', $mailbox->settings['retrieve'], 'retrieve', 'handler')) {
$class
->purge_message($mailbox, $message);
}
if ($message['authenticated_uid'] == 0) {
// User was not authenticated
module_invoke_all('mailhandler_auth', 'auth_failed', $message);
$source_config = $source
->getConfigFor($this);
if ($source_config['auth_required']) {
mailhandler_report('warning', 'User could not be authenticated. Please check your Mailhandler authentication plugin settings.');
unset($messages[$mid]);
continue;
}
}
$this
->commands($message, $source);
}
$batch
->setItems($messages);
}
else {
if (isset($fetched['new'])) {
mailhandler_report('info', 'No new messages.');
}
}
}
/*
* This defines sources which user's can select to map values to.
*/
public function getMappingSources() {
$sources = parent::getMappingSources();
$sources['authenticated_uid'] = array(
'name' => t('User ID'),
'description' => t('The authenticated Drupal user ID'),
);
$plugins = mailhandler_get_plugins('mailhandler', 'commands');
foreach ($plugins as $plugin_name => $plugin) {
$plugin = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands', 'handler');
$sources = array_merge($sources, $plugin
->getMappingSources($this->config));
}
return $sources;
}
/*
* Parse and apply commands.
*/
public function commands(&$message, $source) {
$plugins = mailhandler_get_plugins('mailhandler', 'commands');
foreach ($plugins as $plugin_name => $plugin) {
if ($class = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands', 'handler')) {
$class
->parse($message, $source, $this);
$class
->process($message, $source);
}
}
}
/*
* Authenticate the message and set $message['authenticated_uid'].
*/
public function authenticate(&$message, $mailbox) {
if ($plugin = $this->config['authenticate_plugin']) {
if ($class = mailhandler_plugin_load_class('mailhandler', $plugin, 'authenticate', 'handler')) {
$message['authenticated_uid'] = $class
->authenticate($message, $mailbox);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | CTools export enabled status of this object. | |
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
public | function | Similar to setConfig but adds to existing configuration. | 1 |
FeedsConfigurable:: |
public | function | Submission handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Validation handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Copy a configuration. | 1 |
FeedsConfigurable:: |
public | function | Determine whether this object is persistent and enabled. I. e. it is defined either in code or in the database and it is enabled. | 1 |
FeedsConfigurable:: |
public | function | Implementation of getConfig(). | 1 |
FeedsConfigurable:: |
public static | function | Instantiate a FeedsConfigurable object. | 1 |
FeedsConfigurable:: |
public | function | Set configuration. | 1 |
FeedsConfigurable:: |
public | function | Override magic method __get(). Make sure that $this->config goes through getConfig() | |
FeedsConfigurable:: |
public | function | Override magic method __isset(). This is needed due to overriding __get(). | |
FeedsParser:: |
public | function | Clear all caches for results for given source. | |
FeedsParser:: |
public | function | Get an element identified by $element_key of the given item. The element key corresponds to the values in the array returned by FeedsParser::getMappingSources(). | 1 |
FeedsPlugin:: |
public | function |
Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface:: |
|
FeedsPlugin:: |
protected static | function | Loads on-behalf implementations from mappers/ directory. | |
FeedsPlugin:: |
public | function |
Save changes to the configuration of this object.
Delegate saving to parent (= Feed) which will collect
information from this object by way of getConfig() and store it. Overrides FeedsConfigurable:: |
|
FeedsPlugin:: |
public | function |
A source is being deleted. Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
public | function |
Validation handler for sourceForm. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
A source is being saved. Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
protected | function |
Constructor. Overrides FeedsConfigurable:: |
|
MailhandlerParser:: |
public | function | ||
MailhandlerParser:: |
public | function | ||
MailhandlerParser:: |
public | function |
Override parent::configDefaults(). Overrides FeedsConfigurable:: |
|
MailhandlerParser:: |
public | function |
Build configuration form. Overrides FeedsConfigurable:: |
|
MailhandlerParser:: |
public | function |
Declare the possible mapping sources that this parser produces. Overrides FeedsParser:: |
|
MailhandlerParser:: |
public | function |
Implementation of FeedsParser::parse(). Overrides FeedsParser:: |
|
MailhandlerParser:: |
public | function |
Define defaults. Overrides FeedsPlugin:: |
|
MailhandlerParser:: |
public | function |
Callback methods, exposes source form. Overrides FeedsPlugin:: |