3 * Talk to the Moira database to change a person's home mail machine. This may
4 * be an Athena machine, or a completely arbitrary address.
6 * chpobox with no modifiers reports the current mailbox.
8 * chpobox -s address means set the mailbox to this address.
10 * chpobox -p restores the pobox to a previous POP/IMAP box, if there was one.
12 * chpobox -S address means split mail between POP/IMAP and SMTP
14 * chpobox -u [user] is needed if you are logged in as one user, but
15 * are trying to change the email address of another. You must have
16 * Kerberos tickets as the person whose address you are trying to
17 * change, or the attempt will fail.
19 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
20 * For copying and distribution information, please see the file
24 #include <mit-copyright.h>
26 #include <moira_site.h>
39 #define argis(a, b) (!strcmp(*arg + 1, a) || !strcmp(*arg + 1, b))
43 int get_pobox(int argc, char **argv, void *callarg);
50 int main(int argc, char *argv[])
53 char *address, *uname;
56 int c, setflag, splitflag, prevflag, status;
58 setflag = splitflag = prevflag = 0;
59 address = uname = NULL;
61 if ((whoami = strrchr(argv[0], '/')) == NULL)
69 while (++arg - argv < argc)
73 if (argis("s", "set")) {
74 if (arg - argv < argc - 1) {
81 else if (argis("S", "split")) {
82 if (arg - argv < argc - 1) {
89 else if (argis("p", "previous"))
91 else if (argis("u", "username")) {
92 if (arg - argv < argc - 1) {
98 else if (argis("db", "database")) {
99 if (arg - argv < argc - 1) {
106 else if (uname == NULL)
112 if (prevflag + splitflag + setflag > 1)
117 uname = mrcl_krb_user();
123 if (mrcl_connect(server, "chpobox", 2, 1) != MRCL_SUCCESS)
126 if (setflag || splitflag)
129 status = mrcl_validate_pobox_smtp(uname, address, &addr);
130 if (mrcl_get_message())
131 mrcl_com_err(whoami);
132 if (status != MRCL_SUCCESS)
137 mrarg[1] = setflag ? "SMTP" : "SPLIT";
139 status = mr_query("set_pobox", 3, mrarg, NULL, NULL);
143 com_err(whoami, status,
144 "while setting pobox for %s to type %s, box %s",
145 mrarg[0], mrarg[1], mrarg[2]);
150 status = mr_query("set_pobox_pop", 1, mrarg, NULL, NULL);
151 if (status == MR_MACHINE)
154 "Moira has no record of a previous POP box for %s\n", uname);
156 else if (status != 0)
157 com_err(whoami, status, "while setting pobox");
164 status = mr_query("get_pobox", 1, mrarg, get_pobox, NULL);
165 if (status == MR_NO_MATCH)
166 printf("User %s has no pobox.\n", uname);
167 else if (status != 0)
168 mrcl_com_err(whoami);
175 * get_pobox gets all your poboxes and displays them.
178 int get_pobox(int argc, char **argv, void *callarg)
180 if (!strcmp(argv[1], "SMTP"))
182 printf("User %s, Type %s, Box: %s\n",
183 argv[0], argv[1], argv[2]);
187 printf("User %s, Type %s, Box: %s (%s)\n",
188 argv[0], argv[1], argv[2], argv[3]);
192 printf("User %s, Type %s, Box: %s@%s\n",
193 argv[0], argv[1], argv[0], argv[2]);
195 printf(" Modified by %s on %s with %s\n",
196 argv[argc - 2], argv[argc - 3], argv[argc - 1]);
202 fprintf(stderr, "Usage: %s [-s|-S address] [-p] [-u user] [-db database]\n", whoami);