]> Pileus Git - ~andy/fetchmail/blobdiff - fetchmail.c
Attempt merging from 6.3.24.
[~andy/fetchmail] / fetchmail.c
index 836728e680ee3a2712106e813e3122748bad5d3b..b33cf5858840a4f1ce039b8bb31355075100e177 100644 (file)
@@ -133,8 +133,7 @@ static void printcopyright(FILE *fp) {
        fprintf(fp, GT_("Copyright (C) 2002, 2003 Eric S. Raymond\n"
                   "Copyright (C) 2004 Matthias Andree, Eric S. Raymond,\n"
                   "                   Robert M. Funk, Graham Wilson\n"
-                  "Copyright (C) 2005 - 2006, 2010 Sunil Shetye\n"
-                  "Copyright (C) 2005 - 2010 Matthias Andree\n"
+                  "Copyright (C) 2005 - 2012 Matthias Andree, Sunil Shetye\n"
                   ));
        fprintf(fp, GT_("Fetchmail comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"
                   "are welcome to redistribute it under certain conditions. For details,\n"
@@ -422,11 +421,12 @@ static int get_pwmd_details(const char *pwmd_account, int protocol,
     return 0;
 }
 #endif
-
 int main(int argc, char **argv)
 {
     int bkgd = FALSE;
     int implicitmode = FALSE;
+    flag safewithbg = FALSE; /** if parsed options are compatible with a
+                             fetchmail copy running in the background */
     struct query *ctl;
     netrc_entry *netrc_list;
     char *netrc_file, *tmpbuf;
@@ -470,7 +470,6 @@ int main(int argc, char **argv)
 
 #define IDFILE_NAME    ".fetchids"
     run.idfile = prependdir (IDFILE_NAME, fmhome);
-  
     outlevel = O_NORMAL;
 
     /*
@@ -494,7 +493,7 @@ int main(int argc, char **argv)
     {
        int i;
 
-       i = parsecmdline(argc, argv, &cmd_run, &cmd_opts);
+       i = parsecmdline(argc, argv, &cmd_run, &cmd_opts, &safewithbg);
        if (i < 0)
            exit(PS_SYNTAX);
 
@@ -573,19 +572,50 @@ int main(int argc, char **argv)
     if (!quitonly)
        implicitmode = load_params(argc, argv, optind);
 
-    /* precedence: logfile (if effective) overrides syslog. */
-    if (run.logfile && run.poll_interval && !nodetach) {
-       run.use_syslog = 0;
+    if (run.logfile) {
+       /* nodetach -> turn off logfile option */
+       if (nodetach) {
+           if (outlevel >= O_NORMAL) { fprintf(stderr, GT_("The nodetach option is in effect, ignoring logfile option.\n")); }
+           xfree(run.logfile);
+       }
+
+#if 0
+       /* not in daemon mode -> turn off logfile option */
+       if (0 == run.poll_interval) {
+           if (outlevel >= O_NORMAL) { fprintf(stderr, GT_("Not running in daemon mode, ignoring logfile option.\n")); }
+           xfree(run.logfile);
+       }
+#endif
+
+       /* log file not writable -> turn off logfile option */
+       if (run.logfile && 0 != access(run.logfile, F_OK)) {
+           if (outlevel >= O_NORMAL) { fprintf(stderr, GT_("Logfile \"%s\" does not exist, ignoring logfile option.\n"), run.logfile); }
+           xfree(run.logfile);
+       }
+
+       /* log file not writable -> turn off logfile option */
+       if (run.logfile && 0 != access(run.logfile, W_OK)) {
+           fprintf(stderr, GT_("Logfile \"%s\" is not writable, aborting.\n"), run.logfile);
+           xfree(run.logfile);
+           exit(PS_UNDEFINED);
+       }
     }
 
     /* logging should be set up early in case we were restarted from exec */
     if (run.use_syslog)
     {
        openlog(program_name, LOG_PID, LOG_MAIL);
-       report_init(-1);
+       /* precedence: logfile (if effective) overrides syslog. */
+       if (run.logfile) {
+           syslog(LOG_ERR, GT_("syslog and logfile options are both set, ignoring syslog, and logging to %s"), run.logfile);
+           run.use_syslog = 0;
+           report_init((run.poll_interval == 0 || nodetach) && !run.logfile); /* when changing this, change copy below, too */
+       } else {
+           report_init(-1);
+       }
     }
     else
-       report_init((run.poll_interval == 0 || nodetach) && !run.logfile);
+       report_init((run.poll_interval == 0 || nodetach) && !run.logfile); /* when changing this, change copy above, too */
 
 #ifdef POP3_ENABLE
     /* initialize UID handling */
@@ -759,17 +789,23 @@ int main(int argc, char **argv)
        else if (getpid() == pid)
            /* this test enables re-execing on a changed rcfile */
            fm_lock_assert();
-       else if (argc > 1)
+       else if (argc > 1 && !safewithbg)
        {
            fprintf(stderr,
                    GT_("fetchmail: can't accept options while a background fetchmail is running.\n"));
+           {
+               int i;
+               fprintf(stderr, "argc = %d, arg list:\n", argc);
+               for (i = 1; i < argc; i++) fprintf(stderr, "arg %d = \"%s\"\n", i, argv[i]);
+           }
            return(PS_EXCLUDE);
        }
        else if (kill(pid, SIGUSR1) == 0)
        {
-           fprintf(stderr,
-                   GT_("fetchmail: background fetchmail at %ld awakened.\n"),
-                   (long)pid);
+           if (outlevel > O_SILENT)
+               fprintf(stderr,
+                       GT_("fetchmail: background fetchmail at %ld awakened.\n"),
+                       (long)pid);
            return(0);
        }
        else
@@ -858,14 +894,12 @@ int main(int argc, char **argv)
     else
     {
        /* not in daemon mode */
-       if (run.logfile && !nodetach && access(run.logfile, F_OK) == 0)
-       {
+       if (run.logfile)
+       {
            if (!freopen(run.logfile, "a", stdout))
                    report(stderr, GT_("could not open %s to append logs to\n"), run.logfile);
            if (!freopen(run.logfile, "a", stderr))
                    report(stdout, GT_("could not open %s to append logs to\n"), run.logfile);
-           if (run.use_syslog)
-               report(stdout, GT_("fetchmail: Warning: syslog and logfile are set. Check both for logs!\n"));
        }
     }
 
@@ -1102,7 +1136,6 @@ int main(int argc, char **argv)
            pwm = NULL;
        }
 #endif
-
        /* close connections cleanly */
        terminate_poll(0);
 
@@ -1226,7 +1259,6 @@ static void optmerge(struct query *h2, struct query *h1, int force)
     FLAG_MERGE(server.skip);
     FLAG_MERGE(server.dns);
     FLAG_MERGE(server.checkalias);
-    FLAG_MERGE(server.uidl);
     FLAG_MERGE(server.principal);
 
 #ifdef CAN_MONITOR
@@ -1239,6 +1271,7 @@ static void optmerge(struct query *h2, struct query *h1, int force)
     FLAG_MERGE(server.plugout);
     FLAG_MERGE(server.tracepolls);
     FLAG_MERGE(server.badheader);
+    FLAG_MERGE(server.retrieveerror);
 
     FLAG_MERGE(wildcard);
     FLAG_MERGE(remotename);
@@ -1398,7 +1431,6 @@ static int load_params(int argc, char **argv, int optind)
                        fprintf(stderr,GT_("Warning: multiple mentions of host %s in config file\n"),argv[optind]);
                    ctl->active = TRUE;
                    predeclared = TRUE;
-
 #ifdef HAVE_LIBPWMD
                    if (ctl->pwmd_file) {
                        /*
@@ -1429,7 +1461,6 @@ static int load_params(int argc, char **argv, int optind)
                 * call later on.
                 */
                ctl = hostalloc((struct query *)NULL);
-
 #ifdef HAVE_LIBPWMD
                if (cmd_opts.pwmd_file) {
                    /*
@@ -1589,7 +1620,6 @@ static int load_params(int argc, char **argv, int optind)
            DEFAULT(ctl->mimedecode, FALSE);
            DEFAULT(ctl->idle, FALSE);
            DEFAULT(ctl->server.dns, TRUE);
-           DEFAULT(ctl->server.uidl, FALSE);
            DEFAULT(ctl->use_ssl, FALSE);
            DEFAULT(ctl->sslcertck, FALSE);
            DEFAULT(ctl->server.checkalias, FALSE);
@@ -1638,6 +1668,7 @@ static int load_params(int argc, char **argv, int optind)
            if (!ctl->localnames)       /* for local delivery via SMTP */
                save_str_pair(&ctl->localnames, user, NULL);
 
+
            /*
             * can't handle multidrop mailboxes without "envelope"
             * option, this causes truckloads full of support complaints
@@ -1755,6 +1786,7 @@ static void terminate_run(int sig)
        if (ctl->password)
          memset(ctl->password, '\0', strlen(ctl->password));
 
+
     if (activecount == 0)
        exit(PS_NOMAIL);
     else
@@ -1808,7 +1840,6 @@ static int query_host(struct query *ctl)
        ctl->server.protocol = P_AUTO;
        break;
     case P_POP3:
-    case P_APOP:
 #ifdef POP3_ENABLE
        do {
            st = doPOP3(ctl);
@@ -1872,7 +1903,6 @@ static int print_id_of(struct uid_db_record *rec, void *unused)
     printf("\t%s\n", rec->id);
     return 0;
 }
-
 static void dump_params (struct runctl *runp,
                         struct query *querylist, flag implicit)
 /* display query parameters in English */
@@ -1932,12 +1962,8 @@ static void dump_params (struct runctl *runp,
                printf(GT_("  Password will be prompted for.\n"));
            else if (outlevel >= O_VERBOSE)
            {
-               if (ctl->server.protocol == P_APOP)
-                   printf(GT_("  APOP secret = \"%s\".\n"),
-                          visbuf(ctl->password));
-               else
-                   printf(GT_("  Password = \"%s\".\n"),
-                                                       visbuf(ctl->password));
+               printf(GT_("  Password = \"%s\".\n"),
+                                   visbuf(ctl->password));
            }
        }
 
@@ -1952,8 +1978,6 @@ static void dump_params (struct runctl *runp,
            printf(GT_(" (using service %s)"), ctl->server.service);
        else if (outlevel >= O_VERBOSE)
            printf(GT_(" (using default port)"));
-       if (ctl->server.uidl && MAILBOX_PROTOCOL(ctl))
-           printf(GT_(" (forcing UIDL use)"));
        putchar('.');
        putchar('\n');
        switch (ctl->server.authenticate)
@@ -1985,6 +2009,11 @@ static void dump_params (struct runctl *runp,
        case A_SSH:
            printf(GT_("  End-to-end encryption assumed.\n"));
            break;
+       case A_APOP:
+           printf(GT_("  APOP authentication will be forced.\n"));
+           break;
+       default:
+           abort();
        }
        if (ctl->server.principal != (char *) NULL)
            printf(GT_("  Mail service principal is: %s\n"), ctl->server.principal);
@@ -2271,6 +2300,7 @@ static void dump_params (struct runctl *runp,
                printf(GT_("  No UIDs saved from this host.\n"));
            else
            {
+
                printf(GT_("  %d UIDs saved.\n"), count);
                traverse_uid_db(&ctl->oldsaved, print_id_of, NULL);
            }
@@ -2291,6 +2321,19 @@ static void dump_params (struct runctl *runp,
                break;
        }
 
+       switch (ctl->server.retrieveerror) {
+           case RE_ABORT:
+               if (outlevel >= O_VERBOSE)
+                   printf(GT_("  Messages with fetch body errors will cause the session to abort.\n"));
+               break;
+           case RE_CONTINUE:
+               printf(GT_("  Messages with fetch body errors will be skipped, the session will continue.\n"));
+               break;
+           case RE_MARKSEEN:
+               printf(GT_("  Messages with fetch body errors will be marked seen, the session will continue.\n"));
+               break;
+       }
+
        if (ctl->properties)
            printf(GT_("  Pass-through properties \"%s\".\n"),
                   visbuf(ctl->properties));