dmc

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

commit bbd442e865ec996b4af0a345a49d04b9cbc87e43
parent c35cfeda26c485e56be9fda8cf578944d1c479e1
Author: pancake <nopcode.org>
Date:   Tue,  4 May 2010 02:35:37 +0200

* support other mail transports than pop3
  - defined in ~/.dmc/acc/*
* dmc -c now accepts arguments to interpret commands
  - dmc start "login user pass" ls exit
* fix dmcpush (do not try to send '.d' (hacky)
Diffstat:
dmc.c | 44++++++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/dmc.c b/dmc.c @@ -48,10 +48,10 @@ static char *cfgget(const char *key) { fgets (line, sizeof (line), fd); if (!memcmp (line, key, len)) { ptr = strchr (line, '#'); - if (ptr) + if (ptr) { for (*ptr=0, ptr--; ptr != line && (*ptr==' ' || *ptr=='\t'); ptr--) *ptr = 0; - line [strlen (line)-1] = 0; + } else line [strlen (line)-1] = 0; ret = strdup (line+len); break; } @@ -83,7 +83,8 @@ static char *gethdr(const char *path, const char *file, const char *hdr) { /* server */ static int dmcstart(const char *name) { - char *host, *port; + char a0[512], a1[32]; + char *host, *port, *prot; pipe (dmc_in); pipe (dmc_out); pipe (dmc_err); @@ -108,7 +109,11 @@ static int dmcstart(const char *name) { host = cfgget ("HOST="); port = cfgget ("PORT="); - execl (PREFIX"/bin/dmc-pop3", "dmc-pop3", host, port, NULL); + prot = cfgget ("PROTOCOL="); + snprintf (a0, sizeof (a0), PREFIX"/bin/dmc-%s", prot); + snprintf (a1, sizeof (a1), "dmc-%s", prot); + printf ("(%s)\n", a0); + execl (a0, a1, host, port, NULL); free (host); free (port); exit (1); @@ -204,15 +209,17 @@ static void dmcpush(const char *name) { for (i=0; acc[i]; i++) { snprintf (path, sizeof (path), DMCDIR"/box/%s/out", acc[i]); dir = opendir (path); - while ((de = readdir (dir))) - if (*de->d_name != '.') { - snprintf (file, sizeof (file), "%s/%s", path, de->d_name); + while ((de = readdir (dir))) { + char *n = de->d_name; + if (*n != '.' && !strstr (n, ".d")) { + snprintf (file, sizeof (file), "%s/%s", path, n); printf ("--> %s\n", file); if (dmcsend (file)) { // TODO: remove .d unlink (file); } } + } closedir (dir); } } @@ -250,7 +257,6 @@ static char **dmcaccounts() { } else fprintf (stderr, "No default account defined.\n"); dir = opendir (DMCDIR"/acc"); while ((de = readdir (dir)) && acc<MAXACC-2) - if (de->d_type == DT_REG) if (*de->d_name != '.' && (!defacc || strcmp (de->d_name, defacc))) accounts[acc++] = strdup (de->d_name); accounts[acc] = NULL; @@ -507,14 +513,20 @@ int main(int argc, char **argv) { } break; case 'c': - strcpy (prompt, "dmc> "); - do { - write (1, prompt, strlen (prompt)); - fgets(line, sizeof (line), stdin); - if (feof (stdin)) - strcpy (line, "exit"); - else line[strlen (line)-1] = '\0'; - } while (dmcline (line)); + if (argc<3) { + strcpy (prompt, "dmc> "); + do { + write (1, prompt, strlen (prompt)); + fgets(line, sizeof (line), stdin); + if (feof (stdin)) + strcpy (line, "exit"); + else line[strlen (line)-1] = '\0'; + } while (dmcline (line)); + } else { + strcpy (prompt, ""); + for(i=2; i<argc; i++) + dmcline (argv[i]); + } dmcstop (); break; default: