3 * Shared routines for pobox changing.
5 * Copyright (C) 1999 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
13 #include "mrclient-internal.h"
23 static int save_sloc_machine(int argc, char **argv, void *sq);
24 static int save_alias_value(int argc, char **argv, void *sq);
29 #define strtok_r(s, tokens, resume) strtok(s, tokens)
32 int mrcl_validate_pobox_smtp(char *user, char *address, char **ret)
34 char *addr, *retaddr, *p, *lasts = NULL;
35 char *machine = NULL, *m;
36 int oldlen, len, status = MRCL_SUCCESS;
38 /* Make a private copy of address that we can mangle. */
39 addr = strdup(address);
44 /* For each comma-delimited address, canonicalize the hostname and
45 * verify that the address won't cause mail problems.
47 for (p = strtok_r(addr, ", ", &lasts); p; p = strtok_r(NULL, ",", &lasts))
52 *m++ = '\0'; /* get rid of the @ sign */
53 m = strtrim(m); /* get rid of whitespace */
57 mrcl_set_message("No at sign (@) in address \"%s\".", p);
64 machine = canonicalize_hostname(strdup(m));
68 mrcl_set_message("No hostname in address \"%s@\".", p);
73 switch (mailtype(machine))
76 mrcl_set_message("Cannot forward mail to IMAP server %s.\n "
77 "Use \"chpobox -p\" if you are trying to unset "
78 "your mail forwarding.", machine);
85 mrcl_set_message("The name on the POP box (%s) must match "
86 "the username (%s).", p, user);
93 if ((m = strchr(machine, '.')))
95 machine = realloc(machine, strlen(machine) + 6);
96 strcat(machine, ".LOCAL");
99 case MAILTYPE_MAILHUB:
100 if (!strcmp(p, user))
102 mrcl_set_message("The address \"%s@%s\" would create a mail "
103 "loop.\nSet a POP pobox if you want local "
104 "mail delivery.", p, machine);
105 status = MRCL_REJECT;
110 mrcl_set_message("Cannot forward mail to a local mailing "
111 "address (%s@%s).", p, machine);
112 status = MRCL_REJECT;
117 if (*m != '"' && strcasecmp(m, machine))
119 mrcl_set_message("Warning: hostname %s canonicalized to %s\n",
125 status = MRCL_MOIRA_ERROR;
130 len += (oldlen > 1 ? 2 : 0) + strlen(p) + strlen(machine) + 1;
131 retaddr = realloc(retaddr, len);
132 sprintf(retaddr + oldlen - 1, "%s%s@%s", oldlen > 1 ? ", " : "",
135 machine = NULL; /* Make sure it doesn't get freed again later. */
140 if (status == MRCL_SUCCESS)
149 static int save_sloc_machine(int argc, char **argv, void *sq)
151 sq_save_data(sq, strdup(argv[1]));
155 static int save_alias_value(int argc, char **argv, void *sq)
157 sq_save_data(sq, strdup(argv[2]));