Skip to content

Commit 6e1716d

Browse files
committed
Decoder config options added #175
1 parent 01984b1 commit 6e1716d

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/IMAP/Attachment.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Attachment {
2525
/** @var Message $oMessage */
2626
protected $oMessage;
2727

28+
/** @var array $config */
29+
protected $config = [];
30+
2831
/** @var object $structure */
2932
protected $structure;
3033

@@ -85,6 +88,8 @@ class Attachment {
8588
* @throws Exceptions\ConnectionFailedException
8689
*/
8790
public function __construct(Message $oMessage, $structure, $part_number = 1) {
91+
$this->config = config('imap.options');
92+
8893
$this->oMessage = $oMessage;
8994
$this->structure = $structure;
9095
$this->part_number = ($part_number) ? $part_number : $this->part_number;
@@ -226,7 +231,11 @@ public function getId() {
226231
* @param $name
227232
*/
228233
public function setName($name) {
229-
$this->name = mb_decode_mimeheader($name);
234+
if($this->config['decoder']['message']['subject'] === 'utf-8') {
235+
$this->name = imap_utf8($name);
236+
}else{
237+
$this->name = mb_decode_mimeheader($name);
238+
}
230239
}
231240

232241
/**

src/IMAP/Message.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class Message {
3131
*/
3232
private $client = Client::class;
3333

34+
/** @var array $config */
35+
protected $config = [];
36+
3437
/**
3538
* U ID
3639
*
@@ -174,8 +177,12 @@ class Message {
174177
* @param boolean $fetch_flags
175178
*
176179
* @throws Exceptions\ConnectionFailedException
180+
* @throws InvalidMessageDateException
177181
*/
178182
public function __construct($uid, $msglist, Client $client, $fetch_options = null, $fetch_body = false, $fetch_attachment = false, $fetch_flags = false) {
183+
184+
$this->config = config('imap.options');
185+
179186
$this->setFetchOption($fetch_options);
180187
$this->setFetchBodyOption($fetch_body);
181188
$this->setFetchAttachmentOption($fetch_attachment);
@@ -320,7 +327,11 @@ private function parseHeader() {
320327
}
321328

322329
if (property_exists($header, 'subject')) {
323-
$this->subject = mb_decode_mimeheader($header->subject);
330+
if($this->config['decoder']['message']['subject'] === 'utf-8') {
331+
$this->subject = imap_utf8($header->subject);
332+
}else{
333+
$this->subject = mb_decode_mimeheader($header->subject);
334+
}
324335
}
325336
if (property_exists($header, 'from')) {
326337
$this->from = $this->parseAddresses($header->from);

src/config/imap.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
| error: "Kerberos error: No credentials cache
9999
| file found (try running kinit) (...)"
100100
| or ['GSSAPI','PLAIN'] if you are using outlook mail
101+
| -Decoder options (currently only the message subject and attachment name decoder can be set)
102+
| 'utf-8' - Uses imap_utf8($string) to decode a string
103+
| 'mimeheader' - Uses mb_decode_mimeheader($string) to decode a string
101104
|
102105
*/
103106
'options' => [
@@ -110,6 +113,14 @@
110113
'fetch_order' => 'asc',
111114
'open' => [
112115
// 'DISABLE_AUTHENTICATOR' => 'GSSAPI'
116+
],
117+
'decoder' => [
118+
'message' => [
119+
'subject' => 'utf-8' // mimeheader
120+
],
121+
'attachment' => [
122+
'name' => 'utf-8' // mimeheader
123+
]
113124
]
114125
]
115126
];

0 commit comments

Comments
 (0)