Skip to content
Snippets Groups Projects
Commit fb8a4bf6 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge remote branch 'upstream/develop' into develop-next

parents d3b0a944 3299278d
No related branches found
No related tags found
No related merge requests found
......@@ -399,8 +399,17 @@ class MailFetcher {
return $header;
}
function fetchBody($mid, $index, $encoding) {
$body = imap_fetchbody($this->mbox, $mid, $index);
if ($body && $encoding)
$body = $this->decode($body, $encoding);
return $body;
}
//search for specific mime type parts....encoding is the desired encoding.
function getPart($mid, $mimeType, $encoding=false, $struct=null, $partNumber=false, $recurse=-1, $recurseIntoRfc822=true) {
function getPart($mid, $mimeType, $encoding=false, $struct=null,
$partNumber=false, $recurse=-1, $recurseIntoRfc822=false) {
if(!$struct && $mid)
$struct=@imap_fetchstructure($this->mbox, $mid);
......@@ -490,8 +499,9 @@ class MailFetcher {
*/
function getAttachments($part, $index=0) {
if($part && !$part->parts) {
$ctype = $part ? $this->getMimeType($part) : false;
if($part && (!$part->parts
|| strcasecmp($ctype, 'message/rfc822') === 0)) {
//Check if the part is an attachment.
$filename = false;
if ($part->ifdisposition && $part->ifdparameters
......@@ -516,6 +526,12 @@ class MailFetcher {
$filename = _S('image').'-'.Misc::randCode(4).'.'.strtolower($part->subtype);
}
// Attached message/rfc822 without filename.
if (!$filename
&& $ctype
&& strcasecmp($ctype, 'message/rfc822') === 0)
$filename = 'email-message-'.Misc::randCode(4).'.eml';
if($filename) {
return array(
array(
......@@ -673,11 +689,13 @@ class MailFetcher {
return true; //Report success (moved or delete)
}
// Parse MS TNEF emails
// Process overloaded attachments
if (($struct = imap_fetchstructure($this->mbox, $mid))
&& ($attachments = $this->getAttachments($struct))) {
foreach ($attachments as $i=>$info) {
if (0 === strcasecmp('application/ms-tnef', $info['type'])) {
switch (strtolower($info['type'])) {
// Parse MS TNEF emails
case 'application/ms-tnef':
try {
$data = $this->decode(imap_fetchbody($this->mbox,
$mid, $info['index']), $info['encoding']);
......@@ -690,6 +708,26 @@ class MailFetcher {
} catch (TnefException $ex) {
// Noop -- winmail.dat remains an attachment
}
break;
// Parse attached email message
case 'message/rfc822':
try {
// Fetch the header of attached mime message.
$body = $this->fetchBody($mid, $info['index'].'.0',
$info['encoding']);
// Add fake body to make the parser happy
if ($body)
$body.="\n\nJunk";
$parser = new Mail_Parse($body);
if ($parser->decode()
&& ($subj = $parser->getSubject()))
$attachments[$i]['name'] = $subj.'.eml';
} catch(Exception $ex) {
// Noop -- use random name
}
$body = $parser = null;
break;
}
}
}
......@@ -948,7 +986,8 @@ class MailFetcher {
db_query('UPDATE '.EMAIL_TABLE.' SET mail_errors=mail_errors+1, mail_lasterror=NOW() WHERE email_id='.db_input($emailId));
if (++$errors>=$MAXERRORS) {
//We've reached the MAX consecutive errors...will attempt logins at delayed intervals
$msg="\n"._S('osTicket is having trouble fetching emails from the following mail account').": \n".
// XXX: Translate me
$msg="\nosTicket is having trouble fetching emails from the following mail account: \n".
"\n"._S('User').": ".$fetcher->getUsername().
"\n"._S('Host').": ".$fetcher->getHost().
"\n"._S('Error').": ".$fetcher->getLastError().
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment