From ccfd32e420d5bcc6d833bb765644b8c2225da51e Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Wed, 10 Aug 2005 15:32:42 +0000 Subject: [PATCH] Added subject line cleaner --- ChangeLog | 6 ++ TODO | 3 - lib/mbselib.h | 3 +- lib/strutil.c | 29 +++++++ mbfido/post.c | 2 + mbfido/storeecho.c | 205 +++++++++++++++++++++++---------------------- mbfido/storenet.c | 2 + mbsebbs/email.c | 2 + mbsebbs/mail.c | 2 + mbsebbs/offline.c | 1 + mbsebbs/pop3.c | 1 + 11 files changed, 150 insertions(+), 106 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ebf055d..8208e560 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ v0.71.3 13-Jun-2005 upgrade: Check mbsetup 7.n.3.14 and 7.n.3.15 settings. + mbselib.a: + Added a function to clean subject lines from garbage, trailing + spaces etc. to improve message linking. + mbcico: Added support for binkp GZ and BZ2 compression. Can be turned off per node. Only effective with originating calls. Incoming @@ -14,12 +18,14 @@ v0.71.3 13-Jun-2005 mbsebbs: Added logging of remote host and terminal. + Added subject line clean in several places. mbnewuser: Added logging of remote host and terminal. mbfido: Fixed commandline parser for mail recipients. + Added subject line clean in several places. mbsetup: Added setup switches per node to disable PLZ or GZ and BZ2 diff --git a/TODO b/TODO index cbe4d780..147b4517 100644 --- a/TODO +++ b/TODO @@ -126,9 +126,6 @@ mbfido: N: Make mailhistory.html a lot shorter, maybe day or week versions. - N: Strip trailing spaces from subject lines to make sure reply linking - works. - mbcico: L: Implement binkp option ND. diff --git a/lib/mbselib.h b/lib/mbselib.h index 10118d0e..9a14dced 100644 --- a/lib/mbselib.h +++ b/lib/mbselib.h @@ -2345,7 +2345,8 @@ unsigned char mbse_Readkey(void); /* Read a translated key */ */ char *padleft(char *str, int size, char pad); char *tl(char *str); -void Striplf(char *String); +void Striplf(char *); +void mbse_CleanSubject(char *); void tlf(char *str); char *tu(char *str); char *tlcap(char *); diff --git a/lib/strutil.c b/lib/strutil.c index 9051c529..827715cc 100644 --- a/lib/strutil.c +++ b/lib/strutil.c @@ -83,6 +83,35 @@ void Striplf(char *String) +void mbse_CleanSubject(char *String) +{ + int i, fixed = FALSE; + + i = strlen(String) -1; + + while ((isspace(String[i])) && i) { + String[i] = '\0'; + i--; + fixed = TRUE; + } + + if ((strncasecmp(String, "Re: ", 4) == 0) && (strncmp(String, "Re: ", 4))) { + /* + * Fix Re: + */ + String[0] = 'R'; + String[1] = 'e'; + String[2] = ':'; + String[3] = ' '; + fixed = TRUE; + } + + if (fixed) + Syslog('m', "Fixed subj: \"%s\"", printable(String, 0)); +} + + + /* * Converts first letter to UpperCase */ diff --git a/mbfido/post.c b/mbfido/post.c index 044bedf5..92896930 100644 --- a/mbfido/post.c +++ b/mbfido/post.c @@ -50,6 +50,8 @@ int Post(char *To, long Area, char *Subj, char *File, char *Flavor) time_t tt; struct tm *t; + mbse_CleanSubject(Subj); + if (!do_quiet) { mbse_colour(3, 0); printf("Post \"%s\" to \"%s\" in area %ld\n", File, To, Area); diff --git a/mbfido/storeecho.c b/mbfido/storeecho.c index 7484533a..50fdaff8 100644 --- a/mbfido/storeecho.c +++ b/mbfido/storeecho.c @@ -4,7 +4,7 @@ * Purpose ...............: Import a echomail message * ***************************************************************************** - * Copyright (C) 1997-2004 + * Copyright (C) 1997-2005 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -56,113 +56,114 @@ extern int do_quiet; /* Quiet flag */ */ int storeecho(faddr *f, faddr *t, time_t mdate, int flags, char *subj, char *msgid, char *reply, int bad, int dupe, FILE *fp) { - int result; - unsigned long crc2; - char *buf; + int result; + unsigned long crc2; + char *buf; - /* - * Update import counters - */ - if (!bad && !dupe) { - StatAdd(&msgs.Received, 1L); - msgs.LastRcvd = time(NULL); - StatAdd(&mgroup.MsgsRcvd, 1L); - mgroup.LastDate = time(NULL); - UpdateMsgs(); - } + mbse_CleanSubject(subj); + + /* + * Update import counters + */ + if (!bad && !dupe) { + StatAdd(&msgs.Received, 1L); + msgs.LastRcvd = time(NULL); + StatAdd(&mgroup.MsgsRcvd, 1L); + mgroup.LastDate = time(NULL); + UpdateMsgs(); + } - if (bad) { - if (strlen(CFG.badboard) == 0) { - Syslog('+', "Killing bad message"); - return 0; - } else { - if ((result = Msg_Open(CFG.badboard))) - Syslog('+', "Tossing in bad board"); - } - } else if (dupe) { - if (strlen(CFG.dupboard) == 0) { - Syslog('+', "Killing dupe message"); - return 0; - } else { - if ((result = Msg_Open(CFG.dupboard))) - Syslog('+', "Tossing in dupe board"); - } + if (bad) { + if (strlen(CFG.badboard) == 0) { + Syslog('+', "Killing bad message"); + return 0; } else { - result = Msg_Open(msgs.Base); + if ((result = Msg_Open(CFG.badboard))) + Syslog('+', "Tossing in bad board"); } - if (!result) { - WriteError("Can't open JAMmb %s", msgs.Base); - return 1; - } - - if (Msg_Lock(30L)) { - if (dupe) - echo_dupe++; - else if (bad) - echo_bad++; - else - echo_imp++; - - if (!do_quiet) { - mbse_colour(3, 0); - printf("\r%6u => %-40s\r", echo_in, msgs.Name); - fflush(stdout); - } - - Msg_New(); - - /* - * Fill subfields - */ - strcpy(Msg.From, f->name); - strcpy(Msg.To, t->name); - strcpy(Msg.FromAddress, ascfnode(f,0x1f)); - strcpy(Msg.Subject, subj); - Msg.Written = mdate; - Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60); - Msg.Echomail = TRUE; - - /* - * These are the only usefull flags in echomail - */ - if ((flags & M_PVT) && ((msgs.MsgKinds == BOTH) || (msgs.MsgKinds == PRIVATE))) - Msg.Private = TRUE; - if (flags & M_FILE) - Msg.FileAttach = TRUE; - - /* - * Set MSGID and REPLY crc. - */ - if (msgid != NULL) { - crc2 = -1; - Msg.MsgIdCRC = upd_crc32(msgid, crc2, strlen(msgid)); - } - if (reply != NULL) { - crc2 = -1; - Msg.ReplyCRC = upd_crc32(reply, crc2, strlen(reply)); - } - - /* - * Start write the message - * If not a bad or dupe message, eat the first - * line (AREA:tag). - */ - buf = calloc(MAX_LINE_LENGTH +1, sizeof(char)); - rewind(fp); - if (!dupe && !bad) - fgets(buf , MAX_LINE_LENGTH, fp); - Msg_Write(fp); - Msg_AddMsg(); - Msg_UnLock(); - Msg_Close(); - free(buf); - return 0; + } else if (dupe) { + if (strlen(CFG.dupboard) == 0) { + Syslog('+', "Killing dupe message"); + return 0; } else { - Syslog('+', "Can't lock msgbase %s", msgs.Base); - Msg_UnLock(); - Msg_Close(); - return 1; + if ((result = Msg_Open(CFG.dupboard))) + Syslog('+', "Tossing in dupe board"); } + } else { + result = Msg_Open(msgs.Base); + } + if (!result) { + WriteError("Can't open JAMmb %s", msgs.Base); + return 1; + } + + if (Msg_Lock(30L)) { + if (dupe) + echo_dupe++; + else if (bad) + echo_bad++; + else + echo_imp++; + + if (!do_quiet) { + mbse_colour(3, 0); + printf("\r%6u => %-40s\r", echo_in, msgs.Name); + fflush(stdout); + } + + Msg_New(); + + /* + * Fill subfields + */ + strcpy(Msg.From, f->name); + strcpy(Msg.To, t->name); + strcpy(Msg.FromAddress, ascfnode(f,0x1f)); + strcpy(Msg.Subject, subj); + Msg.Written = mdate; + Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60); + Msg.Echomail = TRUE; + + /* + * These are the only usefull flags in echomail + */ + if ((flags & M_PVT) && ((msgs.MsgKinds == BOTH) || (msgs.MsgKinds == PRIVATE))) + Msg.Private = TRUE; + if (flags & M_FILE) + Msg.FileAttach = TRUE; + + /* + * Set MSGID and REPLY crc. + */ + if (msgid != NULL) { + crc2 = -1; + Msg.MsgIdCRC = upd_crc32(msgid, crc2, strlen(msgid)); + } + if (reply != NULL) { + crc2 = -1; + Msg.ReplyCRC = upd_crc32(reply, crc2, strlen(reply)); + } + + /* + * Start write the message + * If not a bad or dupe message, eat the first line (AREA:tag). + */ + buf = calloc(MAX_LINE_LENGTH +1, sizeof(char)); + rewind(fp); + if (!dupe && !bad) + fgets(buf , MAX_LINE_LENGTH, fp); + Msg_Write(fp); + Msg_AddMsg(); + Msg_UnLock(); + Msg_Close(); + free(buf); + return 0; + } else { + Syslog('+', "Can't lock msgbase %s", msgs.Base); + Msg_UnLock(); + Msg_Close(); + return 1; + } } diff --git a/mbfido/storenet.c b/mbfido/storenet.c index fda73084..bb8f9bdb 100644 --- a/mbfido/storenet.c +++ b/mbfido/storenet.c @@ -62,6 +62,8 @@ int storenet(faddr *f, faddr *t, time_t mdate, int flags, char *Subj, char *msgi unsigned long crc2; char *Buf; + mbse_CleanSubject(Subj); + if (! SearchNetBoard(t->zone, t->net)) { bad = TRUE; WriteError("Can't find netmail board for %d:%d/%d", t->zone, t->net, t->node); diff --git a/mbsebbs/email.c b/mbsebbs/email.c index fa272ad6..183241d3 100644 --- a/mbsebbs/email.c +++ b/mbsebbs/email.c @@ -676,6 +676,7 @@ void Reply_Email(int IsReply) } else { sprintf(subj, "%s", Msg.Subject); } + mbse_CleanSubject(subj); Syslog('m', "Reply msg to %s, subject %s", to, subj); Syslog('m', "Msgid was %s", Msg.Msgid); sprintf(msgid, "%s", Msg.Msgid); @@ -876,6 +877,7 @@ void Write_Email(void) colour(CFG.MsgInputColourF, CFG.MsgInputColourB); alarm_on(); GetstrP(Msg.Subject, 65, 0); + mbse_CleanSubject(Msg.Subject); if ((strcmp(Msg.Subject, "")) == 0) { Enter(1); diff --git a/mbsebbs/mail.c b/mbsebbs/mail.c index f17cf92b..85f5d7a9 100644 --- a/mbsebbs/mail.c +++ b/mbsebbs/mail.c @@ -566,6 +566,7 @@ void Post_Msg() colour(CFG.MsgInputColourF, CFG.MsgInputColourB); alarm_on(); GetstrP(Msg.Subject, 65, 0); + mbse_CleanSubject(Msg.Subject); if ((strcmp(Msg.Subject, "")) == 0) { Enter(1); @@ -1642,6 +1643,7 @@ void Reply_Msg(int IsReply) colour(CFG.MsgInputColourF, CFG.MsgInputColourB); GetstrP(subj, 50, x); + mbse_CleanSubject(subj); if (strlen(subj)) strcpy(Msg.Subject, subj); diff --git a/mbsebbs/offline.c b/mbsebbs/offline.c index 881c761a..1e83757a 100644 --- a/mbsebbs/offline.c +++ b/mbsebbs/offline.c @@ -1588,6 +1588,7 @@ void BlueWave_Fetch() strcpy(Msg.From, Upr.from); strcpy(Msg.To, Upr.to); strcpy(Msg.Subject, Upr.subj); + mbse_CleanSubject(Msg.Subject); if (Upr.msg_attr & UPL_PRIVATE) Msg.Private = TRUE; if (msgs.MsgKinds == PRIVATE) diff --git a/mbsebbs/pop3.c b/mbsebbs/pop3.c index 0e3770f3..4e4d59f7 100644 --- a/mbsebbs/pop3.c +++ b/mbsebbs/pop3.c @@ -89,6 +89,7 @@ void retr_msg(int msgnum) if (strlen(p) > 109) p[109] = '\0'; sprintf(Msg.Subject, "%s", p+9); + mbse_CleanSubject(Msg.Subject); } if (strncmp(p, "Date: ", 6) == 0) Msg.Written = parsedate(p+6, NULL) - (gmt_offset((time_t)0) * 60);