home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
341b.lha
/
uucp1_v1.03d
/
src
/
MUtil
/
from.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-28
|
2KB
|
137 lines
/*
* FROM.C
*
* FROM [user]
*
* Displays From: and Subject fields, attempts to find personal name
* in From: field. If user not specified searches UULIB:Config
* for UserName.
*/
#include <stdio.h>
#include <stdlib.h>
#include <config.h>
#include "/version.h"
IDENT(".00");
void FromUser();
char *ExtractPersonalName();
void
main(ac, av)
char *av[];
{
char haduser = 0;
short i;
for (i = 1; i < ac; ++i) {
if (av[i][0] != '-') {
haduser = 1;
FromUser(av[i]);
}
}
if (haduser == 0) {
char *user;
if (user = FindConfig(USERNAME))
FromUser(user);
else
printf("UULIB:Config, no 'UserName' entry!\n");
}
}
void
FromUser(user)
char *user;
{
static char Buf[256];
static char FromLine[256];
static char SubjLine[256];
char *file = malloc(strlen(user) + 32);
char *fromstr;
FILE *fi;
sprintf(file, "UUMAIL:%s", user);
if (fi = fopen(file, "r")) {
while (fgets(Buf, 256, fi)) {
/*
* Start of message
*/
if (strncmp(Buf, "From ", 5) != 0)
continue;
/*
* Scan headers for From: and Subject:
* Headers end with a blank line.
*/
FromLine[0] = 0;
SubjLine[0] = '\n';
SubjLine[1] = 0;
while (fgets(Buf, 256, fi) && Buf[0] != '\n') {
if (strncmp(Buf, "From:", 5) == 0)
strcpy(FromLine, Buf + 5);
if (strncmp(Buf, "Subject:", 8) == 0)
strcpy(SubjLine, Buf + 8);
}
fromstr = ExtractPersonalName(FromLine);
printf("%-20s %s", fromstr, SubjLine);
}
}
}
/*
* Search for (name) or name <addr> or <addr> name
*/
char *
ExtractPersonalName(str)
char *str;
{
char *p1, *p2;
char sp = 1;
for (p1 = str; *p1; ++p1) {
if (*p1 == '<') {
if (sp == 0) { /* name before <addr> */
p2 = p1 - 1;
p1 = str;
break;
}
/* name after <addr> */
while (*p1 && *p1 != '>')
++p1;
if (*p1 == '>')
++p1;
p2 = str + strlen(str) - 1;
break;
}
if (*p1 == '(') {
++p1;
for (p2 = p1; *p2 && *p2 != ')'; ++p2);
if (*p2 == ')')
--p2;
break;
}
if (*p1 != ' ' && *p1 != 9)
sp = 0;
}
if (*p1 == 0) { /* could find a personal name! */
p1 = str;
p2 = str + strlen(str) - 1;
}
while (p2 >= p1 && (*p2 == '\n' || *p2 == ' ' || *p2 == 9))
--p2;
++p2;
if (p2 < p1)
p2 = p1;
*p2 = 0;
return(p1);
}