]>
diplodocus.org Git - nmh/blob - uip/ali.c
3 * ali.c -- list nmh mail aliases
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
13 #include <h/addrsbr.h>
14 #include <h/aliasbr.h>
19 * maximum number of names
23 static struct swit switches
[] = {
25 { "alias aliasfile", 0 },
49 extern struct aka
*akahead
;
54 static void print_aka (char *, int, int);
55 static void print_usr (char *, int, int);
59 main (int argc
, char **argv
)
61 int i
, vecp
= 0, inverted
= 0, list
= 0;
62 int noalias
= 0, normalize
= AD_NHST
;
63 char *cp
, **ap
, **argp
, buf
[BUFSIZ
];
64 char *vec
[NVEC
], **arguments
;
68 setlocale(LC_ALL
, "");
70 invo_name
= r1bindex (argv
[0], '/');
72 /* read user profile/context */
76 arguments
= getarguments (invo_name
, argc
, argv
, 1);
79 while ((cp
= *argp
++)) {
81 switch (smatch (++cp
, switches
)) {
83 ambigsw (cp
, switches
);
86 adios (NULL
, "-%s unknown", cp
);
89 snprintf (buf
, sizeof(buf
), "%s [switches] aliases ...",
91 print_help (buf
, switches
, 1);
94 print_version (invo_name
);
98 if (!(cp
= *argp
++) || *cp
== '-')
99 adios (NULL
, "missing argument to %s", argp
[-2]);
100 if ((i
= alias (cp
)) != AK_OK
)
101 adios (NULL
, "aliasing error in %s - %s", cp
, akerror (i
));
133 /* allow Aliasfile: profile entry */
134 if ((cp
= context_find ("Aliasfile"))) {
137 for (ap
= brkstring(dp
= getcpy(cp
), " ", "\n"); ap
&& *ap
; ap
++)
138 if ((i
= alias (*ap
)) != AK_OK
)
139 adios (NULL
, "aliasing error in %s - %s", *ap
, akerror (i
));
147 * If -user is specified
151 adios (NULL
, "usage: %s -user addresses ... (you forgot the addresses)",
154 for (i
= 0; i
< vecp
; i
++)
155 print_usr (vec
[i
], list
, normalize
);
161 /* print specified aliases */
162 for (i
= 0; i
< vecp
; i
++)
163 print_aka (akvalue (vec
[i
]), list
, 0);
166 for (ak
= akahead
; ak
; ak
= ak
->ak_next
) {
167 printf ("%s: ", ak
->ak_name
);
168 pos
+= strlen (ak
->ak_name
) + 1;
169 print_aka (akresult (ak
), list
, pos
);
177 print_aka (char *p
, int list
, int margin
)
182 printf ("<empty>\n");
191 printf ("\n%*s", margin
, "");
217 print_usr (char *s
, int list
, int norm
)
219 register char *cp
, *pp
, *vp
;
220 register struct aka
*ak
;
221 register struct mailname
*mp
, *np
;
223 if ((pp
= getname (s
)) == NULL
)
224 adios (NULL
, "no address in \"%s\"", s
);
225 if ((mp
= getm (pp
, NULL
, 0, norm
, NULL
)) == NULL
)
226 adios (NULL
, "bad address \"%s\"", s
);
231 for (ak
= akahead
; ak
; ak
= ak
->ak_next
) {
233 while ((cp
= getname (pp
))) {
234 if ((np
= getm (cp
, NULL
, 0, norm
, NULL
)) == NULL
)
236 if (!mh_strcasecmp (mp
->m_host
, np
->m_host
)
237 && !mh_strcasecmp (mp
->m_mbox
, np
->m_mbox
)) {
238 vp
= vp
? add (ak
->ak_name
, add (",", vp
))
239 : getcpy (ak
->ak_name
);
252 print_aka (vp
? vp
: s
, list
, pos
+= strlen (s
) + 1);
254 print_aka (vp
? vp
: s
, list
, 0);