notetools/md2imap/md2imap.sh

30 lines
631 B
Bash

qp () {
perl -MMIME::QuotedPrint -s -ne '
BEGIN { *e = $d ? \&decode_qp : \&encode_qp }
print e $_
' -- "$@"
}
rm mbox
rm uidmap
for f in input/*.md
do
dos2unix -q "$f"
f=${f##*/}
title=${f%.md}
subject=$(echo $title|qp -e)
uid=$(cat /proc/sys/kernel/random/uuid)
echo $uid $title >> uidmap
cp imap-note-header "$title".header
sed -i "s/name/$1/" "$title".header
sed -i "s/email/$2/" "$title".header
sed -i "s/uid/${uid}/" "$title".header
sed -i "s/title/${subject}/" "$title".header
cat "$title".header >> mbox
printf '\n\n' >> mbox
cat "input/$f" | qp -e >> mbox
rm "$title".header
done