DMail Milestone 1.0
Drupal Mail Client
|
Public Member Functions | |
__construct ($user, $pass, $host=NULL, $port=NULL, $service=NULL, $mb_delim=NULL, $encrypt_mode=NULL, $validate_cert=NULL, $readonly=NULL) | |
__destruct () | |
__set ($param, $value) | |
open ($mode=0, $force=FALSE) | |
close () | |
check ($mbox_name=NULL) | |
status ($mbox_name=NULL, $options=SA_ALL) | |
fetch_overview ($messages, $mbox_name=NULL) | |
list_headers ($mbox_name) | |
delete_item ($msgno) | |
copy_item ($msgno, $to_folder) | |
move_item ($msgno, $to_folder) | |
expunge ($mbox_name=NULL) | |
headerinfo ($msgno) | |
fetchheader ($msgno) | |
fetchstructure ($msgno) | |
bodystruct ($msgno, $partno) | |
list_mbox ($mbox) | |
list_mboxes () | |
fetch_item ($msgno, $mime_part= 'TEXT/PLAIN', $parts=NULL) | |
Protected Attributes | |
$host = 'localhost' | |
$port = 143 | |
$service = 'imap' | |
$encrypt = 'none' | |
$validate = FALSE | |
$mbdelim = '.' | |
$mbuser = array('user' => 'mbuser', 'pass' => 'mbpass') | |
$mbreadonly = FALSE | |
$mbflags = NULL | |
$mbconnstr = NULL | |
$mbox = NULL | |
$mbres = NULL | |
Private Member Functions | |
parts ($structure, $msgno, $partno=FALSE) | |
part_decode ($encoding, $text) | |
mime_type ($structure) | |
error () | |
check_mbox ($mbox_name, $open_mode=OP_READONLY) | |
Private Attributes | |
$mode = NULL | |
$check = NULL |
__construct | ( | $ | user, |
$ | pass, | ||
$ | host = NULL , |
||
$ | port = NULL , |
||
$ | service = NULL , |
||
$ | mb_delim = NULL , |
||
$ | encrypt_mode = NULL , |
||
$ | validate_cert = NULL , |
||
$ | readonly = NULL |
||
) |
The object constructor.
$user |
|
$pass |
|
$host |
|
$port |
|
$service |
|
$mb_delim |
|
$encrypt_mode |
|
$validate_cert |
|
$readonly |
|
Definition at line 59 of file imap.lib.
References $host, $port, and $service.
{ $this->mbuser = array('user' => $user, 'pass' => $pass); if ($host) $this->host = $host; if ($port) $this->port = $port; if ($service) $this->service = $service; $this->encrypt = $encrypt_mode; $this->encrypt = ($this->encrypt === 'none' || is_null($this->encrypt)) ? FALSE : $this->encrypt; if ($validate_cert) $this->validate = ($validate_cert) === 'yes' ? TRUE : FALSE; if ($mb_delim) $this->mbdelim = $mb_delim; if ($readonly) $this->mbreadonly = ($readonly) === 'yes' ? TRUE : FALSE; $this->mbflags = '/service=' . $this->service; if ($this->mbreadonly) { $this->mbflags .= '/readonly'; } if ($this->encrypt) { $this->mbflags .= '/' . $this->encrypt; } if ($this->validate) { $this->mbflags .= '/validate-cert'; } else { $this->mbflags .= '/novalidate-cert'; } }
__destruct | ( | ) |
__set | ( | $ | param, |
$ | value | ||
) |
bodystruct | ( | $ | msgno, |
$ | partno | ||
) |
Get the structure of a specified message and body part.
$msgno |
|
$partno |
|
Definition at line 587 of file imap.lib.
References error(), and open().
{ static $except = FALSE; $fetch = imap_bodystruct($this->mbres, $msgno, $partno); $error = $this->error(); if ($error) { switch ($error->type) { case 'CLOSED': { if (!$except) { $this->open(0, TRUE); $except = TRUE; return $this->bodystruct($msgno, $partno); } else { throw new Exception($error->text); } } break; case 'WARNING': { //ignore. } break; default: { throw new Exception($error->text); } break; } } $except = FALSE; return $fetch; }
check | ( | $ | mbox_name = NULL | ) |
Check the mailbox.
$mbox_name |
|
Definition at line 195 of file imap.lib.
References check_mbox().
{ $this->check_mbox($mbox_name); return imap_check($this->mbres); }
check_mbox | ( | $ | mbox_name, |
$ | open_mode = OP_READONLY |
||
) | [private] |
Check if the named bmailbox is open.
$mbox_name |
|
$open_mode |
|
Definition at line 903 of file imap.lib.
Referenced by check(), expunge(), fetch_overview(), list_headers(), and status().
{ if ($mbox_name) { if ($mbox_name != $this->mbox) { $this->mbox = $mbox_name; $this->open($open_mode); } } }
close | ( | ) |
Close the service connection.
Definition at line 175 of file imap.lib.
Referenced by __destruct().
{ $return = NULL; if (is_resource($this->mbres)) $return = imap_close($this->mbres); return $return; }
copy_item | ( | $ | msgno, |
$ | to_folder | ||
) |
delete_item | ( | $ | msgno | ) |
error | ( | ) | [private] |
Get the last error.
Definition at line 831 of file imap.lib.
Referenced by bodystruct(), fetchheader(), fetchstructure(), headerinfo(), and open().
{ $text = imap_last_error(); if ($text === FALSE) { return $text; } $parts = explode(' ', strtolower($text)); switch ($parts[0]) { case 'warning:': { $type = 'WARNING'; } break; case 'unexpected': { $type = 'WARNING'; } break; case 'unterminated': { $type = 'WARNING'; } break; case '[closed]': { $type = 'CLOSED'; } break; case 'invalid': { if ($parts[1] === 'mailbox' && $parts[2] === 'list:' && $parts[3] === '<>') { $type = 'WARNING'; } else { $type = 'UNKNOWN'; } } break; case 'must': { if ($parts[1] === 'use' && $parts[2] === 'comma') { $type = 'WARNING'; } else { $type = 'UNKNOWN'; } } break; case 'no': { if ($parts[1] === 'body' && $parts[2] === 'information') { $type = 'WARNING'; } else { $type = 'UNKNOWN'; } } break; case 'store': { if ($parts[3] === 'read-only') { $type = 'WARNING'; } else { $type = 'UNKNOWN'; } } break; default: { $type = 'UNKNOWN'; } break; } $error->type = $type; $error->text = $text; return $error; }
expunge | ( | $ | mbox_name = NULL | ) |
Removed the items marked deleted.
$mbox_name |
|
Definition at line 354 of file imap.lib.
References check_mbox().
{ $this->check_mbox($mbox_name); return imap_expunge($this->mbres); }
fetch_item | ( | $ | msgno, |
$ | mime_part = 'TEXT/PLAIN' , |
||
$ | parts = NULL |
||
) |
Get the specified mime_part of the item body for the specified message.
$msgno |
|
$mime_part |
|
$parts |
|
Definition at line 677 of file imap.lib.
References parts().
{ if (is_null($parts)) { $structure = imap_fetchstructure($this->mbres, $msgno); $parts = $this->parts($structure, $msgno); return $this->fetch_item($msgno, $mime_part, $parts); } else { $ret = NULL; foreach ($parts as $part) { if ($part->mime_type === $mime_part) { $ret .= "\r\n\r\n" . $part->text; } elseif ($mime_part == 'ATTACHMENT' && $part->disposition == 'attachment') { $att = new stdClass; $att->subtype = $att->filename = $att->name = NULL; $att->subtype = $part->subtype; if ($part->dparameters) { $att->{$part->dparameters[0]->attribute} = $part->dparameters[0]->value; } if ($part->parameters) { $att->{$part->parameters[0]->attribute} = $part->parameters[0]->value; } $att->contents = $part->text; $ret[] = $att; } } return $ret; } }
fetch_overview | ( | $ | messages, |
$ | mbox_name = NULL |
||
) |
Get an overview of the messages in a mailbox.
$messages |
|
$mbox_name |
|
Definition at line 263 of file imap.lib.
References check_mbox().
{ $this->check_mbox($mbox_name); watchdog('imap debug', print_r($messages, true)); return imap_fetch_overview($this->mbres, $messages, 0); }
fetchheader | ( | $ | msgno | ) |
Get the complete unfiltered header of a specified message.
$msgno |
|
Definition at line 486 of file imap.lib.
References error(), and open().
{ static $except = FALSE; $fetch = imap_fetchheader($this->mbres, $msgno); $error = $this->error(); if ($error) { switch ($error->type) { case 'CLOSED': { if (!$except) { $this->open(0, TRUE); $except = TRUE; return $this->fetchheader($msgno); } else { throw new Exception($error->text); } } break; case 'WARNING': { //ignore. } break; default: { throw new Exception($error->text); } break; } } $except = FALSE; return $fetch; }
fetchstructure | ( | $ | msgno | ) |
Get the structure of a specified message.
$msgno |
|
Definition at line 547 of file imap.lib.
References error(), and open().
{ static $except = FALSE; $fetch = imap_fetchstructure($this->mbres, $msgno); $error = $this->error(); if ($error) { switch ($error->type) { case 'CLOSED': { if (!$except) { $this->open(0, TRUE); $except = TRUE; return $this->fetchstructure($msgno); } else { throw new Exception($error->text); } } break; case 'WARNING': { //ignore. } break; default: { throw new Exception($error->text); } break; } } $except = FALSE; return $fetch; }
headerinfo | ( | $ | msgno | ) |
Get the header of the message.
$msgno |
|
Definition at line 449 of file imap.lib.
References error(), and open().
{ static $except = FALSE; $fetch = imap_headerinfo($this->mbres, $msgno); $error = $this->error(); if ($error) { switch ($error->type) { case 'CLOSED': { if (!$except) { $this->open(0, TRUE); $except = TRUE; return $this->headerinfo($msgno); } else { throw new Exception($error->text); } } break; case 'WARNING': { //ignore. } break; default: { throw new Exception($error->text); } break; } } $except = FALSE; return $fetch; }
list_headers | ( | $ | mbox_name | ) |
Get a list of all headers.
$mbox_name |
|
Definition at line 294 of file imap.lib.
References $check, and check_mbox().
{ $headers = array(); $this->check_mbox($mbox_name); $check = imap_check($this->mbres); $headers = imap_fetch_overview($this->mbres, "1:{$check->Nmsgs}", 0); return $headers; }
list_mbox | ( | $ | mbox | ) |
Get the mailbox information for the specified information with the status data infused.
$mbox |
|
Definition at line 625 of file imap.lib.
References $mbox.
Referenced by list_mboxes().
{ $mboxes = imap_getmailboxes($this->mbres, $this->mbconnstr, $mbox); if (count($mboxes) === 0) { return FALSE; } elseif (count($mboxes) > 1) { throw new Exception('Invalid mailbox specification.'); } $mbx =& $mboxes[0]; $status = imap_status($this->mbres, $this->mbconnstr . $mbox, SA_ALL); foreach ((array)$status as $key => $stat) { $mbx->$key = $stat; } return $mbx; }
list_mboxes | ( | ) |
Get a list of all mailboxes for the open connection.
Definition at line 647 of file imap.lib.
References $mbox, and list_mbox().
mime_type | ( | $ | structure | ) | [private] |
Determine the MIME type from the structure.
$structure |
|
Definition at line 808 of file imap.lib.
{ $primary_mime_types = array('TEXT', 'MULTIPART', 'MESSAGE', 'APPLICATION', 'AUDIO', 'IMAGE', 'VIDEO', 'OTHER'); if ($structure->subtype) { $mime_type = $primary_mime_types[$structure->type] . '/' . $structure->subtype; } else { $mime_type = "TEXT/PLAIN"; } return $mime_type; }
move_item | ( | $ | msgno, |
$ | to_folder | ||
) |
open | ( | $ | mode = 0 , |
$ | force = FALSE |
||
) |
Open the service.
$mode |
|
$force |
|
Definition at line 130 of file imap.lib.
References $mode, and error().
Referenced by bodystruct(), fetchheader(), fetchstructure(), and headerinfo().
{ if (!$this->mbconnstr) { $this->mbconnstr = '{' . $this->host . ':' . $this->port . $this->mbflags . '}'; } $user =& $this->mbuser['user']; $pass =& $this->mbuser['pass']; if ($this->mbreadonly) { $mode |= OP_READONLY; } if ($mode & OP_HALFOPEN) { $mb = NULL; } else { $mb = $this->mbox; } if (!$force && $this->mbres) { imap_reopen($this->mbres, $this->mbconnstr . $mb, $mode); $error = $this->error(); if ($error->type == 'CLOSED') { return $this->open($mode, TRUE); } } else { if ($force && !$mode) { $mode == $this->mode; } else { $this->mode = $mode; } $this->mbres = imap_open($this->mbconnstr . $mb, $user, $pass, $mode); } if ($errors = imap_errors()) { foreach ($errors as $error) { drupal_set_message($error, 'error'); } } return $this->mbres; }
part_decode | ( | $ | encoding, |
$ | text | ||
) | [private] |
Decode the encoded text.
$encoding |
|
$text |
|
Definition at line 783 of file imap.lib.
{ switch ($encoding) { case 3: { return imap_base64($text); } break; case 4: { return quoted_printable_decode($text); // This resolved and issue of NULL being returned with imap_qprint return imap_qprint($text); } break; default: { return $text; } break; } }
parts | ( | $ | structure, |
$ | msgno, | ||
$ | partno = FALSE |
||
) | [private] |
Get the parts of the email body.
$structure |
|
$msgno |
|
$partno |
|
Definition at line 724 of file imap.lib.
Referenced by fetch_item().
{ if ($structure) { $parts = array(); if (!$structure->parts) { if ($partno === FALSE) { $partno = '1'; } $body = imap_fetchbody($this->mbres, $msgno, $partno); $bodystruct = imap_bodystruct($this->mbres, $msgno, $partno); $body = $this->part_decode($bodystruct->encoding, $body); if ($bodystruct->ifparameters) { foreach ($bodystruct->parameters as $parameter) { if (strtolower($parameter->attribute) == 'charset') { $body = iconv($parameter->value, 'utf-8', $body); break; } } } $part = new stdClass; $part->partno = $partno; $part->mime_type = $this->mime_type($bodystruct); $part->text = $body; $part->bytes = $bodystruct->bytes; $part->subtype = $bodystruct->ifsubtype ? $bodystruct->subtype : NULL; $part->disposition = $bodystruct->ifdisposition ? $bodystruct->disposition : NULL; $part->dparameters = $bodystruct->ifdparameters ? $bodystruct->dparameters : NULL; $part->parameters = $bodystruct->ifparameters ? $bodystruct->parameters : NULL; $parts[$partno] = $part; } else { while (list($index, $substructure) = each($structure->parts)) { if ($partno) { $prefix = $partno . '.'; } else { $prefix = NULL; } $data = $this->parts($substructure, $msgno, $prefix . ($index + 1)); $parts += $data; } } return $parts; } return FALSE; }
status | ( | $ | mbox_name = NULL , |
$ | options = SA_ALL |
||
) |
Get status information for the mailbox.
$mbox_name |
|
$options |
|
Definition at line 225 of file imap.lib.
References $mbox, and check_mbox().
{ $this->check_mbox($mbox_name); $mbox = $this->mbconnstr . $this->mbox; return imap_status($this->mbres, $mbox, $options); }
$check = NULL [private] |
Definition at line 25 of file imap.lib.
Referenced by list_headers().
$host = 'localhost' [protected] |
Definition at line 12 of file imap.lib.
Referenced by __construct().
$mbox = NULL [protected] |
Definition at line 22 of file imap.lib.
Referenced by list_mbox(), list_mboxes(), and status().
$mbuser = array('user' => 'mbuser', 'pass' => 'mbpass') [protected] |
$port = 143 [protected] |
Definition at line 13 of file imap.lib.
Referenced by __construct().
$service = 'imap' [protected] |
Definition at line 14 of file imap.lib.
Referenced by __construct().