📄 maillib.c
字号:
/* */
/* Allows copying message with one or more of the options */
/* specified in the copyopt data type. */
/*--------------------------------------------------------------------*/
boolean CopyMsg(int msgnum, FILE *f, copyopt headers, boolean indent)
{
long nextloc;
boolean print;
char buf[BUFSIZ];
/*--------------------------------------------------------------------*/
/* Write a separator line, if needed */
/*--------------------------------------------------------------------*/
if (headers == seperators)
{
if (fputs(MESSAGESEP,f) == EOF) /* Write out separator line */
{
printerr("CopyMsg");
panic();
} /* if (fputs(MESSAGESEP,f) == EOF) */
} /* if (headers == seperators) */
/*--------------------------------------------------------------------*/
/* else add a one line from line, if desired */
/*--------------------------------------------------------------------*/
else if (headers == fromheader )
{
register char *sp = buf;
headers = noheader; /* Do not print full header */
if (RetrieveLine(letters[msgnum].date, buf, LSIZE))
{
register char *sp = buf;
while (!isspace(*sp))
sp++;
while (isspace(*sp))
sp++;
fprintf(f,"On %s,", sp );
} /* if */
if (RetrieveLine(letters[msgnum].from, buf, BUFSIZ))
{
while (!isspace(*sp) && (*sp != '\0'))
sp++;
BuildAddress( buf, sp );
} /* if */
else
strcpy(buf,"you"); /* Wimp out without admitting it */
fprintf(f, " %s wrote:\n", buf) ;
} /* if (headers == fromheader ) */
/*--------------------------------------------------------------------*/
/* Now position to the front of the letter */
/*--------------------------------------------------------------------*/
fseek(fmailbox, letters[msgnum].adr , SEEK_SET);
nextloc = letters[msgnum + 1].adr;
while (ftell(fmailbox) < nextloc &&
fgets(buf, BUFSIZ, fmailbox) != nil(char)) {
/*--------------------------------------------------------------------*/
/* Determine if we should write the line */
/*--------------------------------------------------------------------*/
print = TRUE;
switch (headers)
{
case noheader:
print = FALSE;
break;
case nocontinue:
if ((*buf != '\n') && !isgraph(*buf)) {
print = FALSE;
break;
}
else
headers = noreceived;
/* Fall through ... */
case noreceived:
{
char entry = 0;
while ( strlen(ignorelist[entry]) && print )
{
if (equalni(ignorelist[entry],buf,strlen(ignorelist[entry])))
{
print = FALSE;
headers = nocontinue;
}
else
entry++;
}
} /* case noreceived */
/* Fall through */
case noseperator:
case seperators:
break;
default:
printmsg(0,"CopyMsg: Bad header copy state of %d",headers);
panic();
} /* switch */
/*--------------------------------------------------------------------*/
/* If we should print the line, do so */
/*--------------------------------------------------------------------*/
if (print)
{
if (indent)
{
if ( fputs(INDENT , f ) == EOF )
{
printerr( "CopyMsg" );
panic();
} /* if ( fputs(INDENT , f ) == EOF ) */
} /* if (indent) */
if ( fputs(buf , f ) == EOF )
{
printerr( "CopyMsg" );
panic();
} /* if ( fputs(buf , f ) == EOF ) */
} /* if (print) */
/*--------------------------------------------------------------------*/
/* If end of the header, print all data until the end of the input */
/*--------------------------------------------------------------------*/
if ( (headers != seperators) && equal(buf, "\n") )
headers = seperators;
} /*while*/
return TRUE;
} /*CopyMsg*/
/*--------------------------------------------------------------------*/
/* N u m e r i c */
/* */
/* Determine if a string is numeric. Returns TRUE if string is */
/* numeric, else FALSE. */
/*--------------------------------------------------------------------*/
boolean Numeric( const char *number)
{
char *column = (char *) number;
if (*column == '\0')
return FALSE;
while( isdigit(*column) ) /* Scan to string end or 1st non-digit */
column++;
return *column == '\0'; /* Success if whole string was made of
digits */
} /* Numeric */
/*--------------------------------------------------------------------*/
/* R e t r i e v e L i n e */
/* */
/* Read a line from a mail header, if available */
/*--------------------------------------------------------------------*/
boolean RetrieveLine(long adr, char *line, const size_t len)
{
char *cp = line;
size_t count;
*line = '\0'; /* Insure nothing to find */
if (adr == MISSING) /* No information to read? */
return FALSE; /* Report this to caller */
if (fseek(fmailbox, adr, SEEK_SET)) /* Position to data */
{ /* Have a problem? */
printerr("mailbox"); /* Yes --> Report and return */
return FALSE;
}
/*--------------------------------------------------------------------*/
/* Actually read the data in */
/*--------------------------------------------------------------------*/
count = fread(line, sizeof *line, len-1, fmailbox);
if ((count < (len-1)) && ferror( fmailbox ))
{
printerr( "RetrieveLine");
return FALSE;
}
line[count] = '\0'; /* Terminate the string read */
/*--------------------------------------------------------------------*/
/* A field continues until a new field begins in column of the */
/* next line or the header ends (an empty line); find the end */
/* of the field, trimming extra white space from the beginning */
/* of each line as we go */
/*--------------------------------------------------------------------*/
while( (cp = strchr(cp , '\n')) != NULL )
{
if ((cp[1] == '\n') || !isspace(cp[1])) /* End of field? */
*cp = '\0'; /* Yes --> Terminate string */
else {
char *next;
*cp++ = ' '; /* Convert line break to whitespace */
next = ++cp; /* Get first position of new line */
while( isspace( *next ) ) /* Ignore leading white space */
next++;
memmove( cp , next , strlen(next) + 1 );
/* Trim leading white space */
} /* else */
} /* while */
return TRUE;
} /*RetrieveLine*/
/*--------------------------------------------------------------------*/
/* R e t u r n A d d r e s s */
/* */
/* Returns the user name (if available and requested) or */
/* E-mail address of the user */
/* */
/* Written by ahd 15 July 1989 */
/*--------------------------------------------------------------------*/
void ReturnAddress(char *line, struct ldesc *ld)
{
char buffer[BUFSIZ];
if (!RetrieveLine(ld->from, buffer, BUFSIZ))
/* From: line available? */
strcpy(line,"-- Unknown --"); /* No --> Return error */
else {
char *begin = buffer;
while (!isspace(*begin) && (*begin != '\0'))
begin++;
if (strlen(begin))
ExtractName(line,begin); /* Yes --> Return name */
else
strcpy(line,"-- Invalid From: line --");
}
return;
} /*ReturnAddress*/
/*--------------------------------------------------------------------*/
/* s a y o p t i o n s */
/* */
/* Announce user options in effect */
/*--------------------------------------------------------------------*/
void sayoptions( FLAGTABLE *flags)
{
size_t subscript;
size_t used = 0;
printf("\nThe following options are set:\n");
for (subscript = 0; flags[subscript].sym != NULL; subscript++)
{
size_t width;
if (flags[subscript].bits & B_GLOBAL)
continue; /* Don't print system options */
width = 1 + strlen( flags[subscript].sym ) +
( bflag[ flags[subscript].position ] ? 0 : 2 );
used += width;
if ( subscript > 0 )
{
if ( used > 79 )
{
putchar('\n');
used = width;
} /* if ( used > 79 ) */
else
putchar(' ');
} /* if ( subscript > 0 ) */
printf("%s%s",
bflag[ flags[subscript].position ] ? "" : "no" ,
flags[subscript].sym );
} /* for */
putchar('\n');
} /* sayoptions */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -