/[drupal]/contributions/modules/mailhandler/mailhandler.module
ViewVC logotype

Contents of /contributions/modules/mailhandler/mailhandler.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.97 - (hide annotations) (download) (as text)
Fri May 2 14:54:58 2008 UTC (18 months, 3 weeks ago) by weitzman
Branch: MAIN
CVS Tags: HEAD
Changes since 1.96: +1 -1 lines
File MIME type: text/x-php
FILE REMOVED
Please use the relevant branches. HEAD is not currently in use.
1 killes 1.76 <?php
2 weitzman 1.97 // $Id: mailhandler.module,v 1.96 2008/05/02 12:58:16 weitzman Exp $
3 weitzman 1.93
4 weitzman 1.96
5 killes 1.76 /**
6 weitzman 1.96 * Implementation of hook_cron(). Process msgs from all enabled mailboxes.
7 killes 1.76 */
8 weitzman 1.96 function mailhandler_cron() {
9    
10     // Include mailhandler retrieval functions
11     module_load_include('inc', 'mailhandler', 'retrieve');
12 killes 1.76
13 weitzman 1.96 // Retrieve messages
14     $result = db_query('SELECT * FROM {mailhandler} WHERE enabled = 1 ORDER BY mail');
15     while ($mailbox = db_fetch_array($result)) {
16     mailhandler_cron_retrieve($mailbox);
17 killes 1.76 }
18    
19 weitzman 1.96 }
20 killes 1.76
21    
22     /**
23 weitzman 1.96 * Implementation of hook_perm().
24 killes 1.76 */
25 weitzman 1.96 function mailhandler_perm() {
26     return array('administer mailhandler');
27 killes 1.76 }
28    
29    
30     /**
31 weitzman 1.96 * Implementation of hook_menu().
32 killes 1.76 */
33 weitzman 1.96 function mailhandler_menu() {
34 killes 1.76
35 weitzman 1.96 $items = array();
36 killes 1.76
37 weitzman 1.96 $items['admin/content/mailhandler'] = array(
38     'title' => t('Mailhandler'),
39     'description' => t('Manage mailboxes and retrieve messages.'),
40     'page callback' => 'mailhandler_list_mailboxes',
41     'access arguments' => array('administer mailhandler'),
42     'file' => 'mailhandler.admin.inc',
43     );
44    
45     $items['admin/content/mailhandler/list'] = array(
46     'title' => t('List'),
47     'description' => t('Manage mailboxes and retrieve messages.'),
48     'type' => MENU_DEFAULT_LOCAL_TASK,
49     'access arguments' => array('administer mailhandler'),
50     'weight' => -10,
51     );
52    
53     $items['admin/content/mailhandler/add'] = array(
54     'title' => t('Add mailbox'),
55     'page callback' => 'drupal_get_form',
56     'page arguments' => array('mailhandler_add_edit_mailbox', NULL),
57     'access arguments' => array('administer mailhandler'),
58     'type' => MENU_LOCAL_TASK,
59     'file' => 'mailhandler.admin.inc',
60     );
61    
62     $items['admin/content/mailhandler/retrieve/%'] = array(
63     'title' => t('Retrieve'),
64     'page callback' => 'mailhandler_admin_retrieve',
65     'page arguments' => array(4),
66     'access arguments' => array('administer mailhandler'),
67     'type' => MENU_CALLBACK,
68     'file' => 'mailhandler.retrieve.inc',
69     );
70    
71     $items['admin/content/mailhandler/edit/%'] = array(
72     'title' => t('Edit mailbox'),
73     'page callback' => 'drupal_get_form',
74     'page arguments' => array('mailhandler_add_edit_mailbox', 4),
75     'access arguments' => array('administer mailhandler'),
76     'type' => MENU_CALLBACK,
77     'file' => 'mailhandler.admin.inc',
78     );
79    
80     $items['admin/content/mailhandler/delete/%'] = array(
81     'title' => t('Delete mailbox'),
82     'page callback' => 'drupal_get_form',
83     'page arguments' => array('mailhandler_admin_delete_confirm', 4),
84     'access arguments' => array('administer mailhandler'),
85     'type' => MENU_CALLBACK,
86     'file' => 'mailhandler.admin.inc',
87     );
88    
89     $items['admin/settings/mailhandler'] = array(
90     'title' => 'Mailhandler',
91     'description' => t('Set the default content type for incoming messages and set the cron limit.'),
92     'page callback' => 'drupal_get_form',
93     'page arguments' => array('mailhandler_admin_settings'),
94     'access arguments' => array('administer mailhandler'),
95     'file' => 'mailhandler.admin.inc',
96     );
97 killes 1.76
98 weitzman 1.96 return $items;
99 killes 1.76 }
100    
101    
102     /**
103 weitzman 1.96 * Implementation of hook_help().
104 killes 1.76 */
105 weitzman 1.96 function mailhandler_help($path = 'admin/help#mailhandler', $arg) {
106     $output = '';
107     $link->add = l(t('Add mailbox'), 'admin/content/mailhandler/add');
108 killes 1.76
109 weitzman 1.96 switch ($path) {
110     case 'admin/help#mailhandler':
111     $output = '<p>'. t('The mailhandler module allows registered users to create or edit nodes and comments via e-mail. Users may post taxonomy terms, teasers, and other post attributes using the mail commands capability. This module is useful because e-mail is the preferred method of communication by community members.') .'</p>';
112     $output .= '<p>'. t('The mailhandler module requires the use of a custom mailbox. Administrators can add mailboxes that should be customized to meet the needs of a mailing list. This mailbox will then be checked on every cron job. Administrators may also initiate a manual retrieval of messages.') .'</p>';
113     $output .= '<p>'. t('This is particularly useful when you want multiple sets of default commands. For example , if you want to authenticate based on a non-standard mail header like Sender: which is useful for accepting submissions from a listserv. Authentication is usually based on the From: e-mail address. Administrators can edit the individual mailboxes when they administer mailhandler.') .'</p>';
114     $output .= t('<p>You can</p>
115     <ul>
116     <li><a href="@run-cron">run cron</a> to retrieve messages from all cron enabled mailboxes.</li>
117     <li>list mailboxes at <a href="@admin-mailhandler">Administer &gt;&gt; Content management &gt;&gt; Mailhandler</a>.</li>
118     <li>add a mailbox at <a href="@admin-mailhandler-add">Administer &gt;&gt; Content management &gt;&gt; Mailhandler &gt;&gt; Add mailbox.</a></li>
119     <li>set default commands, (password, type, taxonomy, promote, status), for how to work with incoming mail at <a href="%admin-mailhandler">Administer &gt;&gt; Content management &gt;&gt; Mailhandler</a> and select <strong>edit</strong> for the email address being handled. Set commands in the default command field.</li>
120     <li>post email, such as from a mailing list, to a forum by adding the term id (number found in the URL) to the default commands using <strong>tid: #</strong>.</li>
121     <li>alter mailhandler settings (default content type and cron threshold) at <a href="@admin-mailhandler-settings">Administer &gt;&gt; Site configuration &gt;&gt; Mailhandler</a>.</li>
122     </ul>',
123     array(
124     '@run-cron' => url('admin/logs/status/run-cron'),
125     '@admin-mailhandler-add' => url('admin/content/mailhandler/add'),
126     '@admin-mailhandler' => url('admin/content/mailhandler'),
127     '@admin-mailhandler-settings' => url('admin/settings/mailhandler'),
128     ));
129     $output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="%mailhandler">Mailhandler page</a>.', array('%mailhandler' => 'http://www.drupal.org/handbook/modules/mailhandler/')) .'</p>';
130     return $output;
131     case 'admin/content/mailhandler':
132     return t('The mailhandler module allows registered users to create or edit nodes and comments via email. Authentication is usually based on the From: email address. There is also an email filter that can be used to prettify incoming email. Users may post taxonomy terms, teasers, and other node parameters using the Command capability.');
133     case 'admin/content/mailhandler/add':
134     return t('Add a mailbox whose mail you wish to import into Drupal. Can be IMAP, POP3, or local folder.');
135     case 'admin/content/mailhandler/edit/%':
136     return t('Edit the mailbox whose mail you wish to import into Drupal. Can be IMAP, POP3, or local folder.');
137     case 'admin/settings/mailhandler':
138     return t('The mailhandler module allows registered users to create or edit nodes and comments via e-mail.');
139 killes 1.76 }
140     }
141    
142    
143     /**
144 weitzman 1.96 * Implementation of hook_init to add mailhandler.css
145 killes 1.76 */
146 weitzman 1.96 function mailhandler_init() {
147     drupal_add_css(drupal_get_path('module', 'mailhandler') .'/mailhandler.css');
148     return;
149 killes 1.76 }
150    
151    
152 weitzman 1.96 // The following functions are called by both mailhandler.admin.inc and mailhandler.retrieve.inc so they
153     // are defined here to make them available to both
154 weitzman 1.92
155     /**
156 weitzman 1.96 * Establish a connection to the mailbox specified by the array $mailbox
157 weitzman 1.92 */
158 weitzman 1.96 function mailhandler_open_mailbox($mailbox) {
159 weitzman 1.92
160 weitzman 1.96 if ($mailbox['domain']) {
161     if ($mailbox['imap'] == 1) {
162     $box = '{'. $mailbox['domain'] .':'. $mailbox['port'] . $mailbox['extraimap'] .'}'. $mailbox['folder'];
163 weitzman 1.92 }
164 weitzman 1.96 else {
165     $box = '{'. $mailbox['domain'] .':'. $mailbox['port'] .'/pop3'. $mailbox['extraimap'] .'}'. $mailbox['folder'];
166 weitzman 1.92 }
167 weitzman 1.96 $result = imap_open($box, $mailbox['name'], $mailbox['pass']);
168     $err = 'domain';
169 weitzman 1.92 }
170 weitzman 1.94 else {
171 weitzman 1.96 $box = $mailbox['folder'];
172     $result = imap_open($box, '', '');
173 weitzman 1.94 }
174 weitzman 1.92
175 weitzman 1.96 return $result;
176 weitzman 1.92
177 weitzman 1.80 }
178    
179 killes 1.76
180     /**
181 weitzman 1.96 * Fetch data for a specific mailbox from the database.
182 killes 1.76 */
183 weitzman 1.96 function mailhandler_get_mailbox($mid) {
184     return db_fetch_array(db_query("SELECT * FROM {mailhandler} WHERE mid = %d", $mid));
185 weitzman 1.80 }
186 killes 1.76
187    
188 weitzman 1.80 /**
189 weitzman 1.96 * Return a default content type if the user has not chosen a specific type on the settings page
190     * In order of priority, return blog, story, page
191     * This assumes that one of these basic types is in use on a site (page and story are active by default)
192     * A user can choose other content types via the settings page as this exposes all available types
193 weitzman 1.80 */
194 weitzman 1.96 function mailhandler_default_type() {
195 killes 1.76
196 weitzman 1.96 // Get the current default setting, if defined
197     $default_type = variable_get('mailhandler_default_type', NULL);
198 killes 1.76
199 weitzman 1.96 // Find out what types are available
200     $available_types = node_get_types('names');
201 weitzman 1.80
202 weitzman 1.96 // Check the default type is still available (it could have been deleted)
203     if ($default_type && array_key_exists($default_type, $available_types)) {
204     return $default_type;
205 killes 1.76 }
206 weitzman 1.80
207 weitzman 1.96 // If we get here then either no default is set, or the default type is no longer available
208 killes 1.76
209 weitzman 1.96 // Search for the array key (the machine readable name) for blog, story and page basic types
210     if (array_key_exists('blog', $available_types)) {
211     $default_type = 'blog';
212 killes 1.76 }
213 weitzman 1.96 else if (array_key_exists('story', $available_types)) {
214     $default_type = 'story';
215 killes 1.76 }
216 weitzman 1.96 else if (array_key_exists('page', $available_types)) {
217     $default_type = 'page';
218 killes 1.76 }
219     else {
220 weitzman 1.96 // If basic types not found then return the first item from the array as an alternative default
221     $default_type = key($available_types);
222 weitzman 1.80 }
223 chriskennedy 1.87
224 weitzman 1.96 return $default_type;
225 killes 1.76
226 chriskennedy 1.87 }

  ViewVC Help
Powered by ViewVC 1.1.2