You are here

function MailhandlerCommandsFiles::process in Mailhandler 6.2

Same name and namespace in other branches
  1. 7.2 plugins/mailhandler/commands/MailhandlerCommandsFiles.class.php \MailhandlerCommandsFiles::process()

Parse attachments from message mimeparts.

Overrides MailhandlerCommands::process

File

plugins/mailhandler/commands/MailhandlerCommandsFiles.class.php, line 12
MailhandlerCommandsFiles class.

Class

MailhandlerCommandsFiles
@file MailhandlerCommandsFiles class.

Code

function process(&$message, $source) {
  $message['attachments'] = array();
  foreach ($message['mimeparts'] as $attachment) {

    // 'unnamed_attachment' files are not really attachments, but mimeparts like HTML or Plain Text.
    // We only want to save real attachments, like images and files.
    if ($attachment->filename !== 'unnamed_attachment') {
      $filename = mb_decode_mimeheader($attachment->filename);
      $file = file_save_data($attachment->data, file_directory_temp() . '/' . mb_decode_mimeheader($filename));
      $cid = NULL;
      if (!empty($attachment->id)) {
        $cid = trim($attachment->id, '<>');
      }
      $message['attachments'][] = new MailhandlerAttachmentEnclosure($filename, $attachment->filemime, $attachment->data, $cid);
    }
  }
  unset($message['mimeparts']);
}