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;
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;
}
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;
}
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);
if (!copy) {
if (res)
- bye(EX_TEMPFAIL, "%m");
+ bye(EX_TEMPFAIL, "Cannot save mail to mailbox %s: %m", where);
else
bye(0, NULL);
}
destroy_email(em);
if (!copy) {
if (res)
- bye(EX_TEMPFAIL, "%m");
+ bye(EX_TEMPFAIL, "Cannot forward e-mail: %m");
else
bye(0, NULL);
}
{
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))
#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)
{
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)