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;*/
41 strcpymax(char *dest
, const char *src
, int n
)
46 n
--; /* decrease one to allow for the termination byte */
47 for (i
= 0; *src
&& (i
< n
); i
++)
54 blankstring(char *str
)
57 for (cp
= str
; *cp
; cp
++) {
58 if (*cp
!= ' ' && *cp
!= '\t' && *cp
!= '\r'
69 /* we should replace the @-letter in the email
71 int newlen
= strlen(input
) + 4;
72 char *atptr
= strchr(input
, '@');
74 char *newbuf
= malloc(newlen
);
75 int index
= atptr
- input
;
76 /* copy the part before the @ */
77 memcpy(newbuf
, input
, index
);
79 memcpy(newbuf
+ index
, "_at_", 4);
80 /* append the part after the @ */
81 strcpy(newbuf
+ index
+ 4, input
+ index
+ 1);
82 /* correct the pointer and free the old */
86 /* weird email, bail out */
92 ** Grabs the name and email address from a From: header.
93 ** This could get tricky; I've tried to keep it simple.
94 ** Should be able to handle all the addresses below:
97 ** From: kent (Kent Landfield) [no @ - with comment]
98 ** From: <user@node.domain> [no text name, use email as text name]
99 ** From: Kent Landfield <kent> [text name but no @]
100 ** From: (kent) [comment - no email address]
101 ** From: "" <kent> [email address but null comment]
102 ** From: [blank From: line]
103 ** From: uu.net!kent [uucp addresses - no comment]
104 ** From: uu.net!kent (kent) [uucp addresses - with comment]
105 ** From: "(Joe Bloggs)" <joe@anorg.com>
106 ** From: "Roy T. Fielding" <fielding@kiwi.ics.uci.edu>
107 ** From: kent@localhost
108 ** From: kent@uu.net (Kent Landfield)
109 ** From: (George Burgyan) <gburgyan@cybercon.com>
110 ** From: <gburgyan@cybercon.com> (George Burgyan)
111 ** From: Kent B. Landfield <kent@landfield.com>
112 ** From: IN%"fekete+reply@c2.net" 26-JAN-1997 13:28:55.36
113 ** From: IN%"vicric@panix.com" "Vicki Richman" 13-AUG-1996 10:54:33.38
114 ** From: US2RMC::"lwv26@cas.org" "Larry W. Virden, x2487" 22-OCT-1994 09:44:21.44
115 ** From: Mail Delivery Subsystem <postmaster@igc.apc.org>
116 ** From: Self <ehasbrouck>
117 ** From: adam@eden.apana.org.au (Adam Frey)
118 ** From: faqserv@penguin-lust.mit.edu
119 ** From: nc0548@freebsd.netcom.com (Mark Hittinger)
120 ** From: "- Pam Greene, one of the *.answers moderators" <pgreene@MIT.EDU>
121 ** From: "Felan shena Thoron'edras" <felan@netcom.com>
122 ** From: David Muir Sharnoff <muir@idiom.com>
123 ** From: A.J.Doherty@reading.ac.uk (Andy Doherty)
124 ** From: Jordan Hubbard <jkh@vector.eikon.e-technik.tu-muenchen.de>
125 ** From: ZXPAN%SLACVM.BITNET@MITVMA.MIT.EDU
126 ** From: afs!piz!alf@uu5.psi.com (Alf the Poet)
127 ** From: answers@cp.tn.tudelft.nl ("Moderator *.answers")
128 ** From: mdw%merengue@merengue.oit.unc.edu (Matt Welsh)
129 ** From: bgoffe@whale.st.usm.edu (William L. Goffe)
131 ** This is an interesting new one (1998-11-26):
132 ** From: <name.hidden@era.ericsson.se>›Name.Hidden@era.ericsson.seœ
136 getname(char *line
, char **namep
, char **emailp
)
143 char email
[MAILSTRLEN
];
144 char name
[NAMESTRLEN
];
146 len
= MAILSTRLEN
- 1;
150 * Zero out data storage.
152 memset(email
, 0, MAILSTRLEN
);
153 memset(name
, 0, NAMESTRLEN
);
158 /* EMail Processing First:
159 ** First, is there an '@' sign we can use as an anchor ?
161 if ((c
= hm_strchr(line
, '@')) == NULL
) {
163 ** No '@' sign here so ...
165 if (strchr(line
, '(')) { /* From: bob (The Big Guy) */
166 c
= strchr(line
, ':') + 1;
167 while (*c
== ' ' || *c
== '\t')
169 for (i
= 0; *c
&& *c
!= '(' && *c
!= ' ' &&
170 *c
!= '\t' && *c
!= '\n' && i
< len
; c
++)
173 } else if ((c
= strchr(line
, '<'))) { /* From: <kent> */
175 for (i
= 0; *c
&& *c
!= '>' && *c
!= ' ' &&
176 *c
!= '\t' && *c
!= '\n' && i
< len
; c
++)
181 * - check to see if the From: line is blank, (taken care of)
182 * - check if From: uu.net!kent formatted line
183 * - check if "From: kent" formatted line
185 c
= strchr(line
, ':') + 1;
186 while (*c
== ' ' || *c
== '\t')
188 for (i
= 0; *c
&& *c
!= ' ' && *c
!= '\t' &&
189 *c
!= '\n' && *c
!= ',' && i
< len
; c
++)
195 if (email
[0] == '\0') /* Was it a junk From line ? */
196 strcpymax(email
, NOEMAIL
, MAILSTRLEN
);
198 else if (use_domainaddr
) {
200 * check if site domainizes addresses
201 * but don't modify uucp addresses
203 if ((c
= strchr(email
, '!')) == NULL
) {
205 strcat(email
, set_domainaddr
);
209 while (*c
!= ' ' && *c
!= '\t' && *c
!= '<' && *c
!= '"' &&
213 for (i
= 0; *c
&& *c
!= '>' && *c
!= ' ' && *c
!= '\t' &&
214 *c
!= '"' && *c
!= '\n' && *c
!= ']' && *c
!= ',' &&
221 * NAME Processing - Boy are there a bunch of funky formats here.
222 * No promises... I'll do my best. Let me know
226 if (strchr(line
, '<')) {
227 c
= strchr(line
, ':') + 1;
228 while (*c
== ' ' || *c
== '\t')
231 /* if a comment then just look for the end point */
241 for (i
= 0, len
= NAMESTRLEN
- 1;
242 *c
&& *c
!= '\"' && *c
!= '\n' && i
< len
;
246 if (rmparen
&& name
[(i
- 1)] == ')')
247 --i
; /* get rid of "(name-comment)" parens */
250 } else if (hm_strchr(line
, '(')) {
251 c
= hm_strchr(line
, '(') + 1;
252 if (*c
== '"') /* is there a comment in the comment ? */
254 } else if (*c
== '<') { /* Comment may be on the end */
255 /* From: <bill@celestial.com> Bill Campbell */
256 c
= strchr(line
, '>') + 1;
257 for (i
= 0, len
= NAMESTRLEN
- 1;
258 *c
&& *c
!= '\n' && i
< len
; c
++)
263 } else if (strchr(line
, '(')) {
264 c
= strchr(line
, '(');
266 if (*c
== '"') /* is there a comment in the comment ? */
268 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'
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
!= ')'
304 && *c
!= '(' && *c
!= '\n' && i
< len
; c
++) {
305 /*if (set_iso2022jp) {
306 iso2022_state(c, &in_ascii, &esclen);
308 for (; esclen; esclen--, c++) name[i++] = *c;
309 for (; in_ascii == FALSE && i < len;
310 c++, iso2022_state(c, &in_ascii, &esclen)) {
323 if (i
> 0 && name
[i
- 1] == ' ' && (*c
== '<' || *c
== '('))
329 * Is the name string blank ? If so then
330 * force it to get filled with something.
332 if (blankstring(name
))
335 /* Bailing and taking the easy way out... */
337 if (name
[0] == '\0') {
338 if (email
[0] == '\0')
339 strcpymax(name
, NONAME
, NAMESTRLEN
);
341 strcpymax(name
, email
, NAMESTRLEN
);
345 * need to strip spaces off the end of
346 * the email and name strings
349 c
= email
+ (strlen(email
) - 1);
350 while (c
> email
&& isspace((unsigned char) *c
))
353 *namep
= strsav(name
);
354 *emailp
= strsav(email
);