Hi,

I don't know how helpful it will be, but here's the function I use for
detaching attachments. It only works for four types of encoding (the type has
to be specified), and only for attachments that have an associated file
name, but it's a pretty simple and general solution, I think. All the
attachments it can handle will be written into the current directory. If
the same file name appears more than once the first one will be overwritten.

Eric


det: func [
    {takes a file and writes included MIME attachments to their
    named files}
    f [file!]
    /local lines data name boundary encoding ptr ptr2 hex-digits byte
][
    hex-digits: make bitset! [#"0" - #"9" #"A" - #"F"]
    lines: read f
    parse lines [ any [
        thru "^/--"
        copy boundary to "^/" "^/"
        [
            {Content-Type:}
            thru {name="}
            copy name to {"} {"}
            thru {Content-Transfer-Encoding:}
            any " "
            copy encoding to "^/"
            thru "^/^/"
            copy data to boundary
            ptr:
            (
                (print copy/part data 20)
                print [name encoding boundary length? data index? ptr]
                ptr: skip ptr -4
                clear skip tail data -2
                switch encoding [
                    {base64} [write/binary to file! name debase/base data 64]
                    {quoted-printable} [
                        ptr2: data
                        while [ ptr2: find ptr2 "="] [
                            either parse ptr2 [
                                "=" copy byte 2 hex-digits to end
                            ][
                                remove/part ptr2 3
                                ptr2: insert ptr2 dehex join "%" byte
                            ][ remove/part ptr2 2]

                        ]
                        write to file! name data
                    ]
                    {7bit} [write to file! name data]
                    {8bit} [write/binary to file! name data]
                ]
            ptr: ptr) :ptr |
            none
        ]
    ] ]
]

Reply via email to