fetchmail-friends
[Top] [All Lists]

[fetchmail] [PATCH] new option to control polling

2003-10-29 14:45:19
Hi,

I wrote a patch for fetchmail 6.2.5 to control polling from outside of
fetchmail. It adds a new option to fetchmailrc, if you add

   set skipfile <filename>

and <filename> exists, the polls are skipped. If the file doesn't exist,
fetchmail operates as usual.

To see how it works, add "set skipfile /tmp/offline" to .fetchmailrc and
create a file /tmp/offline. Then run fetchmail...

I use this option with fetchmail in daemon mode for about two weeks
without problems. I either delete the "skipfile" if I am online or
create it if I am offline (e.g. with ip-up and ip-down scripts)

-- 
Holger Mauermann                            GnuPG/PGP Key ID: 0x8EA8C301
diff -Nur fetchmail-6.2.5.orig/conf.c fetchmail-6.2.5/conf.c
--- fetchmail-6.2.5.orig/conf.c Wed Oct 15 21:22:31 2003
+++ fetchmail-6.2.5/conf.c      Wed Oct 22 20:09:32 2003
@@ -198,6 +198,7 @@
     numdump("poll_interval", runp->poll_interval);
     stringdump("logfile", runp->logfile);
     stringdump("idfile", runp->idfile);
+    stringdump("skipfile", runp->skipfile);
     stringdump("postmaster", runp->postmaster);
     booldump("bouncemail", runp->bouncemail);
     booldump("spambounce", runp->spambounce);
diff -Nur fetchmail-6.2.5.orig/fetchmail.c fetchmail-6.2.5/fetchmail.c
--- fetchmail-6.2.5.orig/fetchmail.c    Wed Oct 15 21:22:31 2003
+++ fetchmail-6.2.5/fetchmail.c Wed Oct 22 20:36:09 2003
@@ -544,6 +544,7 @@
         * leaks...
         */
        struct stat     rcstat;
+       struct stat     skipstat;
 
        if (stat(rcfile, &rcstat) == -1)
        {
@@ -588,6 +589,13 @@
            execvp(argv[0], argv);
            report(stderr, GT_("attempt to re-exec fetchmail failed\n"));
        }
+       
+       if (stat(run.skipfile, &skipstat) == 0)
+       {
+           report(stdout, GT_("skipping poll (file %s exists)\n"), 
run.skipfile);
+       }
+       else
+       {
 
 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
        /*
@@ -714,6 +722,8 @@
 #if defined(HAVE_RES_SEARCH) && defined(USE_TCPIP_FOR_DNS)
        endhostent();           /* release TCP/IP connection to nameserver */
 #endif /* HAVE_RES_SEARCH */
+       
+       }
 
        /* close connections cleanly */
        terminate_poll(0);
@@ -1014,6 +1024,8 @@
        run.logfile = cmd_run.logfile;
     if (cmd_run.idfile)
        run.idfile = cmd_run.idfile;
+    if (cmd_run.skipfile)
+       run.skipfile = cmd_run.skipfile;
     /* do this before the keep/fetchall test below, otherwise -d0 may fail */
     if (cmd_run.poll_interval >= 0)
        run.poll_interval = cmd_run.poll_interval;
@@ -1446,6 +1458,8 @@
        printf(GT_("Logfile is %s\n"), runp->logfile);
     if (strcmp(runp->idfile, IDFILE_NAME))
        printf(GT_("Idfile is %s\n"), runp->idfile);
+    if (runp->skipfile)
+       printf(GT_("Skip poll if file %s exists\n"), runp->skipfile);
 #if defined(HAVE_SYSLOG)
     if (runp->use_syslog)
        printf(GT_("Progress messages will be logged via syslog\n"));
diff -Nur fetchmail-6.2.5.orig/fetchmail.h fetchmail-6.2.5/fetchmail.h
--- fetchmail-6.2.5.orig/fetchmail.h    Wed Oct 15 21:22:31 2003
+++ fetchmail-6.2.5/fetchmail.h Wed Oct 22 20:04:08 2003
@@ -130,6 +130,7 @@
 {
     char       *logfile;
     char       *idfile;
+    char       *skipfile;
     int                poll_interval;
     char       *postmaster;
     flag       bouncemail;
diff -Nur fetchmail-6.2.5.orig/rcfile_l.l fetchmail-6.2.5/rcfile_l.l
--- fetchmail-6.2.5.orig/rcfile_l.l     Wed Oct 15 21:22:31 2003
+++ fetchmail-6.2.5/rcfile_l.l  Wed Oct 22 20:05:28 2003
@@ -63,6 +63,7 @@
 set            { return SET; }
 logfile                { return LOGFILE; }
 idfile         { return IDFILE; }
+skipfile       { return SKIPFILE; }
 daemon         { return DAEMON; }
 syslog         { return SYSLOG; }
 invisible      { return INVISIBLE; }
diff -Nur fetchmail-6.2.5.orig/rcfile_y.y fetchmail-6.2.5/rcfile_y.y
--- fetchmail-6.2.5.orig/rcfile_y.y     Wed Oct 15 21:22:31 2003
+++ fetchmail-6.2.5/rcfile_y.y  Wed Oct 22 20:08:39 2003
@@ -68,7 +68,7 @@
 %token NETSEC INTERFACE MONITOR PLUGIN PLUGOUT
 %token IS HERE THERE TO MAP WILDCARD
 %token BATCHLIMIT FETCHLIMIT FETCHSIZELIMIT FASTUIDL EXPUNGE PROPERTIES
-%token SET LOGFILE DAEMON SYSLOG IDFILE INVISIBLE POSTMASTER BOUNCEMAIL 
+%token SET LOGFILE DAEMON SYSLOG IDFILE INVISIBLE POSTMASTER BOUNCEMAIL 
SKIPFILE
 %token SPAMBOUNCE SHOWDOTS
 %token <proto> PROTO AUTHTYPE
 %token <sval>  STRING
@@ -95,6 +95,7 @@
 /* future global options should also have the form SET <name> optmap <value> */
 statement      : SET LOGFILE optmap STRING     {run.logfile = prependdir ($4, 
rcfiledir);}
                | SET IDFILE optmap STRING      {run.idfile = prependdir ($4, 
rcfiledir);}
+               | SET SKIPFILE optmap STRING    {run.skipfile = prependdir ($4, 
rcfiledir);}
                | SET DAEMON optmap NUMBER      {run.poll_interval = $4;}
                | SET POSTMASTER optmap STRING  {run.postmaster = xstrdup($4);}
                | SET BOUNCEMAIL                {run.bouncemail = TRUE;}
<Prev in Thread] Current Thread [Next in Thread>
  • [fetchmail] [PATCH] new option to control polling, Holger Mauermann <=