dmc

dynamic mail client
git clone git://git.suckless.org/dmc
Log | Files | Refs | README | LICENSE

commit 3c1db6f66ad09ca648cbea07cbf81454ef67fa37
parent 4a53c1f65beb951587ed0664a107e5339b3f8c22
Author: nibble <unknown>
Date:   Tue, 10 Nov 2009 23:03:52 +0100

* dmc-pack
  - fixed issue handling symlinks
  - strip directory and suffix from filenames
* dmc
  - Adding attachments is implemented using dmc-pack
Diffstat:
dmc | 12++++++++++--
pack.c | 11+++++++----
2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/dmc b/dmc @@ -115,20 +115,27 @@ send_message () { exit 1 fi # TODO: find better name for the auto mode + if [ -e "${FILE}.d" ]; then + TMP="`mktemp ~/.dmc/tmp/mail.XXXXXX`" + cat $FILE | dmc-pack `ls ${FILE}.d/*` > $TMP + else + TMP=$FILE + fi if [ "${SEND}" = "!msmtp" ]; then TO="`dmc-filter -v To: < $FILE`" SJ="`dmc-filter -v Subject: < $FILE`" echo "Sending mail to $TO (${SJ})..." # HOST=`dmc-smtp ${TO}` - msmtp "--user=${USER}" "--from=${MAIL}" $TO < ${FILE} + msmtp "--user=${USER}" "--from=${MAIL}" $TO < ${TMP} return $? elif [ "`echo \"${SEND}\" | grep '|'`" ]; then echo "=> cat $1 ${SEND}" # TODO: setup environment for $TO $SUBJECT ... - eval cat $1 ${SEND} + eval cat ${TMP} ${SEND} else echo "SEND method '${SEND}' not supported" fi + [ -e "${FILE}.d" ] && rm -f $TMP return 0 } @@ -183,6 +190,7 @@ case "$1" in echo "Mail sent. local copy moved to ~/.dmc/box/${NAME}/sent" mkdir -p ~/.dmc/box/${NAME}/sent mv $b ~/.dmc/box/${NAME}/sent + [ -e "${b}.d" ] && mv ${b}.d ~/.dmc/box/${NAME}/sent else echo "There was an error sending the mail" fi diff --git a/pack.c b/pack.c @@ -32,7 +32,7 @@ int b64_decode(unsigned char in[4], unsigned char out[3]) { void mime_pack(char **files, int nfiles) { FILE *fd = NULL; - char b[1024], cmd[1024], *ptr = NULL; + char b[1024], cmd[1024], *ptr = NULL, *ptr2 = NULL; unsigned char bd[1024]; int header = 1, len, in, out, i; @@ -47,7 +47,7 @@ void mime_pack(char **files, int nfiles) { fputs (b, stdout); } for(i = 0; i < nfiles; i++) { - snprintf (cmd, 1023, "file -i \"%s\"", files[i]); + snprintf (cmd, 1023, "file -iL \"%s\"", files[i]); if (!(fd=popen (cmd, "r"))) continue; fgets (b, 1023, fd); @@ -56,9 +56,12 @@ void mime_pack(char **files, int nfiles) { continue; if (!(fd=fopen(files[i], "r"))) continue; + if ((ptr2 = strrchr(files[i], '/'))) + ptr2++; + else ptr2 = files[i]; puts ("--dmc-multipart"); - printf ("Content-Type: %s\n", ptr+1); - printf ("Content-Disposition: attachment; filename=\"%s\"\n", files[i]); + printf ("Content-Type: %s", ptr+1); + printf ("Content-Disposition: attachment; filename=\"%s\"\n", ptr2); if (strstr (ptr, "text")) { printf("Content-Transfer-Encoding: quoted-printable\n\n"); while (fgets(b, 1023, fd))