Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-ASCII attachment filename decoding #33

Closed
wants to merge 1 commit into from

Conversation

pepamartinec
Copy link
Contributor

I had a problem downloading message parts with headers containing non-ASCII characters (attachment name/filename, to be exact).

Here is example part of received message:

--b1_21c078e69d0b21d50fd733085ceb8767
Content-Type: application/vnd.ms-excel; name="=?UTF-8?Q?Prost=C5=99eno=5F2014=5Fposledn=C3=AD_voln=C3=A9_term=C3=ADny.xls?="; charset="UTF-8"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="=?UTF-8?Q?Prost=C5=99eno=5F2014=5Fposledn=C3=AD_voln=C3=A9_term=C3=ADny.xls?="

0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAACAAAAwgAAAAAA
AAAAEAAA/v///wAAAAD+////AAAAAMAAAADBAAAA////////////////////////////////
...

This part gets decoded by imap_fetchstructure like this:

stdClass Object(
    [type] => 3
    [encoding] => 3
    [ifsubtype] => 1
    [subtype] => VND.MS-EXCEL
    [ifdescription] => 0
    [ifid] => 0
    [bytes] => 137524
    [ifdisposition] => 1
    [disposition] => ATTACHMENT
    [ifdparameters] => 1
    [dparameters] => Array(
        [0] => stdClass Object(
            [attribute] => FILENAME
            [value] => =?ISO-8859-2?Q?Prost=F8eno=5F2014=5Fposledn=ED_voln=E9_term=EDny.xls?=
        )
    )

    [ifparameters] => 1
    [parameters] => Array(
        [0] => stdClass Object(
            [attribute] => CHARSET
            [value] => UTF-8
        )
        [1] => stdClass Object(
            [attribute] => NAME
            [value] => =?ISO-8859-2?Q?Prost=F8eno=5F2014=5Fposledn=ED_voln=E9_term=EDny.xls?=
        )
    )
)

To get the original value, I need to apply imap_utf8 and imap_mime_header_decode functions. After that, a get the right filename Prostřeno_2014_poslední volné termíny.xls.

@ddeboer
Copy link
Owner

ddeboer commented Feb 1, 2015

Fixed via #70.

@ddeboer ddeboer closed this Feb 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants