bug-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-mailutils] Suggestion for a patch to dotlock.c


From: Gianni Mariani
Subject: [bug-mailutils] Suggestion for a patch to dotlock.c
Date: Mon, 16 Jun 2003 11:09:05 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030529


I'm running sendmail and I want one of my aliases to append messages directly to a file that is in my imap directory.

I thought that dotlock was really close so I added the functionality to it. The attached patch has an "--append" option that takes standard input and appends it to a file.

This patch is based on mailutils-0.3.

BTW- any suggestions are welcome - by no means do I think this is the best or most appropriate solution, just one I think will work for my needs. I've spent the last 2 days digging around the qmail/exim/postfix/sendmail docs and most of what I see is a mess and lack of conformity a richly diverse set of requirements and a history that borders on hysterical with a rich set of dogma trown in - no offence inteded, I suppose that's what happens with one of the oldest applications for the internet ! mailutils is a nice simple set of tools - I like that !

Thanks
G


--- dotlock.c.orig      Mon Jun 16 09:15:13 2003
+++ dotlock.c   Mon Jun 16 10:02:50 2003
@@ -25,6 +25,11 @@
 #endif
 #include <unistd.h>
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+
 #include <mailutils/argp.h>
 #include <mailutils/errno.h>
 #include <mailutils/locker.h>
@@ -50,6 +55,9 @@
   {"retry", 'r', N_("RETRIES"), OPTION_ARG_OPTIONAL,
    N_("Retry the lock a few times"), 0},
 
+  {"append", 'a', NULL, 0,
+   N_("Lock file, Append standard input to file, unlock file. (mbox append 
function)"), 0},
+
   {"debug", 'd', NULL, 0,
    N_("Print details of failure reasons to stderr"), 0},
 
@@ -75,6 +83,7 @@
 static int force;
 static int debug;
 static const char *program;
+static int append;
 
 static error_t
 parse_opt (int key, char *arg, struct argp_state *state)
@@ -87,6 +96,24 @@
 
     case 'u':
       unlock = 1;
+
+      if ( append )
+       argp_error (state, _("Cannot do unlock and append"));
+       
+      break;
+
+    case 'a':
+      append = 1;
+      if ( unlock )
+       argp_error (state, _("Cannot do unlock and append"));
+
+      // force for 60 seconds if appending
+      if ( ! ( flags & MU_LOCKER_TIME ) )
+       {
+         force = 60;
+         flags |= MU_LOCKER_TIME;
+       }
+       
       break;
 
     case 'T':
@@ -176,10 +203,6 @@
   else
     err = locker_lock (locker);
 
-  setegid(usergid);
-
-  locker_destroy (&locker);
-
   if (debug && err)
     fprintf (stderr, _("%s %s failed: %s\n"),
             unlock ? _("unlocking") : _("locking"), file, mu_strerror (err));
@@ -203,6 +226,48 @@
       break;
     }
 
+  if ( append && ! err)
+    {
+               
+       int append_fd = open( file, O_APPEND | O_WRONLY );
+
+       if ( append_fd < 0 )
+       {
+           fprintf (stderr, "open for append to %s failed: %s\n", file, 
strerror(errno));
+       }
+       else
+       {
+           char        buff[ 1 << 16 ];
+
+           int         siz;
+
+           while ( ( siz = read( 0, buff, sizeof( buff ) ) ) > 0 )
+             {
+               int wsiz;
+               
+               wsiz = write ( append_fd, buff, siz );
+
+               if ( wsiz != siz )
+                 {
+                   /* oh boy we have a major problem */
+
+                   fprintf (stderr, "Error happened while appending to file %s 
: %s\n", file, strerror(errno));
+                 }
+               
+             }
+
+           close( append_fd );
+       }
+
+       err = locker_remove_lock (locker);
+       
+    }
+    
+  setegid(usergid);
+
+  locker_destroy (&locker);
+
+
   return err;
 }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]