forked from barbushin/php-imap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IncomingMail.php
66 lines (53 loc) · 1.52 KB
/
IncomingMail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php namespace PhpImap;
/**
* @see https://github.com/barbushin/php-imap
* @author Barbushin Sergey http://linkedin.com/in/barbushin
*/
class IncomingMail {
public $id;
public $date;
public $subject;
public $fromName;
public $fromAddress;
public $to = array();
public $toString;
public $cc = array();
public $replyTo = array();
public $messageId;
public $textPlain;
public $textHtml;
/** @var IncomingMailAttachment[] */
protected $attachments = array();
public function addAttachment(IncomingMailAttachment $attachment) {
$this->attachments[$attachment->id] = $attachment;
}
/**
* @return IncomingMailAttachment[]
*/
public function getAttachments() {
return $this->attachments;
}
/**
* Get array of internal HTML links placeholders
* @return array attachmentId => link placeholder
*/
public function getInternalLinksPlaceholders() {
return preg_match_all('/=["\'](ci?d:([\w\.%*@-]+))["\']/i', $this->textHtml, $matches) ? array_combine($matches[2], $matches[1]) : array();
}
public function replaceInternalLinks($baseUri) {
$baseUri = rtrim($baseUri, '\\/') . '/';
$fetchedHtml = $this->textHtml;
foreach($this->getInternalLinksPlaceholders() as $attachmentId => $placeholder) {
if(isset($this->attachments[$attachmentId])) {
$fetchedHtml = str_replace($placeholder, $baseUri . basename($this->attachments[$attachmentId]->filePath), $fetchedHtml);
}
}
return $fetchedHtml;
}
}
class IncomingMailAttachment {
public $id;
public $name;
public $filePath;
public $disposition;
}