feat: inline 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:(VTODO|VJOURNAL)$/ { write_attachment() }
 | 
			
		||||
{ print }
 | 
			
		||||
							
								
								
									
										8
									
								
								src/awk/attachdd.awk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/awk/attachdd.awk
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
BEGIN                       { FS="[:;]" }
 | 
			
		||||
/^END:(VTODO|VJOURNAL)$/    { ins = 0; exit }
 | 
			
		||||
/^[^ ]/ && a                { a = 0 }
 | 
			
		||||
/^ / && a && p              { print substr($0, 2); }
 | 
			
		||||
/^ / && a && !p             { if (index($0, ":")) { p = 1; print substr($0, index($0, ":")+1) } }
 | 
			
		||||
/^ATTACH/ && ins            { i++; }
 | 
			
		||||
/^ATTACH/ && ins && i == id { a = 1; if (index($0, ":")) { p = 1; print substr($0, index($0, ":")+1) } }
 | 
			
		||||
/^BEGIN:(VTODO|VJOURNAL)$/  { ins = 1 }
 | 
			
		||||
							
								
								
									
										41
									
								
								src/awk/attachls.awk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/awk/attachls.awk
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
# 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)
 | 
			
		||||
  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 (enc)
 | 
			
		||||
      info = "inline"
 | 
			
		||||
  }
 | 
			
		||||
  print i, fin, type, enc, info
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BEGIN                      { FS="[:;]"; OFS="\t" }
 | 
			
		||||
/^END:(VTODO|VJOURNAL)$/   { 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:(VTODO|VJOURNAL)$/ { 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:(VTODO|VJOURNAL)$/    { ins = 0 }
 | 
			
		||||
/^[^ ]/ && a                { a = 0 }
 | 
			
		||||
/^ / && a                   { next }
 | 
			
		||||
/^ATTACH/ && ins            { i++; }
 | 
			
		||||
/^ATTACH/ && ins && i == id { a = 1; next }
 | 
			
		||||
/^BEGIN:(VTODO|VJOURNAL)$/  { ins = 1 }
 | 
			
		||||
{ print }
 | 
			
		||||
@@ -50,6 +50,7 @@ BEGIN {
 | 
			
		||||
  # flag_journal:   symbol for journal entries
 | 
			
		||||
  # flag_note:      symbol for note entries
 | 
			
		||||
  # flag_priority   symbol for prior. task
 | 
			
		||||
  # flag_attachment symbol for attachment
 | 
			
		||||
  # style_collection
 | 
			
		||||
  # style_date
 | 
			
		||||
  # style_summary
 | 
			
		||||
@@ -76,6 +77,7 @@ BEGIN {
 | 
			
		||||
BEGINFILE {
 | 
			
		||||
  type = "";
 | 
			
		||||
  prop = "";
 | 
			
		||||
  att = "";
 | 
			
		||||
  delete c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -92,6 +94,11 @@ BEGINFILE {
 | 
			
		||||
  c[prop] = $0;
 | 
			
		||||
  next;
 | 
			
		||||
}
 | 
			
		||||
/^ATTACH/ {
 | 
			
		||||
  prop = ""
 | 
			
		||||
  att = 1;
 | 
			
		||||
  next;
 | 
			
		||||
}
 | 
			
		||||
/^[^ ]/ && prop {
 | 
			
		||||
  prop = "";
 | 
			
		||||
  next;
 | 
			
		||||
@@ -193,6 +200,9 @@ ENDFILE {
 | 
			
		||||
  # categories
 | 
			
		||||
  categories = cat ? cat : " "
 | 
			
		||||
 | 
			
		||||
  # attachments
 | 
			
		||||
  att = att ? flag_attachment " " : ""
 | 
			
		||||
 | 
			
		||||
  # filename
 | 
			
		||||
  # FILENAME
 | 
			
		||||
 | 
			
		||||
@@ -203,6 +213,6 @@ ENDFILE {
 | 
			
		||||
        collection,
 | 
			
		||||
        datecolor d OFF,
 | 
			
		||||
        flag,
 | 
			
		||||
        priotext summarycolor summary OFF,
 | 
			
		||||
        priotext att summarycolor summary OFF,
 | 
			
		||||
        style_category categories OFF;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user