Parent Directory
|
Revision Log
|
Revision Graph
#252832 Add the folder name to the mailboxes overview screen (by jeffmurphy with corrections)
| 1 | killes | 1.76 | <?php |
| 2 | zstolar | 1.87.2.16 | // $Id: mailhandler.module,v 1.87.2.15 2008/08/09 11:56:00 weitzman Exp $ |
| 3 | weitzman | 1.87.2.4 | |
| 4 | killes | 1.76 | /** |
| 5 | * Retrieve all msgs from a given mailbox and process them. | ||
| 6 | */ | ||
| 7 | function mailhandler_retrieve($mailbox) { | ||
| 8 | |||
| 9 | chriskennedy | 1.87 | if ($mailbox['domain']) { |
| 10 | if ($mailbox['imap'] == 1) { | ||
| 11 | $box = '{'. $mailbox['domain'] .':'. $mailbox['port'] . $mailbox['extraimap'] .'}'. $mailbox['folder']; | ||
| 12 | killes | 1.76 | } |
| 13 | else { | ||
| 14 | chriskennedy | 1.87 | $box = '{'. $mailbox['domain'] .':'. $mailbox['port'] .'/pop3'. $mailbox['extraimap'] .'}'. $mailbox['folder']; |
| 15 | killes | 1.76 | } |
| 16 | weitzman | 1.80 | $result = imap_open($box, $mailbox['name'], $mailbox['pass']); |
| 17 | $err = 'domain'; | ||
| 18 | killes | 1.76 | } |
| 19 | else { | ||
| 20 | weitzman | 1.80 | $box = $mailbox['folder']; |
| 21 | $result = imap_open($box, '', ''); | ||
| 22 | killes | 1.76 | } |
| 23 | |||
| 24 | if ($result) { | ||
| 25 | $n = imap_num_msg($result); | ||
| 26 | $num_processed = 0; | ||
| 27 | for ($i = 1; $i <= $n; $i++) { | ||
| 28 | $header = imap_header($result, $i); | ||
| 29 | |||
| 30 | // only process new messages | ||
| 31 | chriskennedy | 1.87 | if (!$mailbox['delete_after_read'] && $header->Unseen != 'U' && $header->Recent != 'N') { |
| 32 | killes | 1.76 | continue; |
| 33 | } | ||
| 34 | |||
| 35 | weitzman | 1.87.2.14 | $mime = explode(',', $mailbox['mime']); |
| 36 | weitzman | 1.87.2.6 | |
| 37 | // Get the first text part - this will be the node body | ||
| 38 | weitzman | 1.80 | $origbody = mailhandler_get_part($result, $i, $mime[0]); |
| 39 | weitzman | 1.87.2.6 | |
| 40 | // If we didn't get a body from our first attempt, try the alternate format (HTML or PLAIN) | ||
| 41 | weitzman | 1.80 | if (!$origbody) { |
| 42 | $origbody = mailhandler_get_part($result, $i, $mime[1]); | ||
| 43 | weitzman | 1.87.2.6 | } |
| 44 | |||
| 45 | // Parse MIME parts, so all mailhandler modules have access to | ||
| 46 | // the full array of mime parts without having to process the email. | ||
| 47 | $mimeparts = mailhandler_get_parts($result, $i); | ||
| 48 | |||
| 49 | // Is this an empty message with no body and no mimeparts? | ||
| 50 | if (!$origbody && !$mimeparts) { | ||
| 51 | // @TODO: Log that we got an empty email? | ||
| 52 | continue; | ||
| 53 | weitzman | 1.80 | } |
| 54 | |||
| 55 | killes | 1.76 | $num_processed++; |
| 56 | |||
| 57 | // we must process before authenticating because the password may be in Commands | ||
| 58 | $node = mailhandler_process_message($header, $origbody, $mailbox); | ||
| 59 | |||
| 60 | // check if mail originates from an authenticated user | ||
| 61 | $node = mailhandler_authenticate($node, $header, $origbody, $mailbox); | ||
| 62 | |||
| 63 | weitzman | 1.87.2.6 | // Put $mimeparts on the node |
| 64 | $node->mimeparts = $mimeparts; | ||
| 65 | weitzman | 1.87.2.3 | |
| 66 | killes | 1.76 | // we need to change the current user |
| 67 | // this has to be done here to allow modules | ||
| 68 | // to create users | ||
| 69 | mailhandler_switch_user($node->uid); | ||
| 70 | |||
| 71 | // modules may override node elements before submitting. they do so by returning the node. | ||
| 72 | foreach (module_list() as $name) { | ||
| 73 | weitzman | 1.80 | if (module_hook($name, 'mailhandler')) { |
| 74 | $function = $name .'_mailhandler'; | ||
| 75 | killes | 1.76 | if (!($node = $function($node, $result, $i, $header, $mailbox))) { |
| 76 | // Exit if a module has handled the submitted data. | ||
| 77 | break; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | if ($node) { | ||
| 83 | weitzman | 1.80 | if ($node->type == 'comment') { |
| 84 | killes | 1.76 | mailhandler_comment_submit($node, $header, $mailbox, $origbody); |
| 85 | } | ||
| 86 | else { | ||
| 87 | mailhandler_node_submit($node, $header, $mailbox, $origbody); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | // don't delete while we're only getting new messages | ||
| 91 | chriskennedy | 1.87 | if ($mailbox['delete_after_read']) { |
| 92 | killes | 1.76 | imap_delete($result, $i); |
| 93 | } | ||
| 94 | |||
| 95 | // switch back to original user | ||
| 96 | mailhandler_switch_user(); | ||
| 97 | } | ||
| 98 | imap_close($result, CL_EXPUNGE); | ||
| 99 | weitzman | 1.80 | return t('Mailhandler retrieve successful: %num_processed messages for %m', array('%num_processed' => $num_processed, '%m' => $mailbox['mail'])); |
| 100 | killes | 1.76 | } |
| 101 | else { | ||
| 102 | chriskennedy | 1.87 | if ($err) { |
| 103 | weitzman | 1.87.2.4 | watchdog('mailhandler', t('Mailhandler %c connection failed: %m', array('%c' => ($mailbox['imap'] ? 'imap' : 'POP3'), '%m' => $mailbox['mail'])), WATCHDOG_ERROR); |
| 104 | weitzman | 1.80 | return t('Mailhandler %c connection failed: %m', array('%c' => ($mailbox['imap'] ? 'imap' : 'POP3'), '%m' => $mailbox['mail'])); |
| 105 | killes | 1.76 | } |
| 106 | else { | ||
| 107 | weitzman | 1.87.2.4 | watchdog('mailhandler', t('Mailhandler: Could not access local folder: %m', array('%m' => $mailbox['mail'])), WATCHDOG_ERROR); |
| 108 | weitzman | 1.80 | return t('Mailhandler could not access local folder: %m', array('%m' => $mailbox['mail'])); |
| 109 | killes | 1.76 | } |
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | /** | ||
| 114 | * Create the comment. | ||
| 115 | */ | ||
| 116 | function mailhandler_comment_submit($node, $header, $mailbox, $origbody) { | ||
| 117 | if (!$node->subject) $node->subject = $node->title; | ||
| 118 | if (!$node->comment) $node->comment = $node->body; | ||
| 119 | // We want the comment to have the email time, not the current time | ||
| 120 | $node->timestamp = $node->created; | ||
| 121 | weitzman | 1.80 | // comment_save gets an array |
| 122 | $edit = (array)$node; | ||
| 123 | weitzman | 1.86 | |
| 124 | weitzman | 1.77 | // post the comment. if unable, send a failure email when so configured |
| 125 | weitzman | 1.80 | if (!comment_save($edit) && $mailbox['replies']) { |
| 126 | killes | 1.76 | // $fromaddress really refers to the mail header which is authoritative for authentication |
| 127 | weitzman | 1.86 | list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox); |
| 128 | $error_txt = t("Sorry, your comment experienced an error and was not posted. Possible reasons are\n- you have insufficient permission to post comments\n- The node is no longer open for comments.\n\n"); | ||
| 129 | weitzman | 1.80 | $error = $error_txt. t("\n\nYou sent:\n\nFrom: %f\nSubject: %t\nBody:\n%b", array('%f' => $fromaddress, '%t' => $header->subject, '%b' => $origbody)); |
| 130 | weitzman | 1.87.2.11 | drupal_mail('mailhandler_error_comment', $fromaddress, t('Email submission to %sn failed - %subj', array('%sn' => variable_get('site_name', 'Drupal'), '%subj' => $header->subject))); |
| 131 | chriskennedy | 1.87 | $watchdog = t('Mailhandler: comment submission failure: %subject.', array('%subject' => $edit['subject'])); |
| 132 | weitzman | 1.87.2.4 | watchdog('mailhandler', $watchdog, WATCHDOG_ERROR); |
| 133 | killes | 1.76 | } |
| 134 | } | ||
| 135 | |||
| 136 | /** | ||
| 137 | * Create the node. | ||
| 138 | */ | ||
| 139 | weitzman | 1.83 | // handle defaults for node creation (e.g. comment | promote | moderate | sticky fields) |
| 140 | $node_blog_default = variable_get('node_options_blog', array('status', 'promote')); | ||
| 141 | $node->status = in_array('status', $node_blog_default); | ||
| 142 | $node->promote = in_array('promote', $node_blog_default); | ||
| 143 | $node->moderate = in_array('moderate', $node_blog_default); | ||
| 144 | $node->revision = in_array('revision', $node_blog_default); | ||
| 145 | $node->comment = variable_get('comment_blog', 2); | ||
| 146 | |||
| 147 | killes | 1.76 | function mailhandler_node_submit($node, $header, $mailbox, $origbody) { |
| 148 | |||
| 149 | weitzman | 1.86 | list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox); |
| 150 | killes | 1.76 | |
| 151 | //dprint_r($node); //DEBUG | ||
| 152 | weitzman | 1.87.2.10 | |
| 153 | // Drupal 5.x & 6.x don't support multiple validations: each node_validate() | ||
| 154 | // call will ADD error messages to previous ones, so if some validation error | ||
| 155 | // occours in one message it will be reported in all messages after it. | ||
| 156 | // Since there is no way to reset form errors, the only method to avoid this | ||
| 157 | // problem is working with $_SESSION['messages'], used by form_set_error(). | ||
| 158 | // See http://drupal.org/node/271975 for more info. | ||
| 159 | // Warning: with this method, if the same error message is reported for 2+ different | ||
| 160 | // fields it will be detected only for the last one. | ||
| 161 | if (!isset($_SESSION['messages'])) { | ||
| 162 | $_SESSION['messages'] = array(); | ||
| 163 | } | ||
| 164 | $saved_errors = is_array($_SESSION['messages']['error']) ? $_SESSION['messages']['error'] : array(); | ||
| 165 | $_SESSION['messages']['error'] = array(); | ||
| 166 | weitzman | 1.80 | node_validate($node); |
| 167 | weitzman | 1.87.2.10 | $error = array(); |
| 168 | if (count($_SESSION['messages']['error'])) { | ||
| 169 | $allerrors = form_get_errors(); | ||
| 170 | foreach ($_SESSION['messages']['error'] as $message) { | ||
| 171 | $keys = array_keys($allerrors, $message); | ||
| 172 | if (!$keys || !count($keys)) { | ||
| 173 | // Not a validation error (but an error, i'll print it) | ||
| 174 | $saved_errors[] = $message; | ||
| 175 | } else { | ||
| 176 | // This is a validation error, i take the last field with it (previous fields | ||
| 177 | // should be about previous validations) | ||
| 178 | $error[$keys[count($keys) - 1]] = $message; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | } | ||
| 182 | weitzman | 1.87.2.13 | if (is_array($saved_errors) && count($saved_errors)) { |
| 183 | weitzman | 1.87.2.12 | $_SESSION['messages']['error'] = $saved_errors; |
| 184 | weitzman | 1.87.2.13 | } |
| 185 | else { | ||
| 186 | weitzman | 1.87.2.12 | unset($_SESSION['messages']['error']); |
| 187 | weitzman | 1.87.2.13 | } |
| 188 | weitzman | 1.87.2.12 | |
| 189 | killes | 1.76 | if (!$error) { |
| 190 | weitzman | 1.83 | // Prepare the node for save and allow modules make changes |
| 191 | weitzman | 1.80 | $node = node_submit($node); |
| 192 | // Save the node | ||
| 193 | killes | 1.76 | if ($node->nid) { |
| 194 | weitzman | 1.80 | if (node_access('update', $node)) { |
| 195 | killes | 1.76 | node_save($node); |
| 196 | weitzman | 1.87.2.4 | watchdog('mailhandler', t("Mailhandler: Updated '%t' by %f", array('%t' => $node->title, '%f' => $fromaddress)), WATCHDOG_NOTICE); |
| 197 | killes | 1.76 | } |
| 198 | else { | ||
| 199 | weitzman | 1.80 | $errortxt = t("The e-mail address '%f' may not update %t items.", array('%f' => $fromaddress, '%t' => $node->type)); |
| 200 | killes | 1.76 | } |
| 201 | } | ||
| 202 | else { | ||
| 203 | weitzman | 1.80 | if (node_access('create', $node)) { |
| 204 | killes | 1.76 | node_save($node); |
| 205 | weitzman | 1.87.2.4 | watchdog('mailhandler', t("Mailhandler: Added '%t' by %f", array('%t' => $node->title, '%f' => $fromaddress)), WATCHDOG_NOTICE); |
| 206 | killes | 1.76 | } |
| 207 | else { | ||
| 208 | weitzman | 1.80 | $errortxt = t("The e-mail address '%f' may not create %t items.", array('%f' => $fromaddress, '%t' => $node->type)); |
| 209 | killes | 1.76 | } |
| 210 | } | ||
| 211 | } | ||
| 212 | else { | ||
| 213 | $errortxt = t("Your submission is invalid: \n\n"); | ||
| 214 | foreach ($error as $key => $value) { | ||
| 215 | $errortxt .= "$key: $value\n"; | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | if ($errortxt) { | ||
| 220 | weitzman | 1.87.2.4 | watchdog('mailhandler', "Mailhandler: $errortxt", WATCHDOG_ERROR); |
| 221 | weitzman | 1.80 | if ($mailbox['replies']) { |
| 222 | $errortxt .= t("\n\nYou sent:\n\nFrom: %f\nSubject: %t\nBody:\n%b", array('%f' => $fromaddress, '%t' => $header->subject, '%b' => $origbody)); | ||
| 223 | weitzman | 1.87.2.11 | drupal_mail('mailhandler_error_node', $fromaddress, t('Email submission to %sn failed - %subj', array('%sn' => variable_get('site_name', 'Drupal'), '%subj' => $node->title)), $errortxt); |
| 224 | killes | 1.76 | } |
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | /** | ||
| 229 | * Append default commands. Separate commands from body. Strip signature. | ||
| 230 | * Return a node object. | ||
| 231 | */ | ||
| 232 | function mailhandler_process_message($header, $body, $mailbox) { | ||
| 233 | weitzman | 1.80 | $node = new stdClass(); |
| 234 | killes | 1.76 | |
| 235 | // initialize params | ||
| 236 | weitzman | 1.80 | $sep = $mailbox['sigseparator']; |
| 237 | killes | 1.76 | |
| 238 | // copy any name/value pairs from In-Reply-To or References e-mail headers to $node. Useful for maintaining threading info. | ||
| 239 | if ($header->references) { | ||
| 240 | // we want the final element in references header, watching out for white space | ||
| 241 | weitzman | 1.80 | $threading = substr(strrchr($header->references, '<'), 0); |
| 242 | killes | 1.76 | } |
| 243 | else if ($header->in_reply_to) { | ||
| 244 | weitzman | 1.80 | $threading = str_replace(strstr($header->in_reply_to, '>'), '>', $header->in_reply_to); // Some MUAs send more info in that header. |
| 245 | killes | 1.76 | } |
| 246 | weitzman | 1.80 | if ($threading = rtrim(ltrim($threading, '<'), '>')) { //strip angle brackets |
| 247 | killes | 1.76 | if ($threading) $node->threading = $threading; |
| 248 | parse_str($threading, $tmp); | ||
| 249 | weitzman | 1.80 | if ($tmp['host']) { |
| 250 | $tmp['host'] = ltrim($tmp['host'], '@'); // strip unnecessary @ from 'host' element | ||
| 251 | killes | 1.76 | } |
| 252 | foreach ($tmp as $key => $value) { | ||
| 253 | $node->$key = $value; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 257 | // prepend the default commands for this mailbox | ||
| 258 | weitzman | 1.80 | if ($mailbox['commands']) { |
| 259 | chriskennedy | 1.87 | $body = trim($mailbox['commands']) ."\n". $body; |
| 260 | killes | 1.76 | } |
| 261 | |||
| 262 | weitzman | 1.87.2.15 | // We set the type now, because we need it in the next block |
| 263 | if (!$node->type) $node->type = 'blog'; | ||
| 264 | |||
| 265 | // Reset $node->taxonomy | ||
| 266 | $node->taxonomy = array(); | ||
| 267 | |||
| 268 | killes | 1.76 | // process the commands and the body |
| 269 | $lines = explode("\n", $body); | ||
| 270 | for ($i = 0; $i < count($lines); $i++) { | ||
| 271 | $line = trim($lines[$i]); | ||
| 272 | weitzman | 1.80 | $words = explode(' ', $line); |
| 273 | killes | 1.76 | // look for a command line. if not present, note which line number is the boundary |
| 274 | weitzman | 1.80 | if (substr($words[0], -1) == ':' && is_null($endcommands)) { |
| 275 | killes | 1.76 | // Looks like a name: value pair |
| 276 | weitzman | 1.80 | $data = explode(': ', $line, 2); |
| 277 | killes | 1.76 | |
| 278 | //TODO: allow for nested arrays in commands ... Possibly trim() values after explode(). | ||
| 279 | // if needed, turn this command value into an array | ||
| 280 | weitzman | 1.80 | if (substr($data[1], 0, 1) == '[' && substr($data[1], -1, 1) == ']') { |
| 281 | $data[1] = rtrim(ltrim($data[1], '['), ']'); //strip brackets | ||
| 282 | killes | 1.76 | $data[1] = explode(",", $data[1]); |
| 283 | } | ||
| 284 | weitzman | 1.80 | $data[0] = strtolower(str_replace(' ', '_', $data[0])); |
| 285 | killes | 1.76 | // if needed, map term names into IDs. this should move to taxonomy_mailhandler() |
| 286 | weitzman | 1.80 | if ($data[0] == 'taxonomy' && !is_numeric($data[1][0])) { |
| 287 | killes | 1.76 | array_walk($data[1], 'mailhandler_term_map'); |
| 288 | weitzman | 1.87.2.15 | $node->taxonomy = array_merge($node->taxonomy, $data[1]); |
| 289 | unset($data[0]); | ||
| 290 | } | ||
| 291 | else if (substr($data[0], 0, 9) == 'taxonomy[' && substr($data[0], -1, 1) == ']'){ | ||
| 292 | // make sure a valid vid is passed in: | ||
| 293 | $vid = substr($data[0], 9, -1); | ||
| 294 | $vocabulary = taxonomy_get_vocabulary($vid); | ||
| 295 | // if the vocabulary is not activated for that node type, unset $data[0], so the command will be ommited from $node | ||
| 296 | // TODO: add an error message | ||
| 297 | if (!in_array($node->type, $vocabulary->nodes)) { | ||
| 298 | unset($data[0]); | ||
| 299 | } | ||
| 300 | else if (!$vocabulary->tags) { | ||
| 301 | array_walk($data[1], 'mailhandler_term_map'); | ||
| 302 | $node->taxonomy = array_merge($node->taxonomy, $data[1]); | ||
| 303 | unset($data[0]); | ||
| 304 | } | ||
| 305 | else if ($vocabulary->tags) { | ||
| 306 | // for freetagging vocabularies, we just pass the list of terms | ||
| 307 | $node->taxonomy['tags'][$vid] = implode(',', $data[1]); | ||
| 308 | unset($data[0]); // unset, so it won't be included when populating the node object | ||
| 309 | } | ||
| 310 | killes | 1.76 | } |
| 311 | weitzman | 1.87.2.8 | if (!empty($data[0])) { |
| 312 | $node->$data[0] = $data[1]; | ||
| 313 | } | ||
| 314 | killes | 1.76 | } |
| 315 | else { | ||
| 316 | if (is_null($endcommands)) $endcommands = $i; | ||
| 317 | } | ||
| 318 | |||
| 319 | // stop when we encounter the sig. we'll discard all remaining text. | ||
| 320 | $start = substr($line, 0, strlen($sep)+3); | ||
| 321 | if ($sep && strstr($start, $sep)) { // mail clients sometimes prefix replies with ' >' | ||
| 322 | break; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | |||
| 326 | // isolate the body from the commands and the sig | ||
| 327 | $tmp = array_slice($lines, $endcommands, $i - $endcommands); | ||
| 328 | // flatten and assign the body to node object. note that filter() is called within node_save() [tested with blog post] | ||
| 329 | $node->body = implode("\n", $tmp); | ||
| 330 | |||
| 331 | if (!$node->teaser) $node->teaser = node_teaser($node->body); | ||
| 332 | weitzman | 1.87.2.15 | |
| 333 | killes | 1.76 | // decode encoded subject line |
| 334 | $subjectarr = imap_mime_header_decode($header->subject); | ||
| 335 | chriskennedy | 1.87 | for ($i = 0; $i < count($subjectarr); $i++) { |
| 336 | killes | 1.76 | if ($subjectarr[$i]->charset != 'default') |
| 337 | $node->title .= drupal_convert_to_utf8($subjectarr[$i]->text, $subjectarr[$i]->charset); | ||
| 338 | else | ||
| 339 | $node->title .= $subjectarr[$i]->text; | ||
| 340 | } | ||
| 341 | |||
| 342 | $node->created = $header->udate; | ||
| 343 | $node->changed = $header->udate; | ||
| 344 | weitzman | 1.80 | $node->format = $mailbox['format']; |
| 345 | killes | 1.76 | |
| 346 | return $node; | ||
| 347 | } | ||
| 348 | |||
| 349 | /** | ||
| 350 | * Accept a taxonomy term name and replace with a tid. this belongs in taxonomy.module. | ||
| 351 | */ | ||
| 352 | function mailhandler_term_map(&$term) { | ||
| 353 | // provide case insensitive and trimmed map so as to maximize likelihood of successful mapping | ||
| 354 | chriskennedy | 1.87 | $term = db_result(db_query("SELECT tid FROM {term_data} WHERE LOWER('". trim($term) ."') LIKE LOWER(name)")); |
| 355 | killes | 1.76 | } |
| 356 | |||
| 357 | /** | ||
| 358 | * Determine who is the author of the upcoming node. | ||
| 359 | */ | ||
| 360 | function mailhandler_authenticate($node, $header, $origbody, $mailbox) { | ||
| 361 | |||
| 362 | // $fromaddress really refers to the mail header which is authoritative for authentication | ||
| 363 | weitzman | 1.86 | list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox); |
| 364 | weitzman | 1.82 | if ($from_user = mailhandler_user_load($fromaddress, $node->pass, $mailbox)) { |
| 365 | killes | 1.76 | $node->uid = $from_user->uid; // success! |
| 366 | $node->name = $from_user->name; | ||
| 367 | } | ||
| 368 | weitzman | 1.80 | else if (function_exists('mailalias_user')) { // since $fromaddress failed, try e-mail aliases |
| 369 | chriskennedy | 1.87 | $result = db_query("SELECT mail FROM {users} WHERE data LIKE '%%". $fromaddress ."%%'"); |
| 370 | killes | 1.76 | while ($alias = db_result($result)) { |
| 371 | weitzman | 1.82 | if ($from_user = mailhandler_user_load($alias, $node->pass, $mailbox)) { |
| 372 | killes | 1.76 | $node->uid = $from_user->uid; // success! |
| 373 | $node->name = $from_user->name; | ||
| 374 | break; | ||
| 375 | } | ||
| 376 | } | ||
| 377 | } | ||
| 378 | if (!$from_user) { | ||
| 379 | // failed authentication. we will still try to submit anonymously. | ||
| 380 | $node->uid = 0; | ||
| 381 | weitzman | 1.86 | $node->name = $fromname; // use the name supplied in email headers |
| 382 | killes | 1.76 | } |
| 383 | return $node; | ||
| 384 | } | ||
| 385 | |||
| 386 | /** | ||
| 387 | * Switch from original user to mail submision user and back. | ||
| 388 | * | ||
| 389 | * Note: You first need to run mailhandler_switch_user without | ||
| 390 | * argument to store the current user. Call mailhandler_switch_user | ||
| 391 | * without argument to set the user back to the original user. | ||
| 392 | * | ||
| 393 | * @param $uid The user ID to switch to | ||
| 394 | * | ||
| 395 | */ | ||
| 396 | function mailhandler_switch_user($uid = NULL) { | ||
| 397 | global $user; | ||
| 398 | static $orig_user = array(); | ||
| 399 | |||
| 400 | if (isset($uid)) { | ||
| 401 | weitzman | 1.87.2.9 | session_save_session(FALSE); |
| 402 | killes | 1.76 | $user = user_load(array('uid' => $uid)); |
| 403 | } | ||
| 404 | // retrieve the initial user, can be called multiple times | ||
| 405 | else if (count($orig_user)) { | ||
| 406 | $user = array_shift($orig_user); | ||
| 407 | weitzman | 1.87.2.9 | session_save_session(TRUE); |
| 408 | killes | 1.76 | array_unshift($orig_user, $user); |
| 409 | } | ||
| 410 | // store the initial user | ||
| 411 | else { | ||
| 412 | $orig_user[] = $user; | ||
| 413 | } | ||
| 414 | } | ||
| 415 | |||
| 416 | /** | ||
| 417 | * Retrieve user information from his email address. | ||
| 418 | */ | ||
| 419 | weitzman | 1.82 | function mailhandler_user_load($mail, $pass, $mailbox) { |
| 420 | weitzman | 1.80 | if ($mailbox['security'] == 1) { |
| 421 | return user_load(array('mail' => $mail, 'pass' => $pass)); | ||
| 422 | killes | 1.76 | } |
| 423 | else { | ||
| 424 | weitzman | 1.80 | return user_load(array('mail' => $mail)); |
| 425 | killes | 1.76 | } |
| 426 | } | ||
| 427 | |||
| 428 | /** | ||
| 429 | * If available, use the mail header specified in mailbox config. otherwise use From: header | ||
| 430 | */ | ||
| 431 | function mailhandler_get_fromaddress($header, $mailbox) { | ||
| 432 | weitzman | 1.80 | if ($fromheader = strtolower($mailbox['fromheader']) && isset($header->$fromheader)) { |
| 433 | killes | 1.76 | $from = $header->$fromheader; |
| 434 | } | ||
| 435 | else { | ||
| 436 | $from = $header->from; | ||
| 437 | } | ||
| 438 | weitzman | 1.86 | return array($from[0]->mailbox .'@'. $from[0]->host, $from[0]->personal); |
| 439 | killes | 1.76 | } |
| 440 | |||
| 441 | /** | ||
| 442 | * Returns the first part with the specified mime_type | ||
| 443 | * | ||
| 444 | * USAGE EXAMPLES - from php manual: imap_fetch_structure() comments | ||
| 445 | * $data = get_part($stream, $msg_number, "TEXT/PLAIN"); // get plain text | ||
| 446 | * $data = get_part($stream, $msg_number, "TEXT/HTML"); // get HTML text | ||
| 447 | */ | ||
| 448 | function mailhandler_get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false) { | ||
| 449 | |||
| 450 | if (!$structure) { | ||
| 451 | $structure = imap_fetchstructure($stream, $msg_number); | ||
| 452 | } | ||
| 453 | if ($structure) { | ||
| 454 | foreach ($structure->parameters as $parameter) { | ||
| 455 | if (strtoupper($parameter->attribute) == 'CHARSET') { | ||
| 456 | $encoding = $parameter->value; | ||
| 457 | //watchdog('mailhandler', 'Encoding is ' . $encoding); | ||
| 458 | } | ||
| 459 | } | ||
| 460 | if ($mime_type == mailhandler_get_mime_type($structure)) { | ||
| 461 | if (!$part_number) { | ||
| 462 | weitzman | 1.80 | $part_number = '1'; |
| 463 | killes | 1.76 | } |
| 464 | $text = imap_fetchbody($stream, $msg_number, $part_number); | ||
| 465 | weitzman | 1.87.2.7 | if ($structure->encoding == ENCBASE64) { |
| 466 | killes | 1.76 | return drupal_convert_to_utf8(imap_base64($text), $encoding); |
| 467 | } | ||
| 468 | weitzman | 1.87.2.7 | else if ($structure->encoding == ENCQUOTEDPRINTABLE) { |
| 469 | killes | 1.76 | return drupal_convert_to_utf8(quoted_printable_decode($text), $encoding); |
| 470 | } | ||
| 471 | else { | ||
| 472 | return drupal_convert_to_utf8($text, $encoding); | ||
| 473 | } | ||
| 474 | } | ||
| 475 | weitzman | 1.87.2.7 | if ($structure->type == TYPEMULTIPART) { /* multipart */ |
| 476 | killes | 1.76 | while (list($index, $sub_structure) = each ($structure->parts)) { |
| 477 | if ($part_number) { | ||
| 478 | weitzman | 1.80 | $prefix = $part_number .'.'; |
| 479 | killes | 1.76 | } |
| 480 | $data = mailhandler_get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1)); | ||
| 481 | if ($data) { | ||
| 482 | return $data; | ||
| 483 | } | ||
| 484 | } | ||
| 485 | } | ||
| 486 | } | ||
| 487 | weitzman | 1.80 | |
| 488 | killes | 1.76 | return false; |
| 489 | } | ||
| 490 | |||
| 491 | weitzman | 1.87.2.3 | |
| 492 | /** | ||
| 493 | * Returns an array of parts as file objects | ||
| 494 | weitzman | 1.87.2.6 | * |
| 495 | weitzman | 1.87.2.3 | * @param |
| 496 | weitzman | 1.87.2.6 | * @param $structure |
| 497 | * A message structure, usually used to recurse into specific parts | ||
| 498 | weitzman | 1.87.2.3 | * @param $max_depth |
| 499 | * Maximum Depth to recurse into parts. | ||
| 500 | weitzman | 1.87.2.6 | * @param $depth |
| 501 | weitzman | 1.87.2.3 | * The current recursion depth. |
| 502 | * @param $part_number | ||
| 503 | * A message part number to track position in a message during recursion. | ||
| 504 | * @return | ||
| 505 | * An array of file objects. | ||
| 506 | */ | ||
| 507 | function mailhandler_get_parts($stream, $msg_number, $max_depth = 10, $depth = 0, $structure = FALSE, $part_number = FALSE) { | ||
| 508 | $parts = array(); | ||
| 509 | |||
| 510 | // Load Structure. | ||
| 511 | if (!$structure && !$structure = imap_fetchstructure($stream, $msg_number)) { | ||
| 512 | watchdog('mailhandler', t('Could not fetch structure for message number %msg_number', array('%msg_number' => $msg_number)), WATCHDOG_NOTICE); | ||
| 513 | return $parts; | ||
| 514 | } | ||
| 515 | |||
| 516 | // Recurse into multipart messages. | ||
| 517 | weitzman | 1.87.2.7 | if ($structure->type == TYPEMULTIPART) { |
| 518 | weitzman | 1.87.2.3 | // Restrict recursion depth. |
| 519 | if ($depth >= $max_depth) { | ||
| 520 | weitzman | 1.87.2.6 | watchdog('mailhandler', t('Maximum recursion depths met in mailhander_get_structure_part for |
| 521 | weitzman | 1.87.2.3 | message number %msg_number.', array('%msg_number' => $msg_number)), WATCHDOG_NOTICE); |
| 522 | return $parts; | ||
| 523 | } | ||
| 524 | foreach($structure->parts as $index => $sub_structure) { | ||
| 525 | // If a part number was passed in and we are a multitype message, prefix the | ||
| 526 | // the part number for the recursive call to match the imap4 dot seperated part indexing. | ||
| 527 | if ($part_number) { | ||
| 528 | $prefix = $part_number .'.'; | ||
| 529 | } | ||
| 530 | $sub_parts = mailhandler_get_parts($stream, $msg_number, $max_depth, $depth + 1, | ||
| 531 | $sub_structure, $prefix . ($index + 1)); | ||
| 532 | $parts = array_merge($parts, $sub_parts); | ||
| 533 | } | ||
| 534 | return $parts; | ||
| 535 | } | ||
| 536 | |||
| 537 | // Per Part Parsing. | ||
| 538 | |||
| 539 | // Initalize file object like part structure. | ||
| 540 | $part = new StdClass(); | ||
| 541 | $part->attributes = array(); | ||
| 542 | $part->filename = 'unnamed_attachment'; | ||
| 543 | if (!$part->filemime = mailhandler_get_mime_type($structure)) { | ||
| 544 | watchdog('mailhandler', t('Could not fetch mime type for message part. Defaulting to application/octet-stream.'), | ||
| 545 | WATCHDOG_NOTICE); | ||
| 546 | $part->filemime = 'application/octet-stream'; | ||
| 547 | } | ||
| 548 | |||
| 549 | if ($structure->ifparameters) { | ||
| 550 | foreach ($structure->parameters as $parameter) { | ||
| 551 | switch (strtoupper($parameter->attribute)) { | ||
| 552 | case 'NAME': | ||
| 553 | case 'FILENAME': | ||
| 554 | $part->filename = $parameter->value; | ||
| 555 | break; | ||
| 556 | default: | ||
| 557 | // put every thing else in the attributes array; | ||
| 558 | $part->attributes[$parameter->attribute] = $parameter->value; | ||
| 559 | } | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | // Handle Content-Disposition parameters for non-text types. | ||
| 564 | weitzman | 1.87.2.7 | if ($structure->type != TYPETEXT && $structure->ifdparameters) { |
| 565 | weitzman | 1.87.2.3 | foreach ($structure->dparameters as $parameter) { |
| 566 | switch (strtoupper($parameter->attribute)) { | ||
| 567 | case 'NAME': | ||
| 568 | case 'FILENAME': | ||
| 569 | $part->filename = $parameter->value; | ||
| 570 | break; | ||
| 571 | // put every thing else in the attributes array; | ||
| 572 | default: | ||
| 573 | $part->attributes[$parameter->attribute] = $parameter->value; | ||
| 574 | } | ||
| 575 | } | ||
| 576 | } | ||
| 577 | |||
| 578 | // Retrieve part convert MIME encoding to UTF-8 | ||
| 579 | weitzman | 1.87.2.6 | if(!$part->data = imap_fetchbody($stream, $msg_number, $part_number)) { |
| 580 | weitzman | 1.87.2.3 | drupal_set_message("imap_fetchbody($stream, $msg_number, $part_number)"); |
| 581 | watchdog('mailhandler', 'No Data!!', WATCHDOG_ERROR); | ||
| 582 | return $parts; | ||
| 583 | } | ||
| 584 | |||
| 585 | // convert text attachment to UTF-8. | ||
| 586 | weitzman | 1.87.2.7 | if ($structure->type == TYPETEXT) { |
| 587 | weitzman | 1.87.2.3 | $part->data = imap_utf8($part->data); |
| 588 | } | ||
| 589 | weitzman | 1.87.2.6 | else { |
| 590 | // If not text then decode as necessary | ||
| 591 | weitzman | 1.87.2.7 | if ($structure->encoding == ENCBASE64) { |
| 592 | weitzman | 1.87.2.6 | $part->data = imap_base64($part->data); |
| 593 | } | ||
| 594 | weitzman | 1.87.2.7 | else if ($structure->encoding == ENCQUOTEDPRINTABLE) { |
| 595 | weitzman | 1.87.2.6 | $part->data = quoted_printable_decode($part->data); |
| 596 | } | ||
| 597 | } | ||
| 598 | weitzman | 1.87.2.3 | |
| 599 | //always return an array to satisfy array_merge in recursion catch, and array return value. | ||
| 600 | $parts[] = $part; | ||
| 601 | return $parts; | ||
| 602 | } | ||
| 603 | |||
| 604 | killes | 1.76 | /** |
| 605 | * Retrieve MIME type of the message structure. | ||
| 606 | */ | ||
| 607 | function mailhandler_get_mime_type(&$structure) { | ||
| 608 | weitzman | 1.80 | static $primary_mime_type = array('TEXT', 'MULTIPART', 'MESSAGE', 'APPLICATION', 'AUDIO', 'IMAGE', 'VIDEO', 'OTHER'); |
| 609 | $type_id = (int)$structure->type; | ||
| 610 | if (isset($primary_mime_type[$type_id]) && !empty($structure->subtype)) { | ||
| 611 | return $primary_mime_type[$type_id] .'/'. $structure->subtype; | ||
| 612 | } | ||
| 613 | return 'TEXT/PLAIN'; | ||
| 614 | } | ||
| 615 | |||
| 616 | /** | ||
| 617 | * Implementation of hook_user(). | ||
| 618 | chriskennedy | 1.87.2.5 | * |
| 619 | * Commented out because mailhandler cannot assume that this mailbox will | ||
| 620 | * accept blog entries from users. | ||
| 621 | */ | ||
| 622 | /* | ||
| 623 | weitzman | 1.80 | function mailhandler_user($type, &$edit, &$account, $category = NULL) { |
| 624 | if ($type == 'view') { | ||
| 625 | // @TODO: We may add a new option in mailboxes to choose which roles can post. | ||
| 626 | if ((user_access('edit own blog') && $GLOBALS['user']->uid == $account->uid) || user_access('administer users')) { | ||
| 627 | // for now, just show the first mailbox address to user. | ||
| 628 | $mailbox = db_fetch_array(db_query('SELECT * FROM {mailhandler} WHERE enabled = 1 ORDER BY mail')); | ||
| 629 | if ($mailbox) { | ||
| 630 | if ($mailbox['security'] == 1) { | ||
| 631 | $form = array( | ||
| 632 | '#title' => t('Mail Handler'), | ||
| 633 | chriskennedy | 1.87 | '#value' => t('You may post to <a href="@blog">your blog</a> by sending an e-mail to %mail. Be sure to include your password at the top of your e-mail body (e.g. <em>pass=mypassword</em>).', array('@blog' => url("blog/$account->uid"), '%mail' => $mailbox['mail'])) |
| 634 | weitzman | 1.80 | ); |
| 635 | killes | 1.76 | } |
| 636 | else { | ||
| 637 | weitzman | 1.80 | $form = array( |
| 638 | '#title' => t('Mail Handler'), | ||
| 639 | chriskennedy | 1.87 | '#value' => t('You may post to <a href="@blog">your blog</a> by sending an e-mail to %mail.', array('@blog' => url("blog/$account->uid"), '%mail' => $mailbox['mail'])) |
| 640 | weitzman | 1.80 | ); |
| 641 | killes | 1.76 | } |
| 642 | weitzman | 1.80 | return array(t('Mail Handler') => array('mailhandler' => theme('item', $form))); |
| 643 | killes | 1.76 | } |
| 644 | weitzman | 1.80 | } |
| 645 | killes | 1.76 | } |
| 646 | } | ||
| 647 | chriskennedy | 1.87.2.5 | */ |
| 648 | killes | 1.76 | |
| 649 | /** | ||
| 650 | weitzman | 1.80 | * Implementation of hook_cron(). Process msgs from all enabled mailboxes. |
| 651 | killes | 1.76 | */ |
| 652 | function mailhandler_cron() { | ||
| 653 | // store the original cron user | ||
| 654 | mailhandler_switch_user(); | ||
| 655 | weitzman | 1.80 | $result = db_query('SELECT * FROM {mailhandler} WHERE enabled = 1 ORDER BY mail'); |
| 656 | killes | 1.76 | while ($mailbox = db_fetch_array($result)) { |
| 657 | mailhandler_retrieve($mailbox); | ||
| 658 | } | ||
| 659 | // revert to the original cron user | ||
| 660 | mailhandler_switch_user(); | ||
| 661 | } | ||
| 662 | |||
| 663 | weitzman | 1.80 | /** |
| 664 | * Implementation of hook_perm(). | ||
| 665 | */ | ||
| 666 | killes | 1.76 | function mailhandler_perm() { |
| 667 | weitzman | 1.80 | return array('administer mailhandler'); |
| 668 | killes | 1.76 | } |
| 669 | |||
| 670 | weitzman | 1.80 | /** |
| 671 | * Implementation of hook_menu(). | ||
| 672 | */ | ||
| 673 | killes | 1.76 | function mailhandler_menu($may_cache) { |
| 674 | $items = array(); | ||
| 675 | weitzman | 1.80 | $admin_access = user_access('administer mailhandler'); |
| 676 | killes | 1.76 | |
| 677 | if ($may_cache) { | ||
| 678 | chriskennedy | 1.87 | $items[] = array('path' => 'admin/content/mailhandler', 'title' => t('Mailhandler'), |
| 679 | weitzman | 1.80 | 'callback' => 'mailhandler_admin', |
| 680 | chriskennedy | 1.87.2.2 | 'description' => t('Manage mailboxes and retrieve messages.'), |
| 681 | weitzman | 1.80 | 'access' => $admin_access); |
| 682 | chriskennedy | 1.87 | $items[] = array('path' => 'admin/content/mailhandler/retrieve', 'title' => t('Retrieve'), |
| 683 | weitzman | 1.80 | 'callback' => 'mailhandler_admin_retrieve', |
| 684 | 'access' => $admin_access, | ||
| 685 | 'type' => MENU_CALLBACK); | ||
| 686 | chriskennedy | 1.87 | $items[] = array('path' => 'admin/content/mailhandler/edit', 'title' => t('Edit mailbox'), |
| 687 | weitzman | 1.80 | 'callback' => 'mailhandler_admin_edit', |
| 688 | 'access' => $admin_access, | ||
| 689 | 'type' => MENU_CALLBACK); | ||
| 690 | chriskennedy | 1.87 | $items[] = array('path' => 'admin/content/mailhandler/delete', 'title' => t('Delete mailbox'), |
| 691 | 'callback' => 'drupal_get_form', | ||
| 692 | 'callback arguments' => array('mailhandler_admin_delete_confirm'), | ||
| 693 | weitzman | 1.80 | 'access' => $admin_access, |
| 694 | 'type' => MENU_CALLBACK); | ||
| 695 | chriskennedy | 1.87 | $items[] = array('path' => 'admin/content/mailhandler/list', 'title' => t('List'), |
| 696 | weitzman | 1.83 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 697 | 'weight' => -10, | ||
| 698 | chriskennedy | 1.87 | 'access' => $admin_access); |
| 699 | $items[] = array('path' => 'admin/content/mailhandler/add', 'title' => t('Add mailbox'), | ||
| 700 | weitzman | 1.80 | 'callback' => 'mailhandler_admin_edit', |
| 701 | 'access' => $admin_access, | ||
| 702 | 'type' => MENU_LOCAL_TASK); | ||
| 703 | } | ||
| 704 | else { | ||
| 705 | chriskennedy | 1.87 | drupal_add_css(drupal_get_path('module', 'mailhandler') .'/mailhandler.css'); |
| 706 | killes | 1.76 | } |
| 707 | |||
| 708 | return $items; | ||
| 709 | } | ||
| 710 | |||
| 711 | weitzman | 1.80 | /** |
| 712 | * Menu callback; presents an overview of all URL aliases. | ||
| 713 | */ | ||
| 714 | function mailhandler_admin() { | ||
| 715 | return mailhandler_display(); | ||
| 716 | killes | 1.76 | } |
| 717 | |||
| 718 | weitzman | 1.80 | /** |
| 719 | * Return a listing of all defined mailboxes. | ||
| 720 | */ | ||
| 721 | function mailhandler_display() { | ||
| 722 | $destination = drupal_get_destination(); | ||
| 723 | zstolar | 1.87.2.16 | $header = array(t('Mailbox'), t('Folder'), array('data' => t('Operations'), 'colspan' => 3)); |
| 724 | weitzman | 1.80 | $rows = array(); |
| 725 | $result = db_query('SELECT * FROM {mailhandler} ORDER BY mail'); | ||
| 726 | while ($mailbox = db_fetch_object($result)) { | ||
| 727 | $rows[] = array( | ||
| 728 | "<a href=\"mailto:$mailbox->mail\">$mailbox->mail</a>", | ||
| 729 | zstolar | 1.87.2.16 | $mailbox->folder ? check_plain($mailbox->folder) : '', |
| 730 | chriskennedy | 1.87 | l(t('Retrieve'), "admin/content/mailhandler/retrieve/$mailbox->mid", array('title' => t('Retrieve and process pending e-mails in this mailbox')), $destination), |
| 731 | l(t('Edit'), "admin/content/mailhandler/edit/$mailbox->mid", array('title' => t('Edit this mailbox configuration')), $destination), | ||
| 732 | l(t('Delete'), "admin/content/mailhandler/delete/$mailbox->mid", array('title' => t('Delete this mailbox')), $destination) | ||
| 733 | weitzman | 1.80 | ); |
| 734 | } | ||
| 735 | |||
| 736 | if (empty($rows)) { | ||
| 737 | $rows[] = array(array('data' => t('No mailboxes available.'), 'colspan' => '4')); | ||
| 738 | } | ||
| 739 | |||
| 740 | return theme('table', $header, $rows); | ||
| 741 | } | ||
| 742 | killes | 1.76 | |
| 743 | weitzman | 1.80 | /** |
| 744 | * Menu callback; Retrieve and process pending e-mails for a mailbox. | ||
| 745 | */ | ||
| 746 | function mailhandler_admin_retrieve($mid = 0) { | ||
| 747 | // store the original user | ||
| 748 | mailhandler_switch_user(); | ||
| 749 | drupal_set_message(mailhandler_retrieve(mailhandler_get_mailbox($mid))); | ||
| 750 | $output = mailhandler_display(); | ||
| 751 | // revert to the original user | ||
| 752 | mailhandler_switch_user(); | ||
| 753 | return $output; | ||
| 754 | } | ||
| 755 | killes | 1.76 | |
| 756 | weitzman | 1.80 | /** |
| 757 | * Menu callback; handles pages for creating and editing mailboxes. | ||
| 758 | */ | ||
| 759 | function mailhandler_admin_edit($mid = 0) { | ||
| 760 | if ($mid) { | ||
| 761 | chriskennedy | 1.87 | $output = drupal_get_form('mailhandler_form', mailhandler_get_mailbox($mid)); |
| 762 | killes | 1.76 | } |
| 763 | weitzman | 1.80 | else { |
| 764 | chriskennedy | 1.87 | $output = drupal_get_form('mailhandler_form'); |
| 765 | killes | 1.76 | } |
| 766 | weitzman | 1.80 | return $output; |
| 767 | killes | 1.76 | } |
| 768 | |||
| 769 | weitzman | 1.80 | /** |
| 770 | * Fetch a specific mailbox from the database. | ||
| 771 | */ | ||
| 772 | killes | 1.76 | function mailhandler_get_mailbox($mid) { |
| 773 | weitzman | 1.80 | return db_fetch_array(db_query("SELECT * FROM {mailhandler} WHERE mid = %d", $mid)); |
| 774 | killes | 1.76 | } |
| 775 | |||
| 776 | weitzman | 1.80 | /** |
| 777 | * Return a form for editing or creating an individual mailbox. | ||
| 778 | */ | ||
| 779 | function mailhandler_form($edit = array()) { | ||
| 780 | chriskennedy | 1.87 | if (empty($edit['folder'])) { |
| 781 | $edit['folder'] = 'INBOX'; | ||
| 782 | } | ||
| 783 | weitzman | 1.80 | |
| 784 | $form['mail'] = array('#type' => 'textfield', '#title' => t('E-mail address'), '#default_value' => $edit['mail'], '#description' => t('The e-mail address to which users should send their submissions.'), '#required' => TRUE); | ||
| 785 | $form['mailto'] = array('#type' => 'textfield', '#title' => t('Second E-mail address'), '#default_value' => $edit['mailto'], '#description' => t('Optional. The e-mail address to which modules should send generated content.')); | ||
| 786 | $form['folder'] = array('#type' => 'textfield', '#title' => t('Folder'), '#default_value' => $edit['folder'], '#description' => t('Optional. The folder where the mail is stored. If you want this mailbox to read from a local folder, give the full path. Leave domain, port, name, and pass empty below. Remember to set the folder to readable and writable by the webserver.')); | ||
| 787 | $form['imap'] = array('#type' => 'select', '#title' => t('POP3 or IMAP Mailbox'), '#options' => array('POP3', 'IMAP'), '#default_value' => $edit['imap'], '#description' => t('If you wish to retrieve mail from a POP3 or IMAP mailbox instead of a Folder, select POP3 or IMAP. Also, complete the Mailbox items below.')); | ||
| 788 | chriskennedy | 1.87.2.1 | $form['domain'] = array('#type' => 'textfield', '#title' => t('Mailbox domain'), '#default_value' => $edit['domain'], '#description' => t('The domain of the server used to collect mail.')); |
| 789 | weitzman | 1.80 | $form['port'] = array('#type' => 'textfield', '#title' => t('Mailbox port'), '#size' => 5, '#maxlength' => 5, '#default_value' => $edit['port'], '#description' => t('The port of the mailbox used to collect mail (usually 110 for POP3, 143 for IMAP).')); |
| 790 | $form['name'] = array('#type' => 'textfield', '#title' => t('Mailbox username'), '#default_value' => $edit['name'], '#description' => t('This username is used while logging into this mailbox during mail retrieval.')); | ||
| 791 | $form['pass'] = array('#type' => 'textfield', '#title' => t('Mailbox password'), '#default_value' => $edit['pass'], '#description' => t('The password corresponding to the username above. Consider using a non-vital password, since this field is stored without encryption in the database.')); | ||
| 792 | killes | 1.76 | |
| 793 | weitzman | 1.80 | // Allow administrators to configure the mailbox with extr |