Skip to content

Commit

Permalink
Fixed parsing internal links (thanks to @Kethryweryn)
Browse files Browse the repository at this point in the history
 Closes #24
  • Loading branch information
barbushin committed May 6, 2015
1 parent be8571f commit e7e65de
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/PhpImap/IncomingMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ public function getAttachments() {
* @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();
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) {
$fetchedHtml = str_replace($placeholder, $baseUri . basename($this->attachments[$attachmentId]->filePath), $fetchedHtml);
if(isset($this->attachments[$attachmentId])) {
$fetchedHtml = str_replace($placeholder, $baseUri . basename($this->attachments[$attachmentId]->filePath), $fetchedHtml);
}
}
return $fetchedHtml;
}
Expand Down

0 comments on commit e7e65de

Please sign in to comment.