Rebol 编程/build-attach-body
外观
< Rebol 编程
BUILD-ATTACH-BODY body files boundary
返回一个带有附件文件的电子邮件正文。
BUILD-ATTACH-BODY 是一个函数值。
- body -- 消息正文(类型:字符串)
- files -- 要发送的文件列表 [%file1.r [%file2.r "data"]](类型:块)
- boundary -- 边界分隔符(类型:字符串)
build-attach-body: func [
"Return an email body with attached files."
body [string!] "The message body"
files [block!] {List of files to send [%file1.r [%file2.r "data"]]}
boundary [string!] "The boundary divider" /local
make-mime-header
break-lines
file
val
][
make-mime-header: func [file] [
net-utils/export context [
Content-Type: join {application/octet-stream; name="} [file {"}]
Content-Transfer-Encoding: "base64"
Content-Disposition: join {attachment; filename="} [file {"
}]
]
]
break-lines: func [mesg data /at num] [
num: any [num 72]
while [not tail? data] [
append mesg join copy/part data num #"^/"
data: skip data num
]
mesg
]
if not empty? files [
insert body reduce [boundary "^/Content-type: text/plain^/^/"]
append body "^/^/"
if not parse files [
some [
(file: none)
[
set file file! (val: read/binary file)
| into [
set file file!
set val skip
to end
]
] (
if file [
repend body [
boundary "^/"
make-mime-header any [find/last/tail file #"/" file]
]
val: either any-string? val [val] [mold :val]
break-lines body enbase val
]
)
]
] [net-error "Cannot parse file list."]
append body join boundary "--^/"
]
body
]