This now works (with .jpg images, at least)...


detach-image: func [
        "detach an image file from the contents of an email"
        email-contents [string!] "the content of an email"
][
        image-code: make string! 100000
        
        if find/any email-contents {image/jpeg} [
                parse/all email-contents [thru {base64^/^/} copy text thru {==} 
(append image-code text)]
        ]

        display-this: image-code
]


>>img: detach-image msg/content

>>write/binary %img.jpg debase img



Thanks for all of the help. Now for further testing with GIFs, etc.

-Ryan

> Hi Ryan
> 
> Here's the answer.  Do not add the "64{" and "}", just use DEBASE/BASE 
> Your TEXT  var is already a string! datatype.  Look at this:
> 
> >> bin: read/binary %bay.jpg
> == #{
> FFD8FFE000104A46494600010101004800480000FFDB00430008060607060508
> 0707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E...
> 
> >> bin64: enbase/base bin 64
> ==
> {/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofH
> h0 aH BwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQk...
> 
> >> write/binary %test.jpg debase/base bin64 64
> 
> The JPG is restored.  I e-mailed myself bay.jpg as an attachment using
> base64 encoding,  read my pop mail box into a file,  extracted the base64
> image with a text editor and it was exactly the same as BIN64 above.
> 
> HTH
> 
> Larry
> 
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, June 12, 2000 1:38 PM
> Subject: [REBOL] detach-image: func (was: %detach.r Re:(4))
> 
> 
> > Here is where I'm at...
> >
> >
> > detach-image: func [
> > "detach an image file from the contents of an email"
> > email-contents [string!] "the content of an email"
> > ][
> > image-code: copy []
> >
> > if find/any email-contents {image/jpeg} [
> > parse/all email-contents [thru {base64^/^/} copy text to {==} (append
> > image-code text)]
> > ]
> >
> > insert image-code "64#{" append image-code "}"
> > ]
> >
> >
> > >>img: detach-image msg/content
> >
> > >>write/binary %img.jpg img
> >
> > Still does not display an image in a browser and is unreadable by an
> > image viewer.
> >
> > -Ryan
> >
> 


Reply via email to