1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
|
/*
* This code was taken from hypermail http://www.hypermail.org/
*
* license: GNU GENERAL PUBLIC LICENSE, Version 2
*
* modified by Jaakko Heinonen <jheinonen@users.sourceforge.net>
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
/*#include "hypermail.h"*/
#include "getname.h"
/*#include "setup.h"*/
/*extern char *set_domainaddr;*/
const char *set_domainaddr = "";
const int use_domainaddr = 0;
#define NAMESTRLEN 80
#define MAILSTRLEN 80
#define NONAME "(no name)"
#define NOEMAIL "(no email)"
#ifndef FALSE
# define FALSE 0
#endif
#ifndef TRUE
# define TRUE 1
#endif
#define hm_strchr(X, XX) strchr(X, XX)
#define strsav(X) ((X == NULL) ? strdup("") : strdup(X))
/*const int set_iso2022jp = 0;*/
void
strcpymax(char *dest, const char *src, int n)
{
int i;
if (n) {
n--; /* decrease one to allow for the termination byte */
for (i = 0; *src && (i < n); i++)
*dest++ = *src++;
}
*dest = 0;
}
static int
blankstring(char *str)
{
register char *cp;
for (cp = str; *cp; cp++) {
if (*cp != ' ' && *cp != '\t' && *cp != '\r'
&& *cp != '\n')
return (0);
}
return (1);
}
#if 0
char *
spamify(char *input)
{
/* we should replace the @-letter in the email
address */
int newlen = strlen(input) + 4;
char *atptr = strchr(input, '@');
if (atptr) {
char *newbuf = malloc(newlen);
int index = atptr - input;
/* copy the part before the @ */
memcpy(newbuf, input, index);
/* append _at_ */
memcpy(newbuf + index, "_at_", 4);
/* append the part after the @ */
strcpy(newbuf + index + 4, input + index + 1);
/* correct the pointer and free the old */
free(input);
return newbuf;
}
/* weird email, bail out */
return input;
}
#endif
/*
** Grabs the name and email address from a From: header.
** This could get tricky; I've tried to keep it simple.
** Should be able to handle all the addresses below:
**
** From: user [no @]
** From: kent (Kent Landfield) [no @ - with comment]
** From: <user@node.domain> [no text name, use email as text name]
** From: Kent Landfield <kent> [text name but no @]
** From: (kent) [comment - no email address]
** From: "" <kent> [email address but null comment]
** From: [blank From: line]
** From: uu.net!kent [uucp addresses - no comment]
** From: uu.net!kent (kent) [uucp addresses - with comment]
** From: "(Joe Bloggs)" <joe@anorg.com>
** From: "Roy T. Fielding" <fielding@kiwi.ics.uci.edu>
** From: kent@localhost
** From: kent@uu.net (Kent Landfield)
** From: (George Burgyan) <gburgyan@cybercon.com>
** From: <gburgyan@cybercon.com> (George Burgyan)
** From: Kent B. Landfield <kent@landfield.com>
** From: IN%"fekete+reply@c2.net" 26-JAN-1997 13:28:55.36
** From: IN%"vicric@panix.com" "Vicki Richman" 13-AUG-1996 10:54:33.38
** From: US2RMC::"lwv26@cas.org" "Larry W. Virden, x2487" 22-OCT-1994 09:44:21.44
** From: Mail Delivery Subsystem <postmaster@igc.apc.org>
** From: Self <ehasbrouck>
** From: adam@eden.apana.org.au (Adam Frey)
** From: faqserv@penguin-lust.mit.edu
** From: nc0548@freebsd.netcom.com (Mark Hittinger)
** From: "- Pam Greene, one of the *.answers moderators" <pgreene@MIT.EDU>
** From: "Felan shena Thoron'edras" <felan@netcom.com>
** From: David Muir Sharnoff <muir@idiom.com>
** From: A.J.Doherty@reading.ac.uk (Andy Doherty)
** From: Jordan Hubbard <jkh@vector.eikon.e-technik.tu-muenchen.de>
** From: ZXPAN%SLACVM.BITNET@MITVMA.MIT.EDU
** From: afs!piz!alf@uu5.psi.com (Alf the Poet)
** From: answers@cp.tn.tudelft.nl ("Moderator *.answers")
** From: mdw%merengue@merengue.oit.unc.edu (Matt Welsh)
** From: bgoffe@whale.st.usm.edu (William L. Goffe)
**
** This is an interesting new one (1998-11-26):
** From: <name.hidden@era.ericsson.se>Name.Hidden@era.ericsson.se
*/
void
getname(char *line, char **namep, char **emailp)
{
int i;
int len;
char *c;
int comment_fnd;
char email[MAILSTRLEN];
char name[NAMESTRLEN];
len = MAILSTRLEN - 1;
comment_fnd = 0;
/*
* Zero out data storage.
*/
memset(email, 0, MAILSTRLEN);
memset(name, 0, NAMESTRLEN);
*namep = NULL;
*emailp = NULL;
/* EMail Processing First:
** First, is there an '@' sign we can use as an anchor ?
*/
if ((c = hm_strchr(line, '@')) == NULL) {
/*
** No '@' sign here so ...
*/
if (strchr(line, '(')) { /* From: bob (The Big Guy) */
c = strchr(line, ':') + 1;
while (*c == ' ' || *c == '\t')
c++;
for (i = 0; *c && *c != '(' && *c != ' ' &&
*c != '\t' && *c != '\n' && i < len; c++)
email[i++] = *c;
email[i] = '\0';
} else if ((c = strchr(line, '<'))) { /* From: <kent> */
c++;
for (i = 0; *c && *c != '>' && *c != ' ' &&
*c != '\t' && *c != '\n' && i < len; c++)
email[i++] = *c;
email[i] = '\0';
} else {
/*
* - check to see if the From: line is blank, (taken care of)
* - check if From: uu.net!kent formatted line
* - check if "From: kent" formatted line
*/
c = strchr(line, ':') + 1;
while (*c == ' ' || *c == '\t')
c++;
for (i = 0; *c && *c != ' ' && *c != '\t' &&
*c != '\n' && *c != ',' && i < len; c++)
email[i++] = *c;
email[i] = '\0';
}
if (email[0] == '\0') /* Was it a junk From line ? */
strcpymax(email, NOEMAIL, MAILSTRLEN);
else if (use_domainaddr) {
/*
* check if site domainizes addresses
* but don't modify uucp addresses
*/
if ((c = strchr(email, '!')) == NULL) {
strcat(email, "@");
strcat(email, set_domainaddr);
}
}
} else {
while (*c != ' ' && *c != '\t' && *c != '<' && *c != '"' &&
*c != ':')
c--;
c++;
for (i = 0; *c && *c != '>' && *c != ' ' && *c != '\t' &&
*c != '"' && *c != '\n' && *c != ']' && *c != ',' &&
i < len; c++)
email[i++] = *c;
email[i] = '\0';
}
/*
* NAME Processing - Boy are there a bunch of funky formats here.
* No promises... I'll do my best. Let me know
* what I missed...
*/
if (strchr(line, '<')) {
c = strchr(line, ':') + 1;
while (*c == ' ' || *c == '\t')
c++;
/* if a comment then just look for the end point */
if (*c == '\"') {
int rmparen = 0;
++c;
if (*c == '(') {
++c;
rmparen = 1;
}
for (i = 0, len = NAMESTRLEN - 1;
*c && *c != '\"' && *c != '\n' && i < len;
c++)
name[i++] = *c;
if (rmparen && name[(i - 1)] == ')')
--i; /* get rid of "(name-comment)" parens */
comment_fnd = 1;
} else if (hm_strchr(line, '(')) {
c = hm_strchr(line, '(') + 1;
if (*c == '"') /* is there a comment in the comment ? */
c++;
} else if (*c == '<') { /* Comment may be on the end */
/* From: <bill@celestial.com> Bill Campbell */
c = strchr(line, '>') + 1;
for (i = 0, len = NAMESTRLEN - 1;
*c && *c != '\n' && i < len; c++)
name[i++] = *c;
comment_fnd = 1;
}
} else if (strchr(line, '(')) {
c = strchr(line, '(');
c++;
if (*c == '"') /* is there a comment in the comment ? */
c++;
while (*c == ' ' || *c == '\t')
c++;
} else if (strchr(line, '[')) {
c = strchr(line, ':') + 1;
while (*c == ' ' || *c == '\t')
c++;
for (i = 0, len = NAMESTRLEN - 1;
*c && *c != '\"' && *c != '[' && *c != '\n'
&& i < len; c++)
name[i++] = *c;
name[--i] = '\0';
comment_fnd = 1;
} else {
/*
* Is there an email address available
* that we can use for the name ?
*/
if (!strcmp(email, NOEMAIL)) /* No */
strcpymax(name, NONAME, NAMESTRLEN);
else {
c = email + strlen(email) - 1;
while (isspace((unsigned char) *c))
*c-- = '\0';
strcpymax(name, email, NAMESTRLEN); /* Yes */
}
*namep = strsav(name);
*emailp = strsav(email);
return;
}
if (!comment_fnd) {
/*int in_ascii = TRUE, esclen = 0; */
for (i = 0, len = NAMESTRLEN - 1;
*c && *c != '<' && *c != '\"' && *c != ')'
&& *c != '(' && *c != '\n' && i < len; c++) {
/*if (set_iso2022jp) {
iso2022_state(c, &in_ascii, &esclen);
if (esclen) {
for (; esclen; esclen--, c++) name[i++] = *c;
for (; in_ascii == FALSE && i < len;
c++, iso2022_state(c, &in_ascii, &esclen)) {
name[i++] = *c;
}
c--;
} else {
name[i++] = *c;
}
} else { */
name[i++] = *c;
/*} */
}
}
if (i > 0 && name[i - 1] == ' ' && (*c == '<' || *c == '('))
name[--i] = '\0';
else
name[i] = '\0';
/*
* Is the name string blank ? If so then
* force it to get filled with something.
*/
if (blankstring(name))
name[0] = '\0';
/* Bailing and taking the easy way out... */
if (name[0] == '\0') {
if (email[0] == '\0')
strcpymax(name, NONAME, NAMESTRLEN);
else
strcpymax(name, email, NAMESTRLEN);
}
/*
* need to strip spaces off the end of
* the email and name strings
*/
c = email + (strlen(email) - 1);
while (c > email && isspace((unsigned char) *c))
*c-- = '\0';
*namep = strsav(name);
*emailp = strsav(email);
}
|