Skip to content

Commit ddd0045

Browse files
committed
Attachment::getMimeType() and Attachment::getExtension() added
1 parent 395ea5f commit ddd0045

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ $oFolder = $aMessage->getContainingFolder();
375375
| Method | Arguments | Return | Description |
376376
| -------------- | ------------------------------ | :------------: | ------------------------------------------------------ |
377377
| getContent | | string or null | Get attachment content |
378+
| getMimeType | | string or null | Get attachment mime type |
379+
| getExtension | | string or null | Get a guessed attachment extension |
378380
| getName | | string or null | Get attachment name |
379381
| getType | | string or null | Get attachment type |
380382
| getDisposition | | string or null | Get attachment disposition |

src/IMAP/Attachment.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Webklex\IMAP;
1414
use Illuminate\Support\Facades\File;
15+
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
1516

1617
/**
1718
* Class Attachment
@@ -233,4 +234,18 @@ public function getDisposition() {
233234
public function getImgSrc() {
234235
return $this->img_src;
235236
}
237+
238+
/**
239+
* @return string|null
240+
*/
241+
public function getMimeType(){
242+
return (new \finfo())->buffer($this->getContent(), FILEINFO_MIME_TYPE);
243+
}
244+
245+
/**
246+
* @return string|null
247+
*/
248+
public function getExtension(){
249+
return ExtensionGuesser::getInstance()->guess($this->getMimeType());
250+
}
236251
}

0 commit comments

Comments
 (0)