diff options
author | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
---|---|---|
committer | Caleb Maclennan <caleb@alerque.com> | 2023-11-10 09:12:04 +0300 |
commit | 5c4fc93d5f4137bf4c22ddf1a048c907a4a26727 (patch) | |
tree | a9a68e1f6a9c3bfe2b64fa1c3a4098865b7d3b5d /samples/qp.lua | |
parent | ccef3bc4e2aa6ee5b997a80aabb58f4ff0b0e98f (diff) | |
parent | 43a97b7f0053313b43906371dbdc226271e6c8ab (diff) | |
download | luasocket-hjelmeland-patch-1.tar.gz luasocket-hjelmeland-patch-1.tar.bz2 luasocket-hjelmeland-patch-1.zip |
Merge branch 'master' into hjelmeland-patch-1hjelmeland-patch-1
Diffstat (limited to 'samples/qp.lua')
-rw-r--r-- | samples/qp.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/samples/qp.lua b/samples/qp.lua new file mode 100644 index 0000000..523238b --- /dev/null +++ b/samples/qp.lua | |||
@@ -0,0 +1,23 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- Little program to convert to and from Quoted-Printable | ||
3 | -- LuaSocket sample files | ||
4 | -- Author: Diego Nehab | ||
5 | ----------------------------------------------------------------------------- | ||
6 | local ltn12 = require("ltn12") | ||
7 | local mime = require("mime") | ||
8 | local convert | ||
9 | arg = arg or {} | ||
10 | local mode = arg and arg[1] or "-et" | ||
11 | if mode == "-et" then | ||
12 | local normalize = mime.normalize() | ||
13 | local qp = mime.encode("quoted-printable") | ||
14 | local wrap = mime.wrap("quoted-printable") | ||
15 | convert = ltn12.filter.chain(normalize, qp, wrap) | ||
16 | elseif mode == "-eb" then | ||
17 | local qp = mime.encode("quoted-printable", "binary") | ||
18 | local wrap = mime.wrap("quoted-printable") | ||
19 | convert = ltn12.filter.chain(qp, wrap) | ||
20 | else convert = mime.decode("quoted-printable") end | ||
21 | local source = ltn12.source.chain(ltn12.source.file(io.stdin), convert) | ||
22 | local sink = ltn12.sink.file(io.stdout) | ||
23 | ltn12.pump.all(source, sink) | ||