creecros / Mailmagik

Kanboard Plugin - Send emails to Kanboard and convert to tasks or comments
MIT License
22 stars 2 forks source link

Error/Exception when fetching mails from Exchange server #41

Closed einhirn closed 4 weeks ago

einhirn commented 6 months ago

When trying to deploy this plugin we ran into Internal Error: Could not search mailbox!

After some jiggery-pokery we arrived at the relevant info, dumping the exception. This gave us

           [message:protected] => IMAP method imap_search() failed with error: [BADCHARSET (US-ASCII)] The specified charset is not supported.

which led us to the following part of php-imap

    /**
     * This function uses imap_search() to perform a search on the mailbox currently opened in the given IMAP stream.
     * For example, to match all unanswered mails sent by Mom, you'd use: "UNANSWERED FROM mom".
     *
     * @param string $criteria              See http://php.net/imap_search for a complete list of available criteria
     * @param bool   $disableServerEncoding Disables server encoding while searching for mails (can be useful on Exchange servers)
     *
     * @return int[] mailsIds (or empty array)
     *
     * @psalm-return list<int>
     */
    public function searchMailbox(string $criteria = 'ALL', bool $disableServerEncoding = false): array
    {

the relevant part being Disables server encoding while searching for mails (can be useful on Exchange servers). We applied this to https://github.com/creecros/Mailmagik/blob/15013ff4d79e6fb8b3a15f7e0d01ab06cc080145/Helper/MailHelper.php#L152 by adding a ,true after $filter and this fixed the issue.

I don't know if there's a way to auto detect it or whether to disable it by default or make it configurable, but here it is.

einhirn commented 6 months ago

Another Issue we ran into with our Exchange server was that we couldn't get this to work with "To" parsing - the header line sure was correct, but I guess that Exchange IMAP doesn't care about that line so much as to return some generic name/line for the mailbox's email-address... Since it worked with "Subject"-Parsing, which seemed more easily accessible anyway, I didn't debug this thing further and didn't want to open another Issue for that.

alfredbuehler commented 1 month ago

The upcoming release will have a config option to select the server encoding.

alfredbuehler commented 4 weeks ago

Solved by 1.4.0