commit 634157b7472e17505d3b19e78d40fa34886a6b80
parent 1686710b857394c3e40443c3e1bd4719e949a74c
Author: pancake <nopcode.org>
Date: Wed, 5 May 2010 00:33:25 +0200
* Some changes in README and split into TODO
* Get USER= and PASS= from account if no arguments given
to 'login' in 'dmc'
* start/stop renamed to on/off
* Add '-b' flag to dmc-filter
- display only body (instead of headers)
* Fix \r|\n support in dmc-filter
* Fix stdout/stderr pipeline for 'cannot connect' in pop3
Diffstat:
5 files changed, 40 insertions(+), 24 deletions(-)
diff --git a/README b/README
@@ -63,7 +63,7 @@ You can start a shell to the default account using the following command:
In the same way you can just execute a command and get the output of it:
- $ dmc -c ls > mails
+ $ dmc -c on login ls "cat 1" off
You can change the default account by using 'dmc -e'
@@ -100,11 +100,3 @@ Fetch new mail:
Stop the daemons
$ dmc stop
-
-TODO
-----
-* Create a mail with attachments (dmc -m addr subject file1 file2 file3 ..)
-* Attach file to mail without hacky commands
-* Define a list of 'subscribed' folders for IMAP
-* Pull specific folder (dmc pull [folder])
-* getword() is implemented so MANY times.. MERGE!
diff --git a/TODO b/TODO
@@ -0,0 +1,10 @@
+TODO
+----
+* how to reply a mail?
+ - dmc -r [mail]
+ -> runs dmc-filter -b < mail | sed -e 's,^,> ,'
+* Create a mail with attachments (dmc -m addr subject file1 file2 file3 ..)
+* Attach file to given mail (not last one)
+* Define a list of 'subscribed' folders for IMAP
+* Pull specific folder (dmc pull [folder])
+* getword() is implemented so MANY times.. MERGE!
diff --git a/dmc.c b/dmc.c
@@ -194,7 +194,7 @@ static char *dmccmd(const char *cmd, char *err, int errlen) {
if (cmd && *cmd && *cmd != '\n') {
snprintf (buf, sizeof (buf), "%s\n", cmd);
write (dmc_in[1], buf, strlen (buf));
- printf ("write (%s)\n", cmd);
+ printf ("-(wri)-> (%s)\n", cmd);
cmd = NULL;
}
}
@@ -298,18 +298,24 @@ static int dmcsend(const char *file) {
}
static int dmcline(const char *line) {
- char err[128];
+ char err[128], cmd[128];
char *ptr = strchr (line, ' ');
- if (ptr)
- *ptr = '\0';
if (!strcmp (line, "?")) {
- printf ("Usage: start stop push pull exit ls cat ..\n");
+ printf ("Usage: on off push pull exit ls cat ..\n");
} else
- if (!strcmp (line, "start")) {
+ if (!strcmp (line, "login")) {
+ char *user = cfgget ("USER=");
+ char *pass = cfgget ("PASS=");
+ snprintf (cmd, sizeof (cmd), "login %s %s\n", user, pass);
+ ptr = dmccmd (cmd, err, sizeof (err));
+ free (user);
+ free (pass);
+ } else
+ if (!strcmp (line, "on")) {
dmcstart (acc[0]);
- ptr = dmccmd ("start", err, sizeof (err));
+ ptr = dmccmd ("on", err, sizeof (err));
} else
- if (!strcmp (line, "stop")) {
+ if (!strcmp (line, "off")) {
dmcstop ();
} else
if (!strcmp (line, "push")) {
@@ -324,8 +330,6 @@ static int dmcline(const char *line) {
if (!strcmp (line, "exit")) {
return 0;
} else {
- if (ptr)
- *ptr = ' ';
/* bypass to child */
ptr = dmccmd (line, err, sizeof (err));
if (ptr) {
diff --git a/filter.c b/filter.c
@@ -8,15 +8,18 @@
int main(int argc, char **argv) {
char b[1024], argv2[1024][1024], *ptr;
- int edit = argc, filter = 1, value = 0, print = 0, i, j;
+ int edit = argc, body = 0, filter = 1, value = 0, print = 0, i, j;
if (argc > 1) {
if (!strcmp (argv[1], "-h")) {
- printf ("Usage: %s [-hv] [headers | :] [-e] [new headers] < mail\n", argv[0]);
+ printf ("Usage: %s [-bhv] [headers | :] [-e] [new headers] < mail\n", argv[0]);
return 1;
} else if (!strcmp (argv[1], "-v")) {
value = 1;
filter++;
+ } else if (!strcmp (argv[1], "-b")) {
+ body = 1;
+ filter++;
}
for (i = filter; i < argc; i++)
if (!strcmp (argv[i], "-e"))
@@ -28,7 +31,9 @@ int main(int argc, char **argv) {
}
*b = '\0';
/* Headers */
- while (fgets (b, sizeof (b), stdin) && b[0] != '\n')
+ while (fgets (b, sizeof (b), stdin) && b[0] != '\n') {
+ if (b[0] == '\r' || b[0] == '\n')
+ break;
if ((b[0] == ' ' || b[0] == '\t')) {
if (print) fputs (b, stdout);
} else for (i = filter; i < edit && argv[i]; i++)
@@ -52,13 +57,15 @@ int main(int argc, char **argv) {
}
break;
} else print = 0;
+ }
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, sizeof (b), stdin))
+ if (body)
+ while ((body || argc<2 || edit<argc) && fgets (b, sizeof (b), stdin))
fputs (b, stdout);
}
return 0;
diff --git a/pop3.c b/pop3.c
@@ -103,7 +103,10 @@ int main(int argc, char **argv) {
strcpy (cmd, ".");
waitreply (1);
while (doword (getword ()));
- } else printf ("Cannot connect to %s %d\n", argv[1], atoi (argv[2]));
+ } else {
+ printf ("## on -1 Cannot connect to %s %d\n", argv[1], atoi (argv[2]));
+ fprintf(stderr, "\n");
+ }
} else printf ("Usage: dmc-pop3 host port [ssl] 2> body > fifo < input\n");
return 0;
}