3 * ali.c -- list nmh mail aliases
10 #include <h/aliasbr.h>
11 #include <zotnet/mts/mts.h>
14 * maximum number of names
18 static struct swit switches[] = {
20 { "alias aliasfile", 0 },
44 extern struct aka *akahead;
49 void print_aka (char *, int, int);
50 void print_usr (char *, int, int);
54 main (int argc, char **argv)
56 int i, vecp = 0, inverted = 0, list = 0;
57 int noalias = 0, normalize = AD_NHST;
58 char *cp, **ap, **argp, buf[BUFSIZ];
59 char *vec[NVEC], **arguments;
63 setlocale(LC_ALL, "");
65 invo_name = r1bindex (argv[0], '/');
67 /* read user profile/context */
71 arguments = getarguments (invo_name, argc, argv, 1);
74 while ((cp = *argp++)) {
76 switch (smatch (++cp, switches)) {
78 ambigsw (cp, switches);
81 adios (NULL, "-%s unknown", cp);
84 snprintf (buf, sizeof(buf), "%s [switches] aliases ...",
86 print_help (buf, switches, 1);
89 print_version (invo_name);
93 if (!(cp = *argp++) || *cp == '-')
94 adios (NULL, "missing argument to %s", argp[-2]);
95 if ((i = alias (cp)) != AK_OK)
96 adios (NULL, "aliasing error in %s - %s", cp, akerror (i));
128 /* allow Aliasfile: profile entry */
129 if ((cp = context_find ("Aliasfile"))) {
132 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++)
133 if ((i = alias (*ap)) != AK_OK)
134 adios (NULL, "aliasing error in %s - %s", *ap, akerror (i));
142 * If -user is specified
146 adios (NULL, "usage: %s -user addresses ... (you forgot the addresses)",
149 for (i = 0; i < vecp; i++)
150 print_usr (vec[i], list, normalize);
156 /* print specified aliases */
157 for (i = 0; i < vecp; i++)
158 print_aka (akvalue (vec[i]), list, 0);
161 for (ak = akahead; ak; ak = ak->ak_next) {
162 printf ("%s: ", ak->ak_name);
163 pos += strlen (ak->ak_name) + 1;
164 print_aka (akresult (ak), list, pos);
172 print_aka (char *p, int list, int margin)
177 printf ("<empty>\n");
186 printf ("\n%*s", margin, "");
212 print_usr (char *s, int list, int norm)
214 register char *cp, *pp, *vp;
215 register struct aka *ak;
216 register struct mailname *mp, *np;
218 if ((pp = getname (s)) == NULL)
219 adios (NULL, "no address in \"%s\"", s);
220 if ((mp = getm (pp, NULL, 0, norm, NULL)) == NULL)
221 adios (NULL, "bad address \"%s\"", s);
226 for (ak = akahead; ak; ak = ak->ak_next) {
228 while ((cp = getname (pp))) {
229 if ((np = getm (cp, NULL, 0, norm, NULL)) == NULL)
231 if (!strcasecmp (mp->m_host, np->m_host)
232 && !strcasecmp (mp->m_mbox, np->m_mbox)) {
233 vp = vp ? add (ak->ak_name, add (",", vp))
234 : getcpy (ak->ak_name);
247 print_aka (vp ? vp : s, list, pos += strlen (s) + 1);
249 print_aka (vp ? vp : s, list, 0);