feat: Basic attachment support
This commit is contained in:
35
src/awk/attach.awk
Normal file
35
src/awk/attach.awk
Normal file
@@ -0,0 +1,35 @@
|
||||
## src/awk/attach.awk
|
||||
## Prepend attachment to iCalendar file.
|
||||
##
|
||||
## @assign file: Path to base64-encoded content
|
||||
## @assign mime: Mime
|
||||
## @assign filename: Original filename
|
||||
|
||||
# Functions
|
||||
|
||||
# Write attachment
|
||||
#
|
||||
# @local variables: line, aline
|
||||
function write_attachment( line, aline, fl) {
|
||||
line = "ATTACH;ENCODING=BASE64;VALUE=BINARY;FMTTYPE="mime";FILENAME="filename":"
|
||||
fl = 1
|
||||
while (getline aline <file) {
|
||||
line = line aline
|
||||
if (fl && length(line) >= 73) {
|
||||
print substr(line, 1, 73)
|
||||
line = substr(line, 74)
|
||||
fl = 0
|
||||
}
|
||||
while (length(line) >= 72) {
|
||||
print " "substr(line, 1, 72)
|
||||
line = substr(line, 73)
|
||||
}
|
||||
}
|
||||
if (line)
|
||||
print " "line
|
||||
}
|
||||
|
||||
# AWK program
|
||||
|
||||
/^END:VEVENT$/ { write_attachment() }
|
||||
{ print }
|
7
src/awk/attachdd.awk
Normal file
7
src/awk/attachdd.awk
Normal file
@@ -0,0 +1,7 @@
|
||||
BEGIN { FS="[:;]" }
|
||||
/^END:VEVENT$/ { ins = 0; exit }
|
||||
/^[^ ]/ && a { a = 0 }
|
||||
/^ / && a { print substr($0, 2) }
|
||||
/^ATTACH/ && ins { i++; }
|
||||
/^ATTACH/ && ins && i == id { a = 1; print substr($0, index($0, ":")+1) }
|
||||
/^BEGIN:VEVENT$/ { ins = 1 }
|
46
src/awk/attachls.awk
Normal file
46
src/awk/attachls.awk
Normal file
@@ -0,0 +1,46 @@
|
||||
# Decide if we need to read more to get all properties
|
||||
#
|
||||
# @input str: strin read so far
|
||||
# @return: 1 if we need more data, 0 otherwise
|
||||
function cont_reading(str) {
|
||||
return index(str, ":") ? 0 : 1
|
||||
}
|
||||
|
||||
# Get information about attachment
|
||||
#
|
||||
# @input i: Attachment index
|
||||
# @input str: Attachment string (at least up to content separator `:`)
|
||||
# @return: informative string
|
||||
function att_info(i, str, cnt, k, info) {
|
||||
str = substr(str, 1, index(str, ":") - 1)
|
||||
cnt = split(str, props)
|
||||
info = "Attachment "i":"
|
||||
if (cnt > 1) {
|
||||
for (k=2; k<=cnt; k++) {
|
||||
pname = substr(props[k], 1, index(props[k], "=") - 1)
|
||||
pvalu = substr(props[k], index(props[k], "=") + 1)
|
||||
if (pname == "ENCODING" && pvalu = "BASE64")
|
||||
enc = "base64"
|
||||
if (pname == "FILENAME")
|
||||
fin = pvalu
|
||||
if (pname == "VALUE")
|
||||
val = pvalu
|
||||
if (pname == "FMTTYPE")
|
||||
type = pvalu
|
||||
}
|
||||
if (fin)
|
||||
info = info " \"" fin "\""
|
||||
if (type)
|
||||
info = info " " type
|
||||
if (enc)
|
||||
info = info " (inline)"
|
||||
}
|
||||
print i, fin, type, enc, info
|
||||
}
|
||||
|
||||
BEGIN { FS="[:;]"; OFS="\t" }
|
||||
/^END:VEVENT$/ { ins = 0; exit }
|
||||
l && !r { att_info(i, l); l = "" }
|
||||
/^ / && r { l = l substr($0, 2); r = cont_reading($0) }
|
||||
/^ATTACH/ && ins { i++; l = $0; r = cont_reading($0) }
|
||||
/^BEGIN:VEVENT$/ { ins = 1 }
|
13
src/awk/attachrm.awk
Normal file
13
src/awk/attachrm.awk
Normal file
@@ -0,0 +1,13 @@
|
||||
## src/awk/attachrm.awk
|
||||
## Remove attachment from iCalendar file.
|
||||
##
|
||||
## @assign id: Attachment number to remove
|
||||
|
||||
BEGIN { FS="[:;]" }
|
||||
/^END:VEVENT$/ { ins = 0 }
|
||||
/^[^ ]/ && a { a = 0 }
|
||||
/^ / && a { next }
|
||||
/^ATTACH/ && ins { i++; }
|
||||
/^ATTACH/ && ins && i == id { a = 1; next }
|
||||
/^BEGIN:VEVENT$/ { ins = 1 }
|
||||
{ print }
|
10
src/awk/has.awk
Normal file
10
src/awk/has.awk
Normal file
@@ -0,0 +1,10 @@
|
||||
## src/awk/has.awk
|
||||
## Decide if VEVENT file has a specific field.
|
||||
##
|
||||
## @assign field: Field name
|
||||
|
||||
# AWK program
|
||||
BEGIN { FS = "[:;]" }
|
||||
/^BEGIN:VEVENT$/ { ins = 1 }
|
||||
/^END:VEVENT$/ { exit 1 }
|
||||
ins && $1 == field { exit 0 }
|
Reference in New Issue
Block a user