3 * This code was taken from hypermail http://www.hypermail.org/
5 * license: GNU GENERAL PUBLIC LICENSE, Version 2
7 * modified by Jaakko Heinonen <jheinonen@users.sourceforge.net>
13 /*#include "hypermail.h"*/
15 /*#include "setup.h"*/
17 /*extern char *set_domainaddr;*/
18 const char *set_domainaddr = "";
19 const int use_domainaddr = 0;
24 #define NONAME "(no name)"
25 #define NOEMAIL "(no email)"
35 #define hm_strchr(X, XX) strchr(X, XX)
36 #define strsav(X) ((X == NULL) ? strdup("") : strdup(X))
38 /*const int set_iso2022jp = 0;*/
40 void strcpymax(char *dest, const char *src, int n)
45 n--; /* decrease one to allow for the termination byte */
46 for (i = 0; *src && (i < n); i++)
52 static int blankstring(char *str)
55 for (cp = str; *cp; cp++) {
56 if (*cp != ' ' && *cp != '\t' && *cp != '\r' && *cp != '\n')
63 char *spamify(char *input)
65 /* we should replace the @-letter in the email
67 int newlen=strlen(input)+4;
68 char *atptr=strchr(input, '@');
70 char *newbuf = malloc(newlen);
71 int index=atptr-input;
72 /* copy the part before the @ */
73 memcpy(newbuf, input, index);
75 memcpy(newbuf+index, "_at_", 4);
76 /* append the part after the @ */
77 strcpy(newbuf+index+4, input+index+1);
78 /* correct the pointer and free the old */
82 /* weird email, bail out */
88 ** Grabs the name and email address from a From: header.
89 ** This could get tricky; I've tried to keep it simple.
90 ** Should be able to handle all the addresses below:
93 ** From: kent (Kent Landfield) [no @ - with comment]
94 ** From: <user@node.domain> [no text name, use email as text name]
95 ** From: Kent Landfield <kent> [text name but no @]
96 ** From: (kent) [comment - no email address]
97 ** From: "" <kent> [email address but null comment]
98 ** From: [blank From: line]
99 ** From: uu.net!kent [uucp addresses - no comment]
100 ** From: uu.net!kent (kent) [uucp addresses - with comment]
101 ** From: "(Joe Bloggs)" <joe@anorg.com>
102 ** From: "Roy T. Fielding" <fielding@kiwi.ics.uci.edu>
103 ** From: kent@localhost
104 ** From: kent@uu.net (Kent Landfield)
105 ** From: (George Burgyan) <gburgyan@cybercon.com>
106 ** From: <gburgyan@cybercon.com> (George Burgyan)
107 ** From: Kent B. Landfield <kent@landfield.com>
108 ** From: IN%"fekete+reply@c2.net" 26-JAN-1997 13:28:55.36
109 ** From: IN%"vicric@panix.com" "Vicki Richman" 13-AUG-1996 10:54:33.38
110 ** From: US2RMC::"lwv26@cas.org" "Larry W. Virden, x2487" 22-OCT-1994 09:44:21.44
111 ** From: Mail Delivery Subsystem <postmaster@igc.apc.org>
112 ** From: Self <ehasbrouck>
113 ** From: adam@eden.apana.org.au (Adam Frey)
114 ** From: faqserv@penguin-lust.mit.edu
115 ** From: nc0548@freebsd.netcom.com (Mark Hittinger)
116 ** From: "- Pam Greene, one of the *.answers moderators" <pgreene@MIT.EDU>
117 ** From: "Felan shena Thoron'edras" <felan@netcom.com>
118 ** From: David Muir Sharnoff <muir@idiom.com>
119 ** From: A.J.Doherty@reading.ac.uk (Andy Doherty)
120 ** From: Jordan Hubbard <jkh@vector.eikon.e-technik.tu-muenchen.de>
121 ** From: ZXPAN%SLACVM.BITNET@MITVMA.MIT.EDU
122 ** From: afs!piz!alf@uu5.psi.com (Alf the Poet)
123 ** From: answers@cp.tn.tudelft.nl ("Moderator *.answers")
124 ** From: mdw%merengue@merengue.oit.unc.edu (Matt Welsh)
125 ** From: bgoffe@whale.st.usm.edu (William L. Goffe)
127 ** This is an interesting new one (1998-11-26):
128 ** From: <name.hidden@era.ericsson.se>
\9bName.Hidden@era.ericsson.se
\9c
131 void getname(char *line, char **namep, char **emailp)
138 char email[MAILSTRLEN];
139 char name[NAMESTRLEN];
141 len = MAILSTRLEN - 1;
145 * Zero out data storage.
147 memset(email, 0, MAILSTRLEN);
148 memset(name, 0, NAMESTRLEN);
153 /* EMail Processing First:
154 ** First, is there an '@' sign we can use as an anchor ?
156 if ((c = hm_strchr(line, '@')) == NULL) {
158 ** No '@' sign here so ...
160 if (strchr(line, '(')) { /* From: bob (The Big Guy) */
161 c = strchr(line, ':') + 1;
162 while (*c == ' ' || *c == '\t')
164 for (i = 0; *c && *c != '(' && *c != ' ' &&
165 *c != '\t' && *c != '\n' && i < len; c++)
169 else if ((c = strchr(line, '<'))) { /* From: <kent> */
171 for (i = 0; *c && *c != '>' && *c != ' ' &&
172 *c != '\t' && *c != '\n' && i < len; c++)
178 * - check to see if the From: line is blank, (taken care of)
179 * - check if From: uu.net!kent formatted line
180 * - check if "From: kent" formatted line
182 c = strchr(line, ':') + 1;
183 while (*c == ' ' || *c == '\t')
185 for (i = 0; *c && *c != ' ' && *c != '\t' &&
186 *c != '\n' && *c != ',' && i < len; c++)
192 if (email[0] == '\0') /* Was it a junk From line ? */
193 strcpymax(email, NOEMAIL, MAILSTRLEN);
195 else if (use_domainaddr) {
197 * check if site domainizes addresses
198 * but don't modify uucp addresses
200 if ((c = strchr(email, '!')) == NULL) {
202 strcat(email, set_domainaddr);
207 while (*c != ' ' && *c != '\t' && *c != '<' && *c != '"' &&
210 for (i = 0; *c && *c != '>' && *c != ' ' && *c != '\t' &&
211 *c != '"' && *c != '\n' && *c != ']' && *c != ',' &&
218 * NAME Processing - Boy are there a bunch of funky formats here.
219 * No promises... I'll do my best. Let me know
223 if (strchr(line, '<')) {
224 c = strchr(line, ':') + 1;
225 while (*c == ' ' || *c == '\t')
228 /* if a comment then just look for the end point */
238 for (i = 0, len = NAMESTRLEN - 1;
239 *c && *c != '\"' && *c != '\n' && i < len; c++)
242 if (rmparen && name[(i - 1)] == ')')
243 --i; /* get rid of "(name-comment)" parens */
247 else if (hm_strchr(line, '(')) {
248 c = hm_strchr(line, '(') + 1;
249 if (*c == '"') /* is there a comment in the comment ? */
252 else if (*c == '<') { /* Comment may be on the end */
253 /* From: <bill@celestial.com> Bill Campbell */
254 c = strchr(line, '>') + 1;
255 for (i = 0, len = NAMESTRLEN - 1; *c && *c != '\n' && i < len;
262 else if (strchr(line, '(')) {
263 c = strchr(line, '(');
265 if (*c == '"') /* is there a comment in the comment ? */
267 while (*c == ' ' || *c == '\t')
270 else if (strchr(line, '[')) {
271 c = strchr(line, ':') + 1;
272 while (*c == ' ' || *c == '\t')
275 for (i = 0, len = NAMESTRLEN - 1;
276 *c && *c != '\"' && *c != '[' && *c != '\n' && i < len; c++)
284 * Is there an email address available
285 * that we can use for the name ?
287 if (!strcmp(email, NOEMAIL)) /* No */
288 strcpymax(name, NONAME, NAMESTRLEN);
290 c = email + strlen(email) - 1;
291 while (isspace((unsigned char)*c))
293 strcpymax(name, email, NAMESTRLEN); /* Yes */
295 *namep = strsav(name);
296 *emailp = strsav(email);
301 /*int in_ascii = TRUE, esclen = 0;*/
302 for (i = 0, len = NAMESTRLEN - 1;
303 *c && *c != '<' && *c != '\"' && *c != ')' && *c != '(' &&
304 *c != '\n' && i < len; c++)
306 /*if (set_iso2022jp) {
307 iso2022_state(c, &in_ascii, &esclen);
309 for (; esclen; esclen--, c++) name[i++] = *c;
310 for (; in_ascii == FALSE && i < len;
311 c++, iso2022_state(c, &in_ascii, &esclen)) {
324 if (i > 0 && name[i-1] == ' ' && (*c == '<' || *c == '('))
330 * Is the name string blank ? If so then
331 * force it to get filled with something.
333 if (blankstring(name))
336 /* Bailing and taking the easy way out... */
338 if (name[0] == '\0') {
339 if (email[0] == '\0')
340 strcpymax(name, NONAME, NAMESTRLEN);
342 strcpymax(name, email, NAMESTRLEN);
346 * need to strip spaces off the end of
347 * the email and name strings
350 c = email + (strlen(email) - 1);
351 while (c > email && isspace((unsigned char)*c))
354 *namep = strsav(name);
355 *emailp = strsav(email);