]> andersk Git - moira.git/blobdiff - gen/mailhub.pc
Don't complain for quota deltas < 400MB.
[moira.git] / gen / mailhub.pc
index fba905a489e3c927bbc5160020db7b458fb7c38f..c7a66b71b0a64ec7b4f1acb4b8cefda37f86f0fa 100644 (file)
@@ -34,8 +34,6 @@ char *divide = "##############################################################";
 #define FALSE 0
 #define TRUE (!FALSE)
 
-FILE *out = stdout;
-
 struct hash *users, *machines, *strings, *lists;
 struct user {
   char *login;
@@ -56,10 +54,10 @@ struct list {
 };
 
 void get_info(void);
-void save_mlist(int id, void *list, void *force);
 int check_string(char *s);
 void output_login(int dummy, void *names, void *out);
-void output_mlist(int id, struct list *l);
+void output_mlist(int id, void *list, void *out);
+void output_membership(struct list *l, FILE *out);
 void put_fill(FILE *aliases, char *string);
 void do_people(void);
 
@@ -69,25 +67,13 @@ int main(int argc, char **argv)
 {
   time_t tm = time(NULL);
   char filename[MAXPATHLEN], *targetfile;
-  struct stat sb;
-  int flag1, flag2;
+  FILE *out = stdout;
 
+  srand(tm);
   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")))
@@ -112,7 +98,7 @@ int main(int argc, char **argv)
 
   incount = 0;
   fprintf(out, "\n%s\n# Mailing lists\n%s\n\n", divide, divide);
-  hash_step(lists, save_mlist, FALSE);
+  hash_step(lists, output_mlist, out);
   fprintf(stderr, "Output %d lists\n", incount);
 
   incount = 0;
@@ -223,29 +209,52 @@ void get_info(void)
   EXEC SQL OPEN u_cursor;
   while (1)
     {
+      char *saddr = NULL, *paddr = NULL;
+
       EXEC SQL FETCH u_cursor INTO :id, :login, :potype, :pid, :iid, :bid;
       if (sqlca.sqlcode)
        break;
       u = malloc(sizeof(struct user));
       u->login = strdup(strtrim(login));
 
-      if (potype[0] == 'I')
-       {
-         EXEC SQL SELECT f.mach_id INTO :pid FROM filesys f, users u
-           WHERE u.users_id = :id AND f.filsys_id = u.imap_id;
-         if (sqlca.sqlcode == 0)
-           potype[0] = 'P';
-       }
-      if (potype[0] == 'P' && (s = hash_lookup(machines, pid)))
+      if (!strcmp(strtrim(potype), "NONE"))
+       u->pobox = NULL;
+      else
        {
-         char *buf = malloc(strlen(u->login) + strlen(s) + 2);
-         sprintf(buf, "%s@%s", u->login, s);
-         u->pobox = buf;
+         /* If SMTP or SPLIT, get SMTP address. */
+         if (potype[0] == 'S')
+           {
+             saddr = hash_lookup(strings, bid);
+
+             /* If SMTP, clear pid and iid. */
+             if (potype[1] == 'M')
+               pid = iid = 0;
+           }
+
+         /* If IMAP, or SPLIT with IMAP, set pid to mach_id. */
+         if (potype[0] == 'I' || (potype[0] == 'S' && iid))
+           {
+             EXEC SQL SELECT mach_id INTO :pid FROM filesys
+               WHERE filsys_id = :iid;
+           }
+
+         if (pid && (s = hash_lookup(machines, pid)))
+           {
+             paddr = malloc(strlen(u->login) + strlen(s) + 2);
+             sprintf(paddr, "%s@%s", u->login, s);
+           }
+
+         if (paddr && saddr)
+           {
+             u->pobox = malloc(strlen(paddr) + strlen(saddr) + 3);
+             sprintf(u->pobox, "%s, %s", paddr, saddr);
+             free(paddr);
+           }
+         else if (paddr)
+           u->pobox = paddr;
+         else
+           u->pobox = saddr;
        }
-      else if (potype[0] ==  'S')
-       u->pobox = hash_lookup(strings, bid);
-      else
-       u->pobox = NULL;
 
       check_string(u->login);
       if (hash_store(users, id, u) < 0)
@@ -340,67 +349,67 @@ sqlerr:
 }
 
 
-void save_mlist(int id, void *list, void *force)
+void output_login(int dummy, void *user, void *out)
+{
+  struct user *u = user;
+
+  incount++;
+  if (u->pobox && check_string(u->login) && u->login[0] != '#')
+    fprintf(out, "%s: %s\n", u->login, u->pobox);
+}
+
+int line_width, alias_width;
+
+void output_mlist(int id, void *list, void *out)
 {
-  struct member *m;
   struct list *l = list, *l1;
+  struct user *u;
+  int len = strlen(l->name);
 
-  if (l->maillist > 1 || (l->maillist == 0 && !force) ||
-      !check_string(l->name))
+  if (!l->maillist || !check_string(l->name))
     return;
 
-  /* If user group appears on list, replace with user. */
+  /* If standard user group appears on a list, substitute in the user. */
   if (l->m && l->m->next == NULL && !strcasecmp(l->name, l->m->name))
-    {
-      l->maillist = 3;
-      return;
-    }
-  l->maillist = 2;
-  output_mlist(id, l);
+    return;
 
-  if (l->acl_t == 'L' && (l1 = hash_lookup(lists, l->acl_id)))
-    save_mlist(0, l1, (void *)TRUE);
+  put_fill(out, l->description);
 
-  for (m = l->m; m; m = m->next)
+  if (l->acl_t ==  'L' && (l1 = hash_lookup(lists, l->acl_id)))
     {
-      if (m->list_id && (l1 = hash_lookup(lists, m->list_id)))
-       save_mlist(0, l1, (void *)TRUE);
+      fprintf(out, "owner-%s: ", l->name);
+      if ((l1->maillist) && (strcmp(l->name, l1->name)))
+       fprintf(out, "%s\n", l1->name);
+      else
+       {
+         alias_width = line_width = len + 8;
+         output_membership(l1, out);
+         fprintf(out, "\n");
+       }
     }
-}
-
-void output_login(int dummy, void *user, void *out)
-{
-  struct user *u = user;
+  else if (l->acl_t ==  'U' && (u = hash_lookup(users, l->acl_id)))
+    fprintf(out, "owner-%s: %s\n", l->name, u->login);
 
+  fprintf(out, "%s: ", l->name);
+  alias_width = line_width = len + 2;
+  output_membership(l, out);
+  fprintf(out, "\n\n");
   incount++;
-  if (u->pobox && check_string(u->login) && u->login[0] != '#')
-    fprintf(out, "%s: %s\n", u->login, u->pobox);
 }
 
-void output_mlist(int id, struct list *l)
+void output_membership(struct list *l, FILE *out)
 {
-  struct list *l1;
   struct member *m;
-  struct user *u;
-  int line_width, alias_width, word_width, beginning;
+  struct list *l1;
+  int word_width, linestart = 1;
   static int cont = 1;
   char str[8];
 
-  put_fill(out, l->description);
-  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);
-  else
-    fprintf(out, "%s: ", l->name);
-
-  alias_width = line_width = strlen(l->name) + 2;
-  beginning = 1;
   for (m = l->m; m; m = m->next)
     {
       word_width = strlen(m->name);
 
-      if (!beginning && alias_width + word_width + 2 > MAX_ALIAS_WIDTH)
+      if (!linestart && alias_width + word_width + 2 > MAX_ALIAS_WIDTH)
        {
          /* Make a continuation. */
          sprintf(str, "%c%c%c%c%c%c", rand() % 26 + 97, rand() % 26 + 97,
@@ -409,20 +418,18 @@ void output_mlist(int id, struct list *l)
          fprintf(out, ",\n\tcont%d-%s\ncont%d-%s: ", cont, str, cont, str);
          cont++;
          alias_width = line_width = 17 + word_width;
-         fputs(m->name, out);
        }
-      else if (beginning)
+      else if (linestart)
        {
-         /* Beginning of alias, so don't wrap. */
+         /* First word on line, so we can't wrap. */
          line_width += word_width;
          alias_width = line_width;
-         fputs(m->name, out);
-         beginning = 0;
+         linestart = 0;
        }
       else if (line_width + word_width + 2 > MAX_LINE_WIDTH)
        {
          /* Wrap. */
-         fprintf(out, ",\n\t%s", m->name);
+         fputs(",\n\t", out);
          alias_width += line_width + word_width + 2;
          line_width = word_width + 8;
        }
@@ -430,13 +437,16 @@ void output_mlist(int id, struct list *l)
        {
          /* Continue line. */
          line_width += word_width + 2;
-         fprintf(out, ", %s", m->name);
+         fputs(", ", out);
        }
+
+      if (m->list_id && (l1 = hash_lookup(lists, m->list_id)) && !l1->maillist)
+       output_membership(l1, out);
+      else
+       fputs(m->name, out);
     }
   if (!l->m)
     fprintf(out, "/dev/null");
-  fprintf(out, "\n\n");
-  incount++;
 }
 
 /* Write a word-wrapped list description to the aliases file as a
@@ -493,8 +503,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.897805 seconds and 4 git commands to generate.