Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

cid: protocol in email?

 [1/2] from: bry::itnisk::com at: 26-Nov-2002 10:12


I was wondering if anyone has ever done anything about using cid: inside email sent via rebol to create html formatted email and refer to images etc. I am asking as our content management system has a maillist generating module which allows you to choose to send html formatted or text formatted email, if I send html formatted I need to have the ability to include css stylesheets and images.

 [2/2] from: rebol-list2:seznam:cz at: 1-Dec-2002 0:51


Hello bryan, Tuesday, November 26, 2002, 10:12:53 AM, you wrote: b> I was wondering if anyone has ever done anything about using cid: inside b> email sent via rebol to create html formatted email and refer to images b> etc. b> I am asking as our content management system has a maillist generating b> module which allows you to choose to send html formatted or text b> formatted email, if I send html formatted I need to have the ability to b> include css stylesheets and images. Try this included script (I didn't test it yet so please do it and let me know if you will find some bugs) =( Oliva David )=======================( [oliva--david--seznam--cz] )== =( Earth/Europe/Czech_Republic/Brno )============================= =( coords: [lat: 49.22 long: 16.67] )============================= -- Attached file included as plaintext by Listar -- -- File: mail-page.r rebol [ title: "Page mailer" author: "Oldes" e-mail: [oliva--david--seznam--cz] version: 0.0.9 date: 1-Dec-2002/0:50:04+1:00 needs: [%qp-encode.r] purpose: {To be able send emails in the HTML format with included images} sponsored: {By nobody, but one Rebol/View/Pro licence would be appreciated} note: {This script was not tested so they may be some bugs, if you would need to include other image types then gifs and jpgs, you should enhance the block with mime-types in the get-type function. Hope you will not use it for spaming! This will now work only on local html files.} usage: { page-mailer/make-html-mail/sendit %ahoj.html [oliva--david--seznam--cz] ;with text version as well: page-mailer/make-html-mail/text/sendit %ahoj.html "Some text" [oliva--david--seznam--cz] ;with header: mhdr: make system/standard/email [from: {"Oldes" <[oliva--david--seznam--cz]>}] page-mailer/make-html-mail/header/sendit %ahoj.html mhdr [oliva--david--seznam--cz] ;send to .msg file: write/binary %test-html.msg page-mailer/form-msg page-mailer/make-html-mail %ahoj.html } ] page-mailer: context [ cids: 0 content-ids: boundaries: content-locs: none mailobj: htmldata: cid: none init: func[][ cids: 0 mailobj: cid: none content-ids: make block! [] content-locs: make block! [] boundaries: make block! [] ] get-content-id: func[file][ cids: cids + 1 if none? cid: select content-ids file [ cid: rejoin ["id" cids "@" system/network/host] insert content-ids reduce [file cid] ] cid ] get-content-location: func[file][ if none? cid: select content-locs file [ cids: cids + 1 cid: file ;rejoin [ cids "_" file] insert content-locs reduce [file cid] ] cid ] get-boundary: func[/local b][ while [ found? find boundaries b: rejoin ["--__REBOL--" system/version "--" checksum form now/precise "__"] ][] insert boundaries copy b return b ] get-type: func[file][ select [ "gif" "image/gif" "jpg" "image/jpg" ;"swf" "application/x-shockwave-flash" "html" "text/html" ] last parse file "." ] html: none form-msg: func[mail][ rejoin [ {Return-Path: <} mail/return-path {>} CRLF ;{Delivered-To: } mail/to "^/" {Message-Id: <} mail/message-id {>} CRLF {Date: } to-idate now CRLF {From: } mail/from CRLF {Mime-Version: 1.0} CRLF {To: } mail/to CRLF {Subject: } mail/subject CRLF {Content-Type: } mail/content-type CRLF either any [ error? try [mail/Encoding] none? mail/Encoding ][""][ rejoin [{Content-Transfer-Encoding: } mail/Encoding CRLF ] ] CRLF mail/content CRLF ] ] break-lines: func [mesg data /at num] [ num: any [num 72] while [not tail? data] [ append mesg join copy/part data num CRLF data: skip data num ] mesg ] to-base64: func[bin /local buff][ buff: enbase/base bin 64 while [not tail? buff][ buff: skip buff 72 insert buff CRLF buff: skip buff 2 ] head buff ] urlchars: charset [#"a" - #"z" #"A" - #"Z" #"0" - #"9" "?/\:&;#%~+-_.*="] form-html-content: func[ page [file! url! string!] /chrset chrst /local x y url html-tags html tmphtml rfile geturl-rule ][ html: make string! 10000 tmphtml: make string! 10000 if not chrset [chrst: "US-ASCII"] html-tags: load/markup page geturl-rule: [opt [{"} (append x {"}) | {'} (append x {'})] copy url any [urlchars] y: to end] foreach tag html-tags [ if all [ tag? tag parse tag [ "img" copy x thru {src=} geturl-rule (tag-name: "img") | "body" copy x thru {background=} geturl-rule (tag-name: "BODY") | "link" copy x thru {href=} geturl-rule ( tag-name: "style" tag: rejoin [{<style><!--^/} read to-file url {^/--></style>}] ) ] ][ if tag? tag [ ;probe url if not none? get-type url [ tag: to-tag rejoin [tag-name x get-content-location url y] ] ] ] append tmphtml tag ] html: qp-encode tmphtml insert html rejoin [ {Content-Type: text/html; charset=} chrst CRLF {Content-Transfer-Encoding: quoted-printable} CRLF ;{Content-Transfer-Encoding: base64} CRLF CRLF ] if cids > 0 [ get-boundary insert html rejoin [ {Content-Type: multipart/related; boundary="} skip boundaries/1 2 {"} CRLF CRLF boundaries/1 CRLF ] foreach [file cid] content-locs [ rfile: file parse file [ copy d 1 skip ":\" copy r to end (rfile: rejoin ["/" d "/" r]) ] append html rejoin [ CRLF boundaries/1 CRLF {Content-Type: } get-type file CRLF {Content-Location: } cid CRLF ;{Content-Id: <} cid {>} CRLF {Content-Transfer-Encoding: base64} CRLF {Content-Disposition: inline; filename="} file {"} CRLF CRLF ] break-lines html enbase read/binary to-file rfile ] append html rejoin [CRLF boundaries/1 "--" CRLF] remove boundaries ] html ] make-html-mail: func[ html-file /header hdr /subject subj /charset chrst /text msg /sendit adress [email! block!] ][ init htmldata: read html-file if not charset [chrst: "US-ASCII"] if not subject [parse htmldata [thru "<title>" copy subj to {</title>}]] get-boundary mailobj: make either header [hdr][system/standard/email] [ subject: subj MIME-Version: "1.0" content-type: rejoin [{multipart/alternative; boundary="} skip boundaries/1 2 {"}] content: rejoin [ boundaries/1 CRLF either text [ replace/all msg newline CRLF rejoin [ {Content-Type: text/plain; charset=} chrst CRLF ;{Content-Transfer-Encoding: quoted-printable} CRLF ;CRLF qp-encode msg CRLF CRLF msg CRLF ] ][""] boundaries/1 CRLF form-html-content/chrset htmldata chrst CRLF boundaries/1 "--" ] ] if sendit [ send/header adress mailobj/content mailobj ] mailobj ] ] -- Attached file included as plaintext by Listar -- -- File: qp-encode.r rebol [ title: "quoted-printable encoder" purpose: {Encodes the string data to quoted-printable format} author: "Oldes" email: [oliva--david--seznam--cz] date: 20-Jun-2002/13:16:03+2:00 version: 1.0.0 usage: {
>> qp-encode "nejzajímavější"
== "nejzaj=EDmav=ECj=9A=ED"} comment: {More info about this encoding: http://www.faqs.org/rfcs/rfc2045.html} ] qp-encode: func[ "Encodes the string data to quoted-printable format" str [any-string!] "string to encode" /local c h l r normal rest ][ l: 0 r: 0 normal: charset [#"!" - #"<" #">" - #"~" #" "] rest: complement normal parse/all copy str [ any [ h: [ ( r: (index? h) - l ) normal ( ;non encoded characters if r = 76 [h: insert h "=^M^/" l: -1 + index? h] ) | copy c rest ( remove h if r >= 74 [h: insert h "=^M^/" l: -1 + index? h] insert h join #"=" copy/part skip mold to binary! c 2 2 ) 2 skip ] :h skip ] ] head h ]