22 parent::edit_form($form, $form_state);
23 global $cookie_domain;
40 $ajax_settings = array(
41 'callback' =>
'_mailinglist_mailbox_test',
42 'wrapper' =>
'mailinglist_test_results',
46 'message' => t(
'Please wait - testing connection settings...'),
49 $form[
'connection'][
'settings'][
'domain'] = array(
50 '#type' =>
'textfield',
51 '#title' => t(
'Domain'),
54 '#description' => t(
'The domain of the server used to collect mail.'),
55 '#ajax' => $ajax_settings,
57 $form[
'connection'][
'settings'][
'port'] = array(
58 '#type' =>
'textfield',
59 '#title' => t(
'Port'),
63 '#description' => t(
'The mailbox port number (usually 110 for POP3).'),
64 '#element_validate' => array(
'element_validate_integer_positive'),
66 '#ajax' => $ajax_settings,
68 $form[
'connection'][
'settings'][
'name'] = array(
69 '#type' =>
'textfield',
70 '#title' => t(
'Username'),
73 '#description' => t(
'This username is used while logging into this mailbox during mail retrieval.'),
74 '#ajax' => $ajax_settings,
76 $form[
'connection'][
'settings'][
'pass'] = array(
77 '#type' =>
'textfield',
78 '#title' => t(
'Password'),
80 '#description' => t(
'The mailbox password corresponding to the username above. Consider using a non-vital password, since this field is stored with minimal encryption in the database and displayed here.'),
81 '#ajax' => $ajax_settings,
84 $form[
'connection'][
'settings'][
'results'] = array(
85 '#type' =>
'container',
86 '#attributes' => array(
87 'id' =>
'mailinglist_test_results',
91 $form[
'connection'][
'settings'][
'timeout'] = array(
92 '#type' =>
'textfield',
93 '#title' => t(
'Timeout'),
96 '#default_value' => $this->
get_setting(
'timeout', 10),
97 '#description' => t(
'Timeout (in Sec) to connect to server'),
98 '#element_validate' => array(
'element_validate_number'),
100 '#ajax' => $ajax_settings,
103 $form[
'extra'][
'settings'][
'apop'] = array(
104 '#type' =>
'checkbox',
105 '#title' => t(
'Detect APOP?'),
106 '#default_value' => $this->
get_setting(
'apop', FALSE),
107 '#description' => t(
'Check to enable APOP protocal detection'),
110 $form[
'extra'][
'settings'][
'delete_after_read'] = array(
111 '#type' =>
'checkbox',
112 '#title' => t(
'Delete messages after they are processed?'),
113 '#default_value' => $this->
get_setting(
'delete_after_read', TRUE),
114 '#description' => t(
'Uncheck this box to leave read messages in the mailbox. They will not be processed again unless they become marked as unread. You normallys should check this box.'),
117 $form[
'extra'][
'settings'][
'ipv6'] = array(
118 '#type' =>
'checkbox',
119 '#title' => t(
'IPv6'),
120 '#default_value' => $this->
get_setting(
'ipv6', FALSE),
121 '#description' => t(
'Use IPv6'),
131 parent::edit_form_validate($form, $form_state);
132 if ($form_state[
'values'][
'settings'][
'port'] < 1 || 65535 < $form_state[
'values'][
'settings'][
'port']) {
133 form_set_error(
'port', t(
'Port must be between 1 and 65535'));
136 if ($form_state[
'values'][
'settings'][
'port'] != 110) {
137 drupal_set_message(t(
'Non-standard Pop3 Port: @port', array(
'@port' => (
int)$form_state[
'values'][
'settings'][
'port'])),
'warning');
142 if ( $form_state[
'values'][
'settings'][
'delete_after_read'] == 0) {
143 drupal_set_message(t(
'Unless you check off "Delete messages after they are processed" when using a POP3 mailbox, old emails will be re-imported each time the mailbox is processed.'),
'warning');
152 parent::edit_form_submit($form, $form_state);
171 if (!$this->connected) {
172 if (!$this->
connect())
return FALSE;
176 $limit = $stat[
'count'];
177 if ($max > 0 && $max < $limit) $limit = $max;
179 for ($i=1; $i<=$limit; $i++) {
237 if (!isset($this->settings[
'apop'])) {
238 $this->settings[
'apop'] = FALSE;
241 if (!isset($this->settings[
'use_sockets']) || !extension_loaded(
"sockets")) {
242 $this->settings[
'use_sockets'] = FALSE;
245 if (!isset($this->settings[
'ipv6'])) $this->settings[
'ipv6'] = FALSE;
247 $timeout = (double)$this->settings[
'timeout'];
248 $timeout_sec = (int)floor($timeout);
249 $timeout_usec = (int)(1000000*($timeout-$timeout_sec));
250 $timeout_array = array(
'sec' => $timeout_sec,
'usec' => $timeout_usec);
251 $host = $this->settings[
'domain'];
252 $port = $this->settings[
'port'];
254 if ($this->settings[
'use_sockets']) {
255 $this->socket = socket_create(($this->settings[
'ipv6'] ? AF_INET6 : AF_INET), SOCK_STREAM, SOL_TCP );
256 if (!$this->socket) {
257 $this->
log(
'Error creating Socket', this::LOG_ERROR);
260 if (!socket_set_option($this->socket, SOL_SOCKET, SO_RCVTIMEO, $timeout_array) || !socket_set_option($this->socket, SOL_SOCKET, SO_SNDTIMEO, $timeout_array)) {
261 $this->
log(
'Error setting socket timeout', this::LOG_ERROR);
264 if (!socket_connect($this->socket, $host, $port) || !socket_getpeername($this->socket, $this->ipaddr)) {
265 $this->
log(
"Error connecting to server", this::LOG_ERROR);
270 $url =
'tcp://' . $host .
':' . $port;
273 $this->socket = fsockopen($url, $intErrno, $strError, $timeout);
274 if (!stream_set_timeout($this->socket, $timeout_sec, $timeout_usec)) {
275 $this->
log(
'Error setting socket timeout', this::LOG_ERROR);
277 $this->ipaddr = gethostbyname($host);
279 $this->
log(
"Connected to " . $this->ipaddr .
':' . $port .
' [' . $host .
']');
286 $start = strpos($buff,
'<');
287 if ($start !== FALSE) {
288 $stop = strpos($buff,
'>', $start);
289 if ($stop != FALSE) {
290 $this->apop_banner = substr($buff, $start+1, $stop-$start-1);
296 if ($this->settings[
'apop'] && !is_null($this->apop_banner)) {
306 $this->
send_cmd(
"USER " . $this->settings[
'name']);
309 if ($ans[0] ==
'+') {
310 $this->connected = TRUE;
323 if ($this->connected ) {
324 if ($this->settings[
'use_sockets']) {
325 if (socket_close($this->socket) === FALSE ) {
326 $this->
log(
"Error On Socket Disconnect", this::LOG_ERROR);
330 if (!fclose($this->socket)) {
331 $this->
log(
"Error On Socket Disconnect", this::LOG_ERROR);
334 $this->connected = FALSE;
355 if (!$this->connected) {
362 if ($res[
"count"] > 0) {
366 if ($limit == 0 || $limit > $res[
'count']) $limit = $res[
'count'];
367 for ($i=1; $i<=$limit; $i++) {
368 list(, $uidl) = explode(
" ", trim($uidls[$i-1]));
369 list(, $list) = explode(
" ", trim($lists[$i-1]));
370 $res[$i][
"uid"] = (int) $uidl;
371 $res[$i][
"octets"] = (int) $list;
384 if (!$this->connected) {
389 $uidls = explode(
"\r\n", trim($uidls));
399 if (!$this->connected) {
404 $lists = explode(
"\r\n", trim($lists));
416 if (!$this->connected) {
420 $stat = explode(
" ", trim($stat));
421 $res[
'count'] = (int) $stat[1];
422 $res[
'octets'] = (int) $stat[2];
435 $this->
send_cmd(
"DELE " . $msg_num);
445 if ($this->connected) {
458 $this->
send_cmd(
"RETR " . $msg_num);
470 protected function recv_string($buff_size = self::DEFAULT_BUFFER_SIZE, $log = TRUE) {
472 if ($this->settings[
'use_sockets']) {
473 $buff = socket_read($this->socket, $buff_size , PHP_NORMAL_READ);
474 if ($buff === FALSE ) {
475 $this->
log(
"Socket Error", this::LOG_ERROR);
477 $len = strlen($buff);
478 if ($buff[$len-1] !=
"\r") {
479 $this->
log(
'Line too long', this::LOG_ERROR);
482 $buff = substr($buff, 0, $len-1);
485 $buff2 = socket_read($this->socket, 1 , PHP_NORMAL_READ);
486 if ($buff2 === FALSE ) {
487 $this->
log(
"Socket Error", this::LOG_ERROR);
489 if ($buff2 !=
"\n") {
490 $this->
log(
'Bad Line Ends', this::LOG_ERROR);
495 $buff = fgets($this->socket, $buff_size);
497 $this->
log(
"fgets(): Couldn't recieve the string from socket", this::LOG_ERROR);
499 $buff = substr($buff, 0, strlen($buff)-2);
501 if ($log) $this->
log($buff);
514 $buffer = $this->
recv_string(self::DEFAULT_BUFFER_SIZE, FALSE);
515 if ($buffer ==
'.') {
518 $buff .= $buffer .
"\n";
531 protected function send( $cmd ) {
533 if ($this->settings[
'use_sockets']) {
534 if (socket_send($this->socket, $cmd, strlen($cmd), 0) === FALSE ) {
535 $this->
log(
"Pop3 Send Error", this::LOG_ERROR);
539 if (!fwrite($this->socket, $cmd, strlen($cmd))) {
540 $this->
log(
"fwrite(): Failed to write string to socket", this::LOG_ERROR);
560 if (strlen($res) > 0 && $res[0] ==
'-') {
561 $this->
log(
"Response Error " . $res, this::LOG_ERROR);
send_cmd($cmd)
This function send the command to the server and will get the response If the command goes failed...
get_message_list($max=0)
Overrides/Implements Mailinglist:Retrieve::get_message_list Connect to mailbox and run message retrie...
purge_message($id)
Overrides/Implements MailinglistRetrieve::purge_message();.
edit_form_validate(&$form, &$form_state)
Implements ctools_export_ui::edit_form_validate().
close()
Overrides/Implements MailinglistRetrieve::close().
Class defining the contents of an e-mail message.
get_setting($name, $def=NULL)
get_settings()
get_msg($msg_num)
Recieve a raw message.
$ipaddr
String for ipaddr we are connecting to.
$socket
Handle for Socket being used.
get_message($id)
Overrides/Implements MailinglistRetrieve::get_message().
edit_form(&$form, &$form_state)
Implements ctools_export_ui::edit_form().
recv_to_point()
recv_to_point
log($str, $level=self::LOG_NOTICE, $parms=array())
log()
edit_form_submit(&$form, &$form_state)
Implements ctools_export_ui::edit_form_submit().
const DEFAULT_BUFFER_SIZE
quit()
Send the quit command to the server.
send($cmd)
Send a string to the server.
_mailinglist_decode_password($code)
_mailinglist_decode_password
recv_string($buff_size=self::DEFAULT_BUFFER_SIZE, $log=TRUE)
recv_string
Retrieve messages using PHP IMAP library.
get_stat()
Get the stats from the pop3 server This is only a string with the count of mails and their size in yo...
$connected
Are we currently connected/logged in.
Retrieve messages from a Mailinglist Mailbox.
$apop_banner
Banner for APOP.
getOfficeStatus($limit=0)
Get the office status.