home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
b
/
bmh02src.zip
/
SCAN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-19
|
5KB
|
220 lines
/*
scan.c : Copyright Paul Healy, EI9GL, 1992.
911227 : Added this header
920620 : Version 0.1
- doesn't remember current folder
- doesn't support listing of a subrange
920706 : Added check to see if specified folder exists
920717 : Added ax25 pbbs R: line disposal
920721 : Fixed bug in listing short messages ("\nF" was not being found)
920819 : Catered for variation in the Date: header contents
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <io.h>
#include "header.h"
#include "buffer.h"
#include "rc.h"
#include "misc.h"
#include "help.h"
#include "pager.h"
#include "current.h"
#ifdef BMH
#define main scan_main
#endif
static char *
name(char *from)
{
char *p, *q;
if ( (p=strchr(from, '(')) != NULL) {
if ( (q=strchr(p, ')')) != NULL)
*q='\0';
else
return from;
return p+1;
}
if ( (p=strchr(from, '"')) != NULL) {
if ( (q=strchr(p+1, '"')) != NULL)
*q='\0';
else
return from;
return p+1;
}
return from;
}
static char *
topic(char **start, char **end, char *subject, char *line)
{
int len = 0;
char *p = *start, *e = *end, *l = line;
while ((*line++ = *subject++) > 0) { /* tcc doesn't like this line */
len++;
if (len>46) {
*line = '\0';
return l;
}
}
line--;
*line++ = '<';
*line++ = '<';
while (p<e) {
*line = *p++;
/*
* 920717 : Dispose of ax25 pbbs R: lines
*/
if ((*(p-1)=='R') && (*(p-2)=='\n') && (*p==':')) {
char s[256];
(void) getstring(&p, &e, s, sizeof(s));
continue;
}
if ((*p == 'F') && ( *(p-1) == '\n') ) {
*line++ = '>';
*line++ = '>';
p--;
break; /* can't risk calling refill, as that would mean missing the */
} /* next message... */
if ((*line == '\n') || (*line == '\r') || (*line == 9) ) /* tab */
*line = ' ';
if (isspace(*line) && isspace(*(line-1)))
continue;
line++;
len++;
if (len>45)
break;
if ( (p==e) && (refill(&p, &e) != 0) )
break;
}
if ((p==e) && (len<43)) {
*line++ = '>';
*line++ = '>';
}
*line++ = '\0';
*start = p;
*end = e;
return l;
}
static int
asc2month(char *s)
{
char *result;
static char m[][4] = {
"Apr", "Aug", "Dec", "Feb", "Jan", "Jul",
"Jun", "Mar", "May", "Nov", "Oct", "Sep" };
static char m2num[] = {4, 8, 12, 2, 1, 7, 6, 3, 5, 11, 10, 9 };
result = (char *) bsearch(s, m, 12, 4, strcmp);
return result == NULL ? 0 : (int) m2num[( (result - (char *) m) / 4 )];
}
static void
date2mh(char *date, int *day, int *month)
{
if ( strlen(date) < 18) {
*day = 0;
*month = 0;
return ;
}
else
date[17] = '\0';
if ( (*day = atoi(&date[11])) == 0) {
/*
* bogon?
* Date: 06 Jan 91 17:30:20 UTC
* 0123456789
*/
*day = atoi(&date[6]);
*month = asc2month(&date[9]);
}
else
/*
* Normal one
* Date: Sun, 06 Jan 91 17:30:20 UTC
* 012345678901234
*/
*month = asc2month(&date[14]);
}
static int
dumpmsg(int i, char **start, char **end, int msg)
{
char *argv[MAXHDR], line[256], buf[256];
int day = 0, month = 0;
if ( parseheader(start, end, argv) == -1) {
fprintf(stderr, "dumpmsg: bad header on message %d\n", i);
return -1;
}
if (argv[DATE] != NULL)
date2mh(argv[DATE], &day, &month);
sprintf(buf, "%c%4d %2d/%02d %-18.18s %s",
i == msg ? '+' : ' ',
i, day, month,
argv[FROM] == NULL ? "" : name(argv[FROM]+6),
topic(start, end, argv[SUBJECT] == NULL ? "" : argv[SUBJECT]+9, line ) );
freeheader(argv);
if ( page_puts(buf) == -1)
return -2;
return 0;
}
static void
listmsgs(char *p, char *end, int msg)
{
int i = 0;
page_setup();
while (1) {
while ( *p != 'F' )
p++;
if ( (p==end) && (refill(&p, &end) != 0) )
break;
else { /* may have found a From */
char s[256];
if (*(p-1) != '\n') {
p++;
continue;
}
getstring(&p, &end, s, sizeof(s));
if (strncmp(s, "From ", 5) == 0)
if ( dumpmsg(++i, &p, &end, msg) == -2)
return ;
}
}
}
int
main(int argc, char *argv[])
{
char *p, *end, *s;
int msg;
dohelp(argc, argv, "scan [+folder]");
if (setupbm()==-1)
return -1;
if (getcurrent(argc, argv, &s, &msg) == -1)
return -1;
if (loadmail("scan", s, &p, &end) == -1)
return -1;
listmsgs(p, end, msg);
return msg;
}