commit 03f58bfef1d037ed254246bc645ea611b073c548
parent 7109edc0fd732ae1155bb6720f334ba8cee743f0
Author: pancake@localhost.localdomain <unknown>
Date: Mon, 2 Nov 2009 02:05:36 +0100
* Lock message in dmc -c is now displayed on stderr
- Fix manpage '-c' usage message
* Fix output of pop3 (ftruncate(0)+lseek(0))
* Fix dmc pull for pop3 with the new dmc -c
* Add dmc-pack -l to list files, but do not extract
Diffstat:
dmc | | | 6 | +++--- |
dmc.1 | | | 2 | +- |
pack.c | | | 50 | ++++++++++++++++++++++++++++---------------------- |
pop3.c | | | 2 | +- |
4 files changed, 33 insertions(+), 27 deletions(-)
diff --git a/dmc b/dmc
@@ -30,7 +30,7 @@ function acc_daemon {
function dmc_cmd {
echo "$@" > ~/.dmc/tmp/${NAME}.input
- head -n 1 ~/.dmc/tmp/${NAME}.lock
+ head -n 1 ~/.dmc/tmp/${NAME}.lock > /dev/stderr
cat ~/.dmc/tmp/${NAME}.output
}
@@ -132,8 +132,8 @@ function pull_mails {
# This is pop3-only
i=1
while [ ! "$LIMIT" = "$i" ] ; do
- dmc -c cat $i > ~/.dmc/box/${NAME}/in/$i.eml
- if [ -n "`head -n 3 ~/.dmc/box/${NAME}/in/$i.eml | grep ERR`" ]; then
+ dmc -c cat $i > ~/.dmc/box/${NAME}/in/$i.eml 2> ~/.dmc/tmp/${NAME}.tmp
+ if [ -n "`cat ~/.dmc/tmp/${NAME}.tmp | grep ERR`" ]; then
rm ~/.dmc/box/${NAME}/in/$i.eml
break
else
diff --git a/dmc.1 b/dmc.1
@@ -27,7 +27,7 @@ Append file to the last mail edited with 'dmc -m'
.It Fl m Ar addr subj
Create new e-mail for sending using $EDITOR from the ~/.dmc/acc.default account
.It Fl c Ar command
-Run dmc-pop3/dmc-imap4 shell 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
diff --git a/pack.c b/pack.c
@@ -37,22 +37,22 @@ void mime_pack(char **files, int nfiles) {
unsigned char bd[1024];
int header = 1, len, in, out, i;
- memset(b, '\0', 1024);
- while(fgets(b, 1023, stdin)) {
+ memset (b, '\0', 1024);
+ while(fgets (b, 1023, stdin)) {
if (header && b[0] == '\n') {
- printf( "Content-Type: multipart/mixed; boundary=\"dmc-multipart\"\n\n"
+ printf ("Content-Type: multipart/mixed; boundary=\"dmc-multipart\"\n\n"
"--dmc-multipart\n"
"Content-Type: text/plain\n");
header = 0;
}
- printf("%s", b);
+ printf ("%s", b);
}
for(i = 0; i < nfiles; i++) {
- snprintf(cmd, 1023, "file -i \"%s\"", files[i]);
- if (!(fd=popen(cmd, "r")))
+ snprintf (cmd, 1023, "file -i \"%s\"", files[i]);
+ if (!(fd=popen (cmd, "r")))
continue;
- fgets(b, 1023, fd);
- pclose(fd);
+ fgets (b, 1023, fd);
+ pclose (fd);
if (!(ptr = strchr(b, ' ')))
continue;
if (!(fd=fopen(files[i], "r")))
@@ -79,16 +79,15 @@ void mime_pack(char **files, int nfiles) {
printf("--dmc-multipart--\n");
}
-void mime_unpack()
-{
+void mime_unpack (int xtr) {
FILE *fd = NULL;
char b[1024], boundary[1024], encoding[1024], filename[1024], *ptr = NULL;
unsigned char bd[1024];
int entity = 0, dump = 0, len, in, out, i;
boundary[0] = encoding[0] = filename[0] = '\0';
- memset(b, '\0', 1024);
- while(fgets(b, 1023, stdin)) {
+ memset (b, '\0', 1024);
+ while (fgets(b, 1023, stdin)) {
if (!memcmp(b, "--", 2)) {
if (boundary[0] && strstr(b, boundary) &&
!memcmp(b+strlen(b)-3, "--", 2)) {
@@ -112,12 +111,17 @@ void mime_unpack()
if ((len=strlen(filename)) > 1)
filename[len-2] = '\0';
} else if (b[0] == '\n') {
- if (!dump && filename[0] && (fd = fopen(filename, "w"))) {
- printf("%s\n", filename);
- dump = 1;
- continue;
- } else if (dump && strstr(encoding, "base64"))
- dump = 0;
+ if (xtr) {
+ if (!dump && filename[0] && (fd = fopen(filename, "w"))) {
+ printf("%s\n", filename);
+ dump = 1;
+ continue;
+ } else if (dump && strstr(encoding, "base64"))
+ dump = 0;
+ } else {
+ if (!dump && filename[0])
+ printf("%s\n", filename);
+ }
}
} else boundary[0] = '\0';
if (dump) {
@@ -140,10 +144,12 @@ void mime_unpack()
/* TODO: Implement dmc-pack -l to only list filenames attached to the mail */
int main(int argc, char **argv) {
- if(argc < 2 || !strcmp(argv[1], "-h"))
- printf("usage: %s [-uh | attachment1 attachment2...]\n", argv[0]);
- else if(!strcmp(argv[1], "-u"))
- mime_unpack();
+ if (argc < 2 || !strcmp(argv[1], "-h"))
+ printf("usage: %s [-hlu | attachment1 attachment2...] < mail\n", argv[0]);
+ else if (!strcmp(argv[1], "-l"))
+ mime_unpack (0);
+ else if (!strcmp(argv[1], "-u"))
+ mime_unpack (1);
else mime_pack(argv+1, argc-1);
return 0;
}
diff --git a/pop3.c b/pop3.c
@@ -29,6 +29,7 @@ static int waitreply (int res) {
result[0] = 0;
ftruncate (2, 0);
+ lseek (2, 0, SEEK_SET);
while (lock || sock_ready ()) {
lock = 0;
if (sock_read (word, 512) <1)
@@ -59,7 +60,6 @@ static int waitreply (int res) {
snprintf (result, 1023, "### %s %d \"\"\n", cmd, reply);
write (1, result, strlen (result));
}
- lseek(1, 0, SEEK_SET);
return reply;
}