You are here

class MailhandlerAttachmentEnclosure in Mailhandler 6.2

Same name and namespace in other branches
  1. 7.2 plugins/mailhandler/commands/MailhandlerCommandsFiles.class.php \MailhandlerAttachmentEnclosure

Attachment enclosure, can be part of the result array.

Hierarchy

Expanded class hierarchy of MailhandlerAttachmentEnclosure

File

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

View source
class MailhandlerAttachmentEnclosure extends FeedsEnclosure {

  /**
   * The Content-ID.
   *
   * @var string
   */
  protected $cid;

  /**
   * The file content.
   *
   * @var string
   */
  protected $data;

  /**
   * Constructs an attachment enclosure.
   *
   * @param string $filename
   *   The file name.
   * @param string $mime_type
   *   The mime type.
   * @param string $data
   *   The file content.
   * @param string $cid
   *   (optional) The Content-ID.
   */
  public function __construct($filename, $mime_type, $data, $cid = NULL) {
    parent::__construct($filename, $mime_type);
    $this->data = $data;
    $this->cid = $cid;
  }

  /**
   * Get the Content-ID.
   *
   * @return string
   *   The Content-ID or NULL if it is not defined.
   */
  public function getContentId() {
    return $this->cid;
  }

  /**
   * Get the file content.
   *
   * @return string
   *   The file content.
   */
  public function getContent() {
    return $this->data;
  }

  /**
   * {@inheritdoc}
   *
   * Save the attachment data the same way as the parent class for remote files.
   */
  public function getFile($destination, $replace = FILE_EXISTS_RENAME) {
    $file = FALSE;
    if ($this
      ->getValue()) {

      // Prepare destination directory.
      file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);
      try {
        $filename = $this
          ->getLocalValue();
        if (module_exists('transliteration')) {
          require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
          $filename = transliteration_clean_filename($filename);
        }
        $file = file_save_data($this
          ->getContent(), $destination . $filename, $replace);
      } catch (Exception $e) {
        watchdog_exception('Feeds', $e, nl2br(check_plain($e)));
      }

      // We couldn't make sense of this enclosure, throw an exception.
      if (!$file) {
        throw new Exception(t('Invalid enclosure %enclosure', array(
          '%enclosure' => $this
            ->getValue(),
        )));
      }
      return $file;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedsElement::$value protected property
FeedsElement::getValue public function @todo Make value public and deprecate use of getValue(). 3
FeedsElement::__toString public function 1
FeedsEnclosure::$delete_file protected property Delete flag, denoting whether a file should be deleted when this object is destroyed.
FeedsEnclosure::$file protected property
FeedsEnclosure::$mime_type protected property
FeedsEnclosure::getMIMEType public function 1
FeedsEnclosure::__destruct public function Destructor, clean up any temporary files.
MailhandlerAttachmentEnclosure::$cid protected property The Content-ID.
MailhandlerAttachmentEnclosure::$data protected property The file content.
MailhandlerAttachmentEnclosure::getContent public function Get the file content. Overrides FeedsEnclosure::getContent
MailhandlerAttachmentEnclosure::getContentId public function Get the Content-ID.
MailhandlerAttachmentEnclosure::getFile public function Save the attachment data the same way as the parent class for remote files. Overrides FeedsEnclosure::getFile
MailhandlerAttachmentEnclosure::__construct public function Constructs an attachment enclosure. Overrides FeedsEnclosure::__construct