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>
41 int get_pobox(int argc, char **argv, void *callarg);
48 int main(int argc, char *argv[])
51 char *address, *uname;
52 int c, setflag, splitflag, prevflag, status;
54 setflag = splitflag = prevflag = 0;
55 address = uname = NULL;
57 if ((whoami = strrchr(argv[0], '/')) == NULL)
65 while ((c = getopt(argc, argv, "s:S:pu:")) != -1)
90 if (argc == 2 && optind == 1 && !uname)
91 uname = argv[optind++];
93 if (optind != argc || (prevflag + splitflag + setflag > 1))
98 uname = mrcl_krb_user();
104 if (mrcl_connect(NULL, "chpobox", 2, 1) != MRCL_SUCCESS)
107 if (setflag || splitflag)
110 if (mrcl_validate_pobox_smtp(uname, address, &addr) != MRCL_SUCCESS)
115 mrarg[1] = setflag ? "SMTP" : "SPLIT";
117 status = mr_query("set_pobox", 3, mrarg, NULL, NULL);
121 com_err(whoami, status,
122 "while setting pobox for %s to type %s, box %s",
123 mrarg[0], mrarg[1], mrarg[2]);
128 status = mr_query("set_pobox_pop", 1, mrarg, NULL, NULL);
129 if (status == MR_MACHINE)
132 "Moira has no record of a previous POP box for %s\n", uname);
134 else if (status != 0)
135 com_err(whoami, status, "while setting pobox");
142 status = mr_query("get_pobox", 1, mrarg, get_pobox, NULL);
143 if (status == MR_NO_MATCH)
144 printf("User %s has no pobox.\n", uname);
145 else if (status != 0)
146 com_err(whoami, status, "while retrieving current mailbox");
153 * get_pobox gets all your poboxes and displays them.
156 int get_pobox(int argc, char **argv, void *callarg)
158 if (!strcmp(argv[1], "SMTP"))
160 printf("User %s, Type %s, Box: %s\n",
161 argv[0], argv[1], argv[2]);
165 printf("User %s, Type %s, Box: %s (%s)\n",
166 argv[0], argv[1], argv[2], argv[3]);
170 printf("User %s, Type %s, Box: %s@%s\n",
171 argv[0], argv[1], argv[0], argv[2]);
173 printf(" Modified by %s on %s with %s\n",
174 argv[argc - 2], argv[argc - 3], argv[argc - 1]);
180 fprintf(stderr, "Usage: %s [-s address] [-p] [-u user]\n", whoami);