예제 #1
0
 function textBody()
 {
     if ($this->altBody) {
         return $this->altBody;
     }
     $h2t = new Html2Text($this->getBody());
     return $h2t->get_text();
 }
예제 #2
0
 /**
  * Formats a message composed by drupal_mail().
  *
  * @see http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7
  *
  * @param array $message
  *   A message array holding all relevant details for the message.
  *
  * @return string
  *   The message as it should be sent.
  */
 public function format(array $message)
 {
     // Get default mail line endings and merge all lines in the e-mail body
     // separated by the mail line endings.
     $line_endings = Settings::get('mail_line_endings', PHP_EOL);
     $message['body'] = SafeMarkup::set(implode($line_endings, $message['body']));
     // Get applicable format.
     $applicable_format = $this->getApplicableFormat($message);
     // Theme message if format is set to be HTML.
     if ($applicable_format == SWIFTMAILER_FORMAT_HTML) {
         $render = array('#theme' => isset($message['params']['theme']) ? $message['params']['theme'] : 'swiftmailer', '#message' => $message);
         $message['body'] = $this->renderer->renderRoot($render);
         if ($this->config['message']['convert_mode'] || !empty($message['params']['convert'])) {
             $converter = new Html2Text($message['body']);
             $message['plain'] = $converter->get_text();
         }
     }
     // Process any images specified by 'image:' which are to be added later
     // in the process. All we do here is to alter the message so that image
     // paths are replaced with cid's. Each image gets added to the array
     // which keeps track of which images to embed in the e-mail.
     $embeddable_images = array();
     preg_match_all('/"image:([^"]+)"/', $message['body'], $embeddable_images);
     for ($i = 0; $i < count($embeddable_images[0]); $i++) {
         $image_id = $embeddable_images[0][$i];
         $image_path = trim($embeddable_images[1][$i]);
         $image_name = basename($image_path);
         if (Unicode::substr($image_path, 0, 1) == '/') {
             $image_path = Unicode::substr($image_path, 1);
         }
         $image = new stdClass();
         $image->uri = $image_path;
         $image->filename = $image_name;
         $image->filemime = file_get_mimetype($image_path);
         $image->cid = rand(0, 9999999999.0);
         $message['params']['images'][] = $image;
         $message['body'] = preg_replace($image_id, 'cid:' . $image->cid, $message['body']);
     }
     return $message;
 }
예제 #3
0
 protected function getText($source = false)
 {
     $source = new Html2Text($source);
     return $source->get_text();
 }
예제 #4
0
 private function multipartMessage($htmlpart, $boundary)
 {
     if ($this->altBody == "") {
         $h2t = new Html2Text($htmlpart);
         $this->altBody = $h2t->get_text();
         //$this->altBody = strip_tags ( $htmlpart, '<br>' );
         //$this->altBody = str_replace(array("\r\n","\n","\t"),' ', $this->altBody);
         //$this->altBody = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $this->altBody);
     }
     $altBoundary = $this->generateBoundary();
     ob_start();
     // Turn on output buffering
     $parts = "This is a multi-part message in MIME format." . $this->newline . $this->newline;
     $parts .= "--" . $boundary . $this->newline;
     $parts .= "Content-Type: multipart/alternative;" . $this->newline;
     $parts .= "    boundary=\"{$altBoundary}\"" . $this->newline . $this->newline;
     $parts .= "--" . $altBoundary . $this->newline;
     $parts .= "Content-Type: text/html; charset={$this->charset}" . $this->newline;
     $parts .= "Content-Transfer-Encoding: {$this->transferEncodeing}" . $this->newline . $this->newline;
     $parts .= $htmlpart . $this->newline . $this->newline;
     $parts .= "--" . $altBoundary . $this->newline;
     $parts .= "Content-Type: text/plain; charset={$this->charset}" . $this->newline;
     $parts .= "Content-Transfer-Encoding: {$this->transferEncodeing}" . $this->newline . $this->newline;
     $parts .= $this->altBody . $this->newline . $this->newline;
     $parts .= "--" . $altBoundary . "--" . $this->newline . $this->newline;
     if (count($this->attachments) > 0) {
         for ($i = 0; $i < count($this->attachments); $i++) {
             $attachment = chunk_split(base64_encode(file_get_contents($this->attachments[$i])));
             $filename = basename($this->attachments[$i]);
             $ext = pathinfo($filename, PATHINFO_EXTENSION);
             $parts .= "--" . $boundary . $this->newline;
             $parts .= "Content-Type: application/{$ext}; name=\"{$filename}\"" . $this->newline;
             $parts .= "Content-Transfer-Encoding: base64" . $this->newline;
             $parts .= "Content-Disposition: attachment; filename=\"{$filename}\"" . $this->newline . $this->newline;
             $parts .= $attachment . $this->newline;
         }
     }
     $parts .= "--" . $boundary . "--";
     return $parts;
 }