int getopt();
int status;
+#define MAXBOX 16
+
extern int h_errno;
static int match;
+static struct pobox_values boxes[MAXBOX];
+static int nboxes = 0;
uid_t getuid();
email address.", uname);
goto punt;
}
+
+ /*
+ * get a list of current boxes
+ */
+ status = sms_query("get_pobox", 1, smsarg, get_machine, NULL);
+ if (status && status != SMS_NO_MATCH) {
+ com_err(whoami, status, "while retrieving current mailboxes\n");
+ goto punt;
+ }
+
/*
* address, if it exists, is of form user@host. It needs to be split up.
*/
}
if (add) {
- printf("\nAdding email address %s@%s for %s.",
- pobox.box, pobox.machine, uname);
-
if (strcmp(pobox.type, "pop") == 0) {
+ int i;
/*
* check to be sure that they're not getting more than one. If
* they are, punt.
*/
+ for (i = 0; i < nboxes; i++) {
+ if (!strcmp(boxes[i].type, "POP")) {
+ printf("%s already has a pobox on %s\n",
+ uname, boxes[i].machine);
+ goto punt;
+ }
+ }
}
+ printf("Adding email address %s@%s for %s.",
+ pobox.box, pobox.machine, uname);
+
return_args = crunch_pobox_args(pobox);
status = sms_query("add_pobox", 4, return_args, scream,
(char *) NULL);
sms_disconnect();
exit(0);
}
- else if (delflag) { /* isn't yet checking to make sure that the
- * user isn't being left without a mailbox. */
+ else if (delflag) {
+ /* check to make sure that the
+ * user isn't being left without a mailbox. */
+ if (nboxes < 2) {
+ printf("That would leave %s without a mailbox\n", uname);
+ goto punt;
+ }
printf("Deleting email address %s@%s for %s.", pobox.box,
pobox.machine, uname);
return_args = crunch_pobox_args(pobox);
sms_disconnect();
exit(0);
}
- else { /* report all current poboxes */
- printf("Current mail address(es) for %s is/are:", uname);
- status = sms_query("get_pobox", 1, smsarg, get_machine,
- (char *) &pobox);
- if (status) {
- if (status == SMS_NO_MATCH)
- printf(" None\n");
- else {
- (void) sprintf(buf, "\nRetrieve from \
-SMS database failed.");
- goto punt;
- }
- }
+
+ printf("Current mail address%s for %s %s:\n",
+ nboxes < 2 ? "" : "es",
+ uname,
+ nboxes < 2 ? "is" : "are");
+ if (nboxes == 0)
+ printf(" None\n");
+ else {
+ int i;
+ for (i = 0; i < nboxes; i++)
+ printf(" type: %s, address: %s@%s\n", boxes[i].type,
+ boxes[i].box, boxes[i].machine);
}
+
sms_disconnect();
exit(0);
punt:
- com_err(whoami, status, buf);
+ if (status)
+ com_err(whoami, status, buf);
sms_disconnect();
exit(1);
}
int argc;
char **argv, *callarg;
{
- struct pobox_values *pobox = (struct pobox_values *) callarg;
+ struct pobox_values *pobox = &boxes[nboxes++];
pobox->type = ds(argv[1]);
pobox->machine = ds(argv[2]);
pobox->box = ds(argv[3]);
- printf("type: %s\naddress: %s@%s\n", pobox->type,
- pobox->box, pobox->machine);
return (0);
}