commit 60bfa2edb213e82738037473393e80c144982b31
parent e1fb9e1b5253424e644fcfb1863ba2059c584957
Author: nibble <unknown>
Date: Mon, 9 Nov 2009 18:35:20 +0100
* Added 'dmc-filter -v' to list the value of given headers
* Removed dmc -H (replaced by 'dmc-filter -v')
* Update Manpage
Diffstat:
4 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -1,7 +1,7 @@
MIT/X Consortium License
© 2009 pancake <pancake at nopcode dot org>
-© 2009 nibble <nibble at gmail dot com>
+© 2009 nibble <nibble at develsec dot org>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
diff --git a/dmc b/dmc
@@ -116,9 +116,8 @@ send_message () {
fi
# TODO: find better name for the auto mode
if [ "${SEND}" = "!msmtp" ]; then
- # TODO: use dmc-filter here
- TO="`dmc -H To < $FILE`"
- SJ="`dmc -H Subject < $FILE`"
+ 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}
@@ -212,13 +211,6 @@ case "$1" in
ls ~/.dmc/acc | cat
fi
;;
-"-H"|"--header")
- if [ -z "$2" ]; then
- echo "Usage: dmc -H [header] < mail"
- else
- grep -e : | grep -re "^$2:" | cut -d : -f 2- | sed 's, ,,'
- fi
- ;;
"-c"|"--cmd")
if [ -z "$2" ]; then
while [ ! "$A" = "exit" ] ; do
@@ -269,7 +261,6 @@ case "$1" in
echo " -A file add attachment to mail"
echo " -c cmd run command for \$DMC_ACCOUNT or acc.default daemon"
echo " -m addr subj create mail with default account"
- echo " -H header grep for header"
echo " -s file send email"
echo " -v show version"
echo " -h show this help message"
diff --git a/dmc.1 b/dmc.1
@@ -28,8 +28,6 @@ Append file to the last mail edited with 'dmc -m'
Create new e-mail for sending using $EDITOR from the ~/.dmc/acc.default account
.It Fl c Ar command
Run dmc-* shell command. If no argument given enters in a shell eval loop
-.It Fl H Ar header
-Grep for given header
.It Fl s Ar file
Send file as mail
.It Fl v
@@ -47,5 +45,4 @@ Send all mails in outbox
.Sh FILES
~/.dmc/signature
.Sh AUTHORS
-.Pp
-pancake <@nopcode.org>
+pancake <@nopcode.org>, nibble <@develsec.org>
diff --git a/filter.c b/filter.c
@@ -6,14 +6,20 @@
int main(int argc, char **argv) {
char b[1024], argv2[1024][1024], *ptr;
- int edit = argc, print = 0, i, j;
+ int edit = argc, filter = 1, value = 0, print = 0, i, j;
- for (i = 0; i < argc; i++)
- if (!strcmp (argv[i], "-h")) {
- printf ("Usage: %s [-h] [headers | :] [-e] [new headers] < mail\n", argv[0]);
+ if (argc > 1) {
+ if (!strcmp (argv[1], "-h")) {
+ printf ("Usage: %s [-hv] [headers | :] [-e] [new headers] < mail\n", argv[0]);
return 1;
- } else if (!strcmp (argv[i], "-e"))
- edit = i;
+ } else if (!strcmp (argv[1], "-v")) {
+ value = 1;
+ filter++;
+ }
+ for (i = filter; i < argc; i++)
+ if (!strcmp (argv[i], "-e"))
+ edit = i;
+ }
for (i = 0; i < argc; i++) {
strncpy (argv2[i], argv[i], 1023);
argv2[i][1023] = '\0';
@@ -23,7 +29,7 @@ int main(int argc, char **argv) {
while (fgets (b, 1023, stdin) && b[0] != '\n')
if ((b[0] == ' ' || b[0] == '\t')) {
if (print) fputs (b, stdout);
- } else for (i = 1; i < edit && argv[i]; i++)
+ } else for (i = filter; i < edit && argv[i]; i++)
if (!strncmp (b, argv[i], strlen(argv[i])) || argv[i][0] == ':') {
/* Edit/Remove Headers */
print = 1;
@@ -36,15 +42,22 @@ int main(int argc, char **argv) {
print = 0;
break;
}
- if (print) fputs (b, stdout);
+ if (print) {
+ if (value && (ptr = strchr (b, ':')))
+ ptr += 2;
+ else ptr = b;
+ fputs (ptr, stdout);
+ }
break;
} else print = 0;
- /* New Headers */
- for (i = edit + 1; i < argc; i++)
- if (argv2[i][0]) puts (argv2[i]);
- if (edit < argc) puts ("");
- /* Body */
- while ((argc < 2 || edit < argc) && fgets (b, 1023, stdin))
- fputs (b, stdout);
+ if (!value) {
+ /* New Headers */
+ for (i = edit + 1; i < argc; i++)
+ if (argv2[i][0]) puts (argv2[i]);
+ if (edit < argc) puts ("");
+ /* Body */
+ while ((argc < 2 || edit < argc) && fgets (b, 1023, stdin))
+ fputs (b, stdout);
+ }
return 0;
}