class mime_mail in Backup and Migrate 7.3
Same name and namespace in other branches
- 8.2 includes/destinations.email.inc \mime_mail
- 8.3 includes/destinations.email.inc \mime_mail
- 6.3 includes/destinations.email.inc \mime_mail
- 6.2 includes/destinations.email.inc \mime_mail
- 7.2 includes/destinations.email.inc \mime_mail
Hierarchy
- class \mime_mail
Expanded class hierarchy of mime_mail
File
- includes/
destinations.email.inc, line 91 - Functions to handle the email backup destination.
View source
class mime_mail {
public $parts;
public $to;
public $from;
public $headers;
public $subject;
public $body;
/**
*
*/
public function __construct() {
$this->parts = array();
$this->to = "";
$this->from = "";
$this->headers = array();
$this->subject = "";
$this->body = "";
}
/**
*
*/
public function add_attachment($message, $name, $ctype) {
$this->parts[] = array(
"message" => $message,
"name" => $name,
"ctype" => $ctype,
);
}
/**
*
*/
public function build_message($part) {
$crlf = "\r\n";
// See RFC 2184.
$continuation = $crlf . ' ';
$name = $part['name'];
$len = strlen($name);
// RFC 5322 recommends lines of no longer than 78 chars, which in
// this case comes down to filenames of no longer than 64 chars.
if ($len > 64) {
// We want to preserve the time stamp and extension and such.
$head = substr($name, 0, 28);
$tail = substr($name, $len - 32);
$name = $head . '___' . $tail;
}
$message = chunk_split(base64_encode($part["message"]), 70, $crlf);
$disposition = $name ? "Content-Disposition: attachment; {$continuation}filename=\"{$name}\"{$crlf}" : "";
return "Content-Type: " . $part["ctype"] . ($name ? ";{$continuation}name=\"{$name}\"" : "") . "{$crlf}Content-Transfer-Encoding: base64{$crlf}{$disposition}{$crlf}{$message}";
}
/**
*
*/
public function build_multipart($boundary) {
$multipart = "This is a MIME encoded message.\r\n\r\n--{$boundary}";
for ($i = count($this->parts) - 1; $i >= 0; $i--) {
$multipart .= "\r\n" . $this
->build_message($this->parts[$i]) . "--{$boundary}";
}
return $multipart . "--\r\n";
}
/**
*
*/
public function send() {
$headers = array();
if (!empty($this->body)) {
$this
->add_attachment($this->body, "", "text/plain");
}
$headers['MIME-Version'] = "1.0";
$boundary = "b" . md5(uniqid(time()));
$headers['Content-Type'] = "multipart/mixed; boundary=\"{$boundary}\"";
$message = $this
->build_multipart($boundary);
$params = array();
$params['body'] = $message;
$params['headers'] = $headers;
$params['subject'] = $this->subject;
drupal_mail('backup_migrate', 'destination_mail', trim($this->to), '', $params, $this->from);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
mime_mail:: |
public | property | ||
mime_mail:: |
public | property | ||
mime_mail:: |
public | property | ||
mime_mail:: |
public | property | ||
mime_mail:: |
public | property | ||
mime_mail:: |
public | property | ||
mime_mail:: |
public | function | ||
mime_mail:: |
public | function | ||
mime_mail:: |
public | function | ||
mime_mail:: |
public | function | ||
mime_mail:: |
public | function |