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 status = mrcl_validate_pobox_smtp(uname, address, &addr);
111 if (mrcl_get_message())
112 mrcl_com_err(whoami);
113 if (status != MRCL_SUCCESS)
118 mrarg[1] = setflag ? "SMTP" : "SPLIT";
120 status = mr_query("set_pobox", 3, mrarg, NULL, NULL);
124 com_err(whoami, status,
125 "while setting pobox for %s to type %s, box %s",
126 mrarg[0], mrarg[1], mrarg[2]);
131 status = mr_query("set_pobox_pop", 1, mrarg, NULL, NULL);
132 if (status == MR_MACHINE)
135 "Moira has no record of a previous POP box for %s\n", uname);
137 else if (status != 0)
138 com_err(whoami, status, "while setting pobox");
145 status = mr_query("get_pobox", 1, mrarg, get_pobox, NULL);
146 if (status == MR_NO_MATCH)
147 printf("User %s has no pobox.\n", uname);
148 else if (status != 0)
149 mrcl_com_err(whoami);
156 * get_pobox gets all your poboxes and displays them.
159 int get_pobox(int argc, char **argv, void *callarg)
161 if (!strcmp(argv[1], "SMTP"))
163 printf("User %s, Type %s, Box: %s\n",
164 argv[0], argv[1], argv[2]);
168 printf("User %s, Type %s, Box: %s (%s)\n",
169 argv[0], argv[1], argv[2], argv[3]);
173 printf("User %s, Type %s, Box: %s@%s\n",
174 argv[0], argv[1], argv[0], argv[2]);
176 printf(" Modified by %s on %s with %s\n",
177 argv[argc - 2], argv[argc - 3], argv[argc - 1]);
183 fprintf(stderr, "Usage: %s [-s|-S address] [-p] [-u user]\n", whoami);