]> andersk Git - moira.git/blobdiff - gen/mailhub.pc
Command line printer manipulation client, and build goo.
[moira.git] / gen / mailhub.pc
index d5ced05bb5d0af0178e5381fdbce6bd1d66b087a..2d075aaa6097601c349acd250bc985166fd132cd 100644 (file)
@@ -52,6 +52,8 @@ struct list {
   char *description;
   char acl_t;
   int acl_id;
+  char mailman;
+  char *mailman_server;
   struct member *m;
 };
 
@@ -69,25 +71,11 @@ int main(int argc, char **argv)
 {
   time_t tm = time(NULL);
   char filename[MAXPATHLEN], *targetfile;
-  struct stat sb;
-  int flag1, flag2;
 
   EXEC SQL CONNECT :db;
 
   if (argc == 2)
     {
-      if (stat(argv[1], &sb) == 0)
-       {
-         if (ModDiff(&flag1, "users", sb.st_mtime) ||
-             ModDiff(&flag2, "list", sb.st_mtime))
-           exit(MR_DATE);
-         if (flag1 < 0 && flag2 < 0)
-           {
-             fprintf(stderr, "File %s does not need to be rebuilt.\n",
-                     argv[1]);
-             exit(MR_NO_CHANGE);
-           }
-       }
       targetfile = argv[1];
       sprintf(filename, "%s~", targetfile);
       if (!(out = fopen(filename, "w")))
@@ -136,11 +124,11 @@ int main(int argc, char **argv)
 void get_info(void)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  int id, pid, iid, bid, cnt, maillistp, acl, mid;
+  int id, pid, iid, bid, eid, cnt, maillistp, acl, mid, mailman;
   char mname[MACHINE_NAME_SIZE], str[STRINGS_STRING_SIZE];
   char login[USERS_LOGIN_SIZE], potype[USERS_POTYPE_SIZE];
   char lname[LIST_NAME_SIZE], desc[LIST_DESCRIPTION_SIZE];
-  char type[LIST_ACL_TYPE_SIZE];
+  char type[LIST_ACL_TYPE_SIZE], mailman_server[MACHINE_NAME_SIZE];
   EXEC SQL END DECLARE SECTION;
   char *s;
   struct user *u;
@@ -162,7 +150,7 @@ void get_info(void)
     WHERE status = 1
     AND ( mach_id IN ( SELECT UNIQUE pop_id FROM users ) OR
          mach_id IN ( SELECT UNIQUE mach_id FROM filesys
-                      WHERE type = 'IMAP' ) )
+                      WHERE type = 'IMAP' ) )    
     ORDER BY mach_id;
   EXEC SQL OPEN m_cursor;
   while (1)
@@ -186,6 +174,28 @@ void get_info(void)
     }
   EXEC SQL CLOSE m_cursor;
 
+  EXEC SQL DECLARE e_cursor CURSOR FOR
+    SELECT mach_id, name
+    FROM machine
+    WHERE status = 1
+    AND mach_id in (SELECT UNIQUE exchange_id FROM users)
+    ORDER BY mach_id;
+  EXEC SQL OPEN e_cursor;
+  while (1)
+    {
+      EXEC SQL FETCH e_cursor INTO :id, :mname;
+      if (sqlca.sqlcode)
+       break;
+      strtrim(mname);
+      if (hash_store(machines, id, strdup(mname)) < 0)
+       {
+         fprintf(stderr, "Out of memory!\n");
+         exit(MR_NO_MEM);
+       }
+      cnt++;
+    }
+  EXEC SQL CLOSE e_cursor;
+       
   fprintf(stderr, "Loaded %d machines\n", cnt);
 
   cnt = 0;
@@ -216,7 +226,7 @@ void get_info(void)
   users = create_hash(13001);
 
   EXEC SQL DECLARE u_cursor CURSOR FOR
-    SELECT users_id, login, potype, pop_id, imap_id, box_id
+    SELECT users_id, login, potype, pop_id, imap_id, box_id, exchange_id
     FROM users
     WHERE status != 3
     ORDER BY users_id;
@@ -225,7 +235,8 @@ void get_info(void)
     {
       char *saddr = NULL, *paddr = NULL;
 
-      EXEC SQL FETCH u_cursor INTO :id, :login, :potype, :pid, :iid, :bid;
+      EXEC SQL FETCH u_cursor INTO :id, :login, :potype, :pid, :iid, :bid,
+       :eid;
       if (sqlca.sqlcode)
        break;
       u = malloc(sizeof(struct user));
@@ -242,7 +253,7 @@ void get_info(void)
 
              /* If SMTP, clear pid and iid. */
              if (potype[1] == 'M')
-               pid = iid = 0;
+               pid = iid = eid = 0;
            }
 
          /* If IMAP, or SPLIT with IMAP, set pid to mach_id. */
@@ -252,6 +263,10 @@ void get_info(void)
                WHERE filsys_id = :iid;
            }
 
+         /* If EXCHANGE or SPLIT with EXCHANGE, set pid to eid. */
+         if (potype[0] == 'E' || (potype[0] == 'S' && eid))
+           pid = eid;
+
          if (pid && (s = hash_lookup(machines, pid)))
            {
              paddr = malloc(strlen(u->login) + strlen(s) + 2);
@@ -285,14 +300,16 @@ void get_info(void)
   lists = create_hash(15000);
 
   EXEC SQL DECLARE l_cursor CURSOR FOR
-    SELECT list_id, name, maillist, description, acl_type, acl_id
-    FROM list
-    WHERE active != 0
+    SELECT l.list_id, l.name, l.maillist, l.description, l.acl_type, l.acl_id,
+    l.mailman, m.name
+    FROM list l, machine m
+    WHERE active != 0 AND l.mailman_id = m.mach_id
     ORDER BY list_id;
   EXEC SQL OPEN l_cursor;
   while (1)
     {
-      EXEC SQL FETCH l_cursor INTO :id, :lname, :maillistp, :desc, :type, :acl;
+      EXEC SQL FETCH l_cursor INTO :id, :lname, :maillistp, :desc, :type, :acl,
+       :mailman, :mailman_server;
       if (sqlca.sqlcode)
        break;
       l = malloc(sizeof(struct list));
@@ -301,6 +318,8 @@ void get_info(void)
       l->description = strdup(strtrim(desc));
       l->acl_t = type[0];
       l->acl_id = acl;
+      l->mailman = mailman;
+      l->mailman_server = strdup(strtrim(mailman_server));
       l->m = NULL;
       if (hash_store(lists, id, l) < 0)
        {
@@ -400,6 +419,11 @@ void output_login(int dummy, void *user, void *out)
     fprintf(out, "%s: %s\n", u->login, u->pobox);
 }
 
+static const char *mailman_suffixes[] = { "-admin", "-owner", "-request",
+                                         "-bounces", "-confirm", "-join",
+                                         "-leave", "-subscribe",
+                                         "-unsubscribe", NULL };
+
 void output_mlist(int id, struct list *l)
 {
   struct list *l1;
@@ -408,9 +432,19 @@ void output_mlist(int id, struct list *l)
   int line_width, alias_width, word_width, beginning;
   static int cont = 1;
   char str[8];
+  int i;
 
   put_fill(out, l->description);
-  if (l->acl_t ==  'L' && (l1 = hash_lookup(lists, l->acl_id)))
+
+  if (l->mailman && strcmp(l->mailman_server, "[NONE]"))
+    {
+      for (i = 0; mailman_suffixes[i]; i++)
+       fprintf(out, "%s%s: %s%s@%s\n", l->name, mailman_suffixes[i], l->name,
+               mailman_suffixes[i], l->mailman_server);
+      fprintf(out, "owner-%s: %s-owner@%s\n%s: ", l->name, l->name,
+             l->mailman_server, l->name);
+    }
+  else if (l->acl_t ==  'L' && (l1 = hash_lookup(lists, l->acl_id)))
     fprintf(out, "owner-%s: %s\n%s: ", l->name, l1->name, l->name);
   else if (l->acl_t ==  'U' && (u = hash_lookup(users, l->acl_id)))
     fprintf(out, "owner-%s: %s\n%s: ", l->name, u->login, l->name);
@@ -516,8 +550,10 @@ void put_fill(FILE *aliases, char *string)
 }
 
 
-/* Illegal chars: this should correspond to the array used by
- * setup_alis. */
+/* Illegal chars: this no longer corresponds to the array
+ * in setup_alis.  '+' is a valid character in a string on 
+ * a list, but is not a valid character in a listname.
+ */
 
 static int illegalchars[] = {
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^@ - ^O */
This page took 0.039798 seconds and 4 git commands to generate.