mp fix to allow printing of news articles
Dave Glowacki
daveg at roxanne.StPaul.GOV
Thu Dec 15 07:42:23 AEST 1988
Here's a patch to get mp to print news articles. This patch adds the
following features:
* Instead of "Mail for user" in the heading, it prints
"Article from newsgroup". It guesses that it's processing
a news article via the presence of either a "Newsgroups: "
or an "Article " header field.
* A "-d" option has been added, to handle digests (each separate
article on a new page with its subject at the bottom.)
* Identification of header fields has (hopefully) been tightened
up. This was done by making sure appropriate header fields were
followed by colon/space. This patch also assumes that mail
"From " header fields are of the form "From user [Sun-Sat] ..."
which will hopefully cut down on the number of falsely
identified lines beginning with "From".
If someone REALLY wanted to get carried away, it'd probably be nice to
have a way to specify which header fields to print and which to leave
out (being a rigid domainist, I left out the "Path:" field patch from
Mr. Feidler, which motivated this whole thing :-)
--
*** mp.c.orig Tue Dec 13 16:14:53 1988
--- mp.c Tue Dec 13 16:37:19 1988
***************
*** 12,17 ****
--- 12,18 ----
#include <sys/file.h>
#include <string.h>
#include <time.h>
+ #include <ctype.h>
#define PATCHLEVEL 2
***************
*** 35,40 ****
--- 36,43 ----
time_t time() ;
struct tm *localtime() ;
char *asctime(), *getlogin(), *gets() ;
+ int newsarticle = 0; /* =1 if this is a news article */
+ char titleobj[MAXLINE]; /* User name/Newsgroup name for this message */
char subject[MAXLINE] ; /* Subject line for this message. */
FILE *fopen(), *pf ;
***************
*** 58,63 ****
--- 61,67 ----
int state ; /* State of message processing automation. */
long clock ; /* Used by the localtime function call. */
struct tm *tm ; /* Used by the localtime and asctime calls. */
+ int digest = 0; /* =1 if we're processing a digest */
char *progname = *argv ; /* This programs name. */
STRCPY(prologue, "/usr/local/lib/mp.pro.ps") ; /* Set up default values. */
***************
*** 77,82 ****
--- 81,90 ----
exit(1) ;
}
}
+ else if (strcmp(*args, "-d") == 0)
+ {
+ digest = 1;
+ }
else
{
FPRINTF(stderr,"%s: Unknown option %s\n",progname,*args) ;
***************
*** 91,97 ****
}
while (fgets(nextline,MAXLINE,pf) != NULL) PRINTF("%s",nextline) ;
! defwrite("loginname",username) ;
clock = time((time_t *) 0) ;
tm = localtime(&clock) ;
defwrite("timenow",asctime(tm)) ;
--- 99,105 ----
}
while (fgets(nextline,MAXLINE,pf) != NULL) PRINTF("%s",nextline) ;
! defwrite("titleobj",username) ;
clock = time((time_t *) 0) ;
tm = localtime(&clock) ;
defwrite("timenow",asctime(tm)) ;
***************
*** 116,133 ****
}
switch (state)
{
! case FROMLINE : if (EQUAL("From"))
{
boldshow(nextline) ;
state = DOHEADER ;
}
break ;
! case DOHEADER : if (EQUAL("From") || EQUAL("Date") || EQUAL("Subject"))
{
mixedshow(nextline) ;
maybe_more = 0 ;
}
! else if (EQUAL("To") || EQUAL("Cc"))
{
mixedshow(nextline) ;
maybe_more = 1 ;
--- 124,152 ----
}
switch (state)
{
! case FROMLINE : if (EQUAL("From ") && realfrom(nextline))
{
boldshow(nextline) ;
state = DOHEADER ;
}
+ else if (EQUAL("From: "))
+ {
+ mixedshow(nextline);
+ state = DOHEADER;
+ }
+ else if (EQUAL("Article "))
+ {
+ boldshow(nextline);
+ getnewsgroup(nextline);
+ state = DOHEADER;
+ }
break ;
! case DOHEADER : if (EQUAL("From: ") || EQUAL("Date: ") || EQUAL("Subject: ") || EQUAL("Message-ID: ") || EQUAL("References: "))
{
mixedshow(nextline) ;
maybe_more = 0 ;
}
! else if (EQUAL("To: ") || EQUAL("Cc: "))
{
mixedshow(nextline) ;
maybe_more = 1 ;
***************
*** 140,155 ****
PRINTF("Courier\n") ;
PRINTF("() showline\n") ;
}
else maybe_more = 0 ;
break ;
! case DOMESSAGE : if (EQUAL("From"))
{
! linect = PAGELENGTH ;
useline() ;
boldshow(nextline) ;
state = DOHEADER ;
}
! else textshow(nextline) ;
break ;
}
}
--- 159,195 ----
PRINTF("Courier\n") ;
PRINTF("() showline\n") ;
}
+ else if (EQUAL("Newsgroups: "))
+ {
+ mixedshow(nextline) ;
+ if (!newsarticle)
+ getnewsgroup(nextline);
+ }
else maybe_more = 0 ;
break ;
! case DOMESSAGE : if (EQUAL("From ") && realfrom(nextline))
{
! linect = PAGELENGTH ;
useline() ;
boldshow(nextline) ;
state = DOHEADER ;
}
! else if (digest && (EQUAL("Date: ") || EQUAL("From: ")))
! {
! linect = PAGELENGTH ;
! useline() ;
! mixedshow(nextline) ;
! state = DOHEADER ;
! }
! else if (EQUAL("Article "))
! {
! linect = PAGELENGTH ;
! useline() ;
! boldshow(nextline);
! getnewsgroup(nextline);
! state = DOHEADER;
! }
! else textshow(nextline) ;
break ;
}
}
***************
*** 159,164 ****
--- 199,245 ----
}
+ getnewsgroup(s)
+ char *s;
+ {
+ char *n;
+
+ for (n = &s[strlen(s) - 1]; (n != s) && !isspace(*n); n--)
+ ;
+ if (n == s)
+ *titleobj = '\0';
+ else
+ for (n++, s = titleobj; *n && (*n != ':') && (*n != ','); )
+ *s++ = *n++;
+ *s = '\0';
+ PRINTF("/titleobj (") ;
+ expand(titleobj) ;
+ PRINTF(") def\n") ;
+ newsarticle = 1;
+ PRINTF("/newsarticle true def\n");
+ }
+
+
+ static char days[] = "SunMonTueWedThuFriSat";
+ realfrom(s)
+ char *s;
+ {
+ int i;
+
+ s += 5;
+ while (*s && isspace(*s))
+ s++;
+ while (*s && !isspace(*s))
+ s++;
+ while (*s && isspace(*s))
+ s++;
+ for (i = 0; i < 21; i += 3)
+ if ((s[0] == days[i]) && (s[1] == days[i+1]) && (s[2] == days[i+2]))
+ return(1);
+ return(0);
+ }
+
+
boldshow(s)
char *s ;
{
***************
*** 251,256 ****
--- 332,341 ----
{
endpage() ;
startpage() ;
+ PRINTF("/titleobj (") ;
+ expand(titleobj) ;
+ PRINTF(") def\n") ;
+ PRINTF("/newsarticle %s def\n", (newsarticle ? "true" : "false"));
PRINTF("/subject (") ;
expand(subject) ;
PRINTF(") def\n") ;
*** mp.pro.ps.orig Tue Dec 13 16:06:32 1988
--- mp.pro.ps Tue Dec 13 14:56:52 1988
***************
*** 8,13 ****
--- 8,15 ----
%%EndComments
%
+ /newsarticle false def
+ /titleobj (printing) def
/subject () def
save /nuksunmailsave exch def
/font1d /Times-Bold findfont 10 scalefont def
***************
*** 48,55 ****
closepath
0 setgray stroke
100 740 moveto
! (Mail for ) show
! loginname (\(null\)) eq {(printing)} {loginname} ifelse show
fontD
timenow stringwidth pop neg 536 add 740 moveto timenow show
fontN
--- 50,57 ----
closepath
0 setgray stroke
100 740 moveto
! newsarticle { fontD (Article from ) show } { (Mail for ) show } ifelse
! titleobj show
fontD
timenow stringwidth pop neg 536 add 740 moveto timenow show
fontN
--
Dave Glowacki ...!pyramid!pwcs!daveg daveg at pwcs.StPaul.GOV
More information about the Comp.sources.bugs
mailing list