3 * ali.c -- list nmh mail aliases
10 #include <h/aliasbr.h>
13 * maximum number of names
17 static struct swit switches[] = {
19 { "alias aliasfile", 0 },
43 extern struct aka *akahead;
48 void print_aka (char *, int, int);
49 void print_usr (char *, int, int);
53 main (int argc, char **argv)
55 int i, vecp = 0, inverted = 0, list = 0;
56 int noalias = 0, normalize = AD_NHST;
57 char *cp, **ap, **argp, buf[BUFSIZ];
58 char *vec[NVEC], **arguments;
62 setlocale(LC_ALL, "");
64 invo_name = r1bindex (argv[0], '/');
66 /* read user profile/context */
70 arguments = getarguments (invo_name, argc, argv, 1);
73 while ((cp = *argp++)) {
75 switch (smatch (++cp, switches)) {
77 ambigsw (cp, switches);
80 adios (NULL, "-%s unknown", cp);
83 snprintf (buf, sizeof(buf), "%s [switches] aliases ...",
85 print_help (buf, switches, 1);
88 print_version (invo_name);
92 if (!(cp = *argp++) || *cp == '-')
93 adios (NULL, "missing argument to %s", argp[-2]);
94 if ((i = alias (cp)) != AK_OK)
95 adios (NULL, "aliasing error in %s - %s", cp, akerror (i));
127 /* allow Aliasfile: profile entry */
128 if ((cp = context_find ("Aliasfile"))) {
131 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++)
132 if ((i = alias (*ap)) != AK_OK)
133 adios (NULL, "aliasing error in %s - %s", *ap, akerror (i));
141 * If -user is specified
145 adios (NULL, "usage: %s -user addresses ... (you forgot the addresses)",
148 for (i = 0; i < vecp; i++)
149 print_usr (vec[i], list, normalize);
155 /* print specified aliases */
156 for (i = 0; i < vecp; i++)
157 print_aka (akvalue (vec[i]), list, 0);
160 for (ak = akahead; ak; ak = ak->ak_next) {
161 printf ("%s: ", ak->ak_name);
162 pos += strlen (ak->ak_name) + 1;
163 print_aka (akresult (ak), list, pos);
171 print_aka (char *p, int list, int margin)
176 printf ("<empty>\n");
185 printf ("\n%*s", margin, "");
211 print_usr (char *s, int list, int norm)
213 register char *cp, *pp, *vp;
214 register struct aka *ak;
215 register struct mailname *mp, *np;
217 if ((pp = getname (s)) == NULL)
218 adios (NULL, "no address in \"%s\"", s);
219 if ((mp = getm (pp, NULL, 0, norm, NULL)) == NULL)
220 adios (NULL, "bad address \"%s\"", s);
225 for (ak = akahead; ak; ak = ak->ak_next) {
227 while ((cp = getname (pp))) {
228 if ((np = getm (cp, NULL, 0, norm, NULL)) == NULL)
230 if (!strcasecmp (mp->m_host, np->m_host)
231 && !strcasecmp (mp->m_mbox, np->m_mbox)) {
232 vp = vp ? add (ak->ak_name, add (",", vp))
233 : getcpy (ak->ak_name);
246 print_aka (vp ? vp : s, list, pos += strlen (s) + 1);
248 print_aka (vp ? vp : s, list, 0);