added an option to restore message as rfc822 attachment

This commit is contained in:
SJ 2014-01-05 22:47:47 +01:00
parent 35aeb0463b
commit 0517c131b0
4 changed files with 59 additions and 4 deletions

View File

@ -139,6 +139,7 @@ $config['SEARCH_RESULT_CHECKBOX_CHECKED'] = 0;
$config['HELPER_URL'] = '';
$config['ENABLE_SYSLOG'] = 1;
$config['REWRITE_MESSAGE_ID'] = 0;
$config['RESTORE_EMAILS_AS_ATTACHMENT'] = 0;
$config['RESTRICTED_AUDITOR'] = 0;
$config['SHOW_ENVELOPE_JOURNAL'] = 0;

View File

@ -90,8 +90,15 @@ class ControllerMessageBulkrestore extends Controller {
}
else {
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt,
"Received: by piler" . EOL . PILER_HEADER_FIELD . $id . EOL . $msg );
if(RESTORE_EMAILS_AS_ATTACHMENT == 1) {
$msg = $this->model_mail_mail->message_as_rfc822_attachment($piler_id, $msg, $rcpt[0]);
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt, $msg);
}
else {
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt,
"Received: by piler" . EOL . PILER_HEADER_FIELD . $id . EOL . $msg );
}
}
if($x == 1) { $this->data['restored']++; }

View File

@ -82,8 +82,15 @@ class ControllerMessageRestore extends Controller {
}
else {
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt,
"Received: by piler" . EOL . PILER_HEADER_FIELD . $this->data['id'] . EOL . $msg );
if(RESTORE_EMAILS_AS_ATTACHMENT == 1) {
$msg = $this->model_mail_mail->message_as_rfc822_attachment($this->data['id'], $msg, $rcpt[0]);
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt, $msg);
}
else {
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt,
"Received: by piler" . EOL . PILER_HEADER_FIELD . $this->data['id'] . EOL . $msg );
}
}
if($x == 1) { $this->data['data'] = $this->data['text_restored']; }

View File

@ -51,6 +51,46 @@ class ModelMailMail extends Model {
}
public function message_as_rfc822_attachment($piler_id = '', $msg = '', $rcpt = '') {
if($piler_id == '' || $msg == '' || $rcpt == '') { return ''; }
$boundary = generate_random_string(24);
$hdr = substr($msg, 0, 8192);
$subject = "";
$s = strstr($hdr, "Subject:");
if($s) {
$l1 = strlen($s);
$l2 = strlen(strstr($s, "\n"));
if($l1 > $l2 + 10) {
$subject = substr($s, 0, $l1 - $l2) . EOL;
}
}
$s = "";
$s .= "Received: by piler" . EOL . PILER_HEADER_FIELD . $piler_id . EOL;
$s .= "Date: " . date("r") . EOL;
$s .= "Message-ID: <" . generate_random_string(25) . '@' . SITE_NAME . ">" . EOL;
$s .= "From: " . SMTP_FROMADDR . EOL;
$s .= "To: " . $rcpt . EOL;
if($subject) { $s .= $subject; }
else { $s .= "Subject: Retrieved message from the email archive" . EOL; }
$s .= "MIME-Version: 1.0" . EOL;
$s .= "Content-Type: multipart/mixed; boundary=\"$boundary\"" . EOL . EOL . EOL;
$s .= "--$boundary" . EOL;
$s .= "Content-Type: message/rfc822; name=\"" . $piler_id . "\"" . EOL;
$s .= "Content-Disposition: attachment; filename=\"" . $piler_id . "\"" . EOL . EOL;
$s .= $msg . EOL;
$s .= "--$boundary" . EOL;
return $s;
}
public function connect_imap() {
$this->imap = new Zend_Mail_Protocol_Imap(IMAP_HOST, IMAP_PORT, IMAP_SSL);