]> mj.ucw.cz Git - umpf.git/commitdiff
cleanup in error messages
authorAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 14:59:51 +0000 (16:59 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 14:59:51 +0000 (16:59 +0200)
ham.c
int.c
lex.c
umpf.c

diff --git a/ham.c b/ham.c
index 1441451d246e78d83bbd89f894743c6a05acf7b8..3e6dade23fc652ace1c8ff1b9a8fa004ddf193a0 100644 (file)
--- a/ham.c
+++ b/ham.c
@@ -154,7 +154,7 @@ get_body(int rfd)
                        fd = mkstemp(tmpfile);
                        /* cannot create tmpfile, try to continue reading */
                        if (fd < 0)
-                               bye(EX_TEMPFAIL, "%m");
+                               bye(EX_TEMPFAIL, "Cannot create temporary file: %m");
                        else {
                                will_save = 1;
                                b->body = NULL;
@@ -163,7 +163,7 @@ get_body(int rfd)
                                res = write(fd, buf, MAIL_LEN);
                                if (res < MAIL_LEN) {
                                        unlink(b->tmpfile);
-                                       bye(EX_TEMPFAIL, "%m");
+                                       bye(EX_TEMPFAIL, "Cannot write to remporary file: %m");
                                }
                                break;  
                        }
@@ -181,14 +181,14 @@ get_body(int rfd)
                                res = write(fd, buf, MAIL_LEN);
                                if (res < MAIL_LEN) {
                                        unlink(b->tmpfile);
-                                       bye(EX_TEMPFAIL, "%m");
+                                       bye(EX_TEMPFAIL, "Cannot write to temporary file: %m");
                                }
                        }
                }
                res = write(fd, buf, j);
                if (res < j) {
                        unlink(b->tmpfile);
-                       bye(EX_TEMPFAIL, "%m");
+                       bye(EX_TEMPFAIL, "Cannot write to temporary file: %m");
                }
        }
        return b; 
@@ -343,8 +343,6 @@ copy_email(int fd, struct email* email)
        }
 
        write_char_to_mailbox('\n', fd);
-       /* body */
-       /* FIXME: do not forget change Content-Length */
        if (email->body) {
                for (pc = email->body; pc < email->body + email->body_len; pc++){
                                write_char_to_mailbox(*pc, fd);
diff --git a/int.c b/int.c
index 56861dd45e1ecc48954774c12ecac7903b81ee37..d2146d754c042ffedab8b25fa234ce2677688365 100644 (file)
--- a/int.c
+++ b/int.c
@@ -451,7 +451,7 @@ deliver(char* where, int copy, struct list* hash)
 
        if (!copy) {
                if (res)
-                       bye(EX_TEMPFAIL, "%m");
+                       bye(EX_TEMPFAIL, "Cannot save mail to mailbox %s: %m", where);
                else
                        bye(0, NULL);
        }
@@ -486,7 +486,7 @@ end:
        destroy_email(em);
        if (!copy) {
                if (res)
-                       bye(EX_TEMPFAIL, "%m");
+                       bye(EX_TEMPFAIL, "Cannot forward e-mail: %m");
                else
                        bye(0, NULL);
        }
diff --git a/lex.c b/lex.c
index 4e4a10334ab08dcc502570d8a5d3398fa2213a33..aaf10d01b71ecd5287850c8946756104548315be 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -28,8 +28,10 @@ read_conf(char* filename)
 {
        conf = fopen(filename, "r");
 
-       if (! conf)
-               die("read_conf: %m"); 
+       if (! conf) {
+               fprintf(stderr, "Error reading config file: %m\nSaving to default mailbox %s\n", default_mailbox);
+               longjmp(env, 1); 
+       }
 }
 
 void __attribute__ ((noreturn)) 
diff --git a/umpf.c b/umpf.c
index e97da9eadc89554a0346a57b707c13c294387664..e01aca26a1d1a042d342e466c9513ba5984f0be0 100644 (file)
--- a/umpf.c
+++ b/umpf.c
@@ -1,9 +1,13 @@
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <pwd.h>
+#include <getopt.h>
 
 #include "umpf.h"
 
+#define DEFAULT_CONF ".umpf"
+
 void
 init(void)
 {
@@ -18,28 +22,48 @@ init(void)
 int
 main(int argc, char** argv)
 {
-       int res;
-       int i;
+       int res, i, opt;
+       char* conffile = NULL;
        
-       if (argc < 2)
-               die("Usage: ./umpf conf_file [default_mailbox]");
+       while ((opt = getopt(argc, argv, "c:m:")) != -1) {
+               switch (opt) {
+               case 'm':
+                       default_mailbox = optarg;
+                       break;
+               case 'c':
+                       conffile = optarg;
+                       break;
+               default:
+                       die("Usage: ./umpf [-c conf_file] [-m default_mailbox]");
+               }
+       }
 
-       struct passwd* p;
-       p = getpwuid(getuid());
-       if (argc < 3)
-                default_mailbox = cat("/var/mail/", p->pw_name);
-       else
-                default_mailbox = argv[2];
+       if (!default_mailbox) {
+               struct passwd* p;
 
-       save_gids();
+               p = getpwuid(getuid());
+               default_mailbox = cat("/var/mail/", p->pw_name);
+       }
 
+               save_gids();
        init();
 
        /* returning from longjump? save the mail and exit */
        if (setjmp(env))
                goto skip_conf;
 
-       read_conf(argv[1]);
+       if (! conffile) {
+               int len;
+               char* home; 
+
+               home = getenv("HOME");
+               if (! home)
+                       goto skip_conf;
+
+               conffile = xmalloc(strlen(home) + strlen(DEFAULT_CONF) + 1);
+               sprintf(conffile, "%s/%s", home, DEFAULT_CONF); 
+       }
+       read_conf(conffile);
        res = yyparse ();
 
        if (res)