Perhaps the problem lies in the fact this function is looking for a string! while
an e-mail message as understood by REBOL is an object! Changing the
word declaration for 'email from
email [string!]
to
email [object!]
doesn't solve the problem, however.
> detach: func [
> {takes in the whole email text and returns a block of filenames
> and decoded base64 attachments present in the email}
> email [string!]
> /local boundary body attached headers file
> ][
> print "starting decoding process..."
> headers: import-email email
> boundary: headers/content-type
> if boundary: find/tail boundary {boundary="} [
> remove back tail boundary
> print ["Boundary string:" boundary]
> ]
> either boundary [
> attached: make block! 2
> body: headers/content
> while [body: find/tail body boundary] [
> print ["Found message attachment; remaining length:" length?
> body] headers: parse-header system/standard/email skip body 1
> ; end of the message attachments? if find/match body "--"
> [print "attachents finished" break] file: copy/part
> headers/content find body: headers/content "^/--" either all [
> not error? try [headers/content-transfer-encoding]
> find headers/content-transfer-encoding "base64"
> ] [
> print "about to decode..."
> insert file "64#{" append file "}"
> print ["Adding attachment; encoded length:" length? file]
> seek: file while [seek: find seek "^/"] [remove seek]
> append attached reduce [find-filename headers to-string
> load file]
> ] [ ; not base64 encoded... just add it directly
> append attached reduce [find-filename headers file]
> ]
> ]
> attached
> ] [none]
> ]
>