diff --git a/ChangeLog b/ChangeLog index a501721f..361ab3ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -46,6 +46,9 @@ v0.37.7 09-Sep-2003 Debug logging is now in a separate file, the normal logging is now only in the normal logfiles. + msgbase.a: + Moved messages link from mbmsg program into library. + mbcico: Fixed MB state error from the previous version. Rewrote another part of the binkp driver, initializing the @@ -64,6 +67,15 @@ v0.37.7 09-Sep-2003 mbtask debug switch from menu 18. Import and purge oneliners now log what is done. + mbmsg: + Moved message linking to msgbase library. + + mbsebbs: + When a message is saved, the messages in that area are linked. + + mbfido: + When mails are scanned for export via ftn and one of the from, + to or subject lines are too long, the export is cancelled. v0.37.6 10-Aug-2003 - 09-Sep-2003 diff --git a/lib/Makefile b/lib/Makefile index 84cf11ca..d0cb9885 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -160,7 +160,7 @@ dbnode.o: ../config.h libs.h structs.h common.h users.h records.h clcomm.h dbcfg dbtic.o: ../config.h libs.h structs.h users.h records.h clcomm.h dbcfg.h dbtic.h dbuser.o: ../config.h libs.h structs.h users.h records.h dbcfg.h dbuser.h jammsg.o: ../config.h libs.h clcomm.h msgtext.h msg.h jam.h jammsg.h -msg.o: ../config.h libs.h msgtext.h msg.h jammsg.h +msg.o: ../config.h libs.h msgtext.h msg.h clcomm.h structs.h common.h jammsg.h msgtext.o: ../config.h libs.h msgtext.h msg.h nntp.o: ../config.h libs.h structs.h users.h records.h clcomm.h mbinet.h pop3.o: ../config.h libs.h structs.h users.h records.h clcomm.h mbinet.h diff --git a/lib/msg.c b/lib/msg.c index c245d80e..3f5fe8ba 100644 --- a/lib/msg.c +++ b/lib/msg.c @@ -32,6 +32,9 @@ #include "libs.h" #include "msgtext.h" #include "msg.h" +#include "clcomm.h" +#include "structs.h" +#include "common.h" #include "jammsg.h" @@ -329,3 +332,132 @@ void Msg_Write(FILE *fp) } +typedef struct { + unsigned long Subject; + unsigned long Number; +} MSGLINK; + + + +/* + * Link messages in one area. + * Returns -1 if error, else the number of linked messages. + */ +int Msg_Link(char *Path, int do_quiet, int slow_util) +{ + int i, m, msg_link = 0; + unsigned long Number, Prev, Next, Crc, Total; + char Temp[128], *p; + MSGLINK *Link; + + if (! Msg_Open(Path)) { + return -1; + } + + if (!do_quiet) { + colour(12, 0); + printf(" (linking)"); + colour(13, 0); + fflush(stdout); + } + + if ((Total = Msg_Number()) != 0L) { + if (Msg_Lock(30L)) { + if ((Link = (MSGLINK *)malloc(Total * sizeof(MSGLINK))) != NULL) { + memset(Link, 0, Total * sizeof(MSGLINK)); + Number = Msg_Lowest(); + i = 0; + do { + Msg_ReadHeader(Number); + strcpy(Temp, Msg.Subject); + p = strupr(Temp); + if (!strncmp(p, "RE:", 3)) { + p += 3; + if (*p == ' ') + p++; + } + Link[i].Subject = StringCRC32(p); + Link[i].Number = Number; + i++; + + if (slow_util && do_quiet && ((i % 5) == 0)) + usleep(1); + + if (((i % 10) == 0) && (!do_quiet)) { + printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); + fflush(stdout); + } + } while(Msg_Next(&Number) == TRUE); + + if (!do_quiet) { + printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); + fflush(stdout); + } + Number = Msg_Lowest(); + i = 0; + do { + Msg_ReadHeader(Number); + Prev = Next = 0; + Crc = Link[i].Subject; + + for (m = 0; m < Total; m++) { + if (m == i) + continue; + if (Link[m].Subject == Crc) { + if (m < i) + Prev = Link[m].Number; + else if (m > i) { + Next = Link[m].Number; + break; + } + } + } + + if (slow_util && do_quiet && ((i % 5) == 0)) + usleep(1); + + if (((i % 10) == 0) && (!do_quiet)) { + printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); + fflush(stdout); + } + + if (Msg.Original != Prev || Msg.Reply != Next) { + Msg.Original = Prev; + Msg.Reply = Next; + Msg_WriteHeader(Number); + msg_link++; + } + + i++; + + } while(Msg_Next(&Number) == TRUE); + + if (!do_quiet) { + printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); + fflush(stdout); + } + + free(Link); + } + + if (!do_quiet) { + printf(" \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); + } + Msg_UnLock(); + } else { + Syslog('+', "Can't lock %s", Path); + return -1; + } + } + + Msg_Close(); + + if (!do_quiet) { + printf("\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b"); + fflush(stdout); + } + return msg_link; +} + + diff --git a/lib/msg.h b/lib/msg.h index 4be44234..445e15d5 100644 --- a/lib/msg.h +++ b/lib/msg.h @@ -141,7 +141,7 @@ int Msg_SetLastRead(lastread); void Msg_UnLock(void); int Msg_WriteHeader(unsigned long); void Msg_Write(FILE *); - +int Msg_Link(char *, int, int); #endif diff --git a/mbfido/mbmsg.c b/mbfido/mbmsg.c index 6ae2a8fb..ea8d6ce8 100644 --- a/mbfido/mbmsg.c +++ b/mbfido/mbmsg.c @@ -420,127 +420,17 @@ void DoMsgBase() -typedef struct { - unsigned long Subject; - unsigned long Number; -} MSGLINK; - - - void LinkArea(char *Path, long Areanr) { - int i, m; - unsigned long Number, Prev, Next, Crc, Total; - char Temp[128], *p; - MSGLINK *Link; - - IsDoing("Linking %ld", Areanr); + int rc; - if (Msg_Open(Path)) { - if (!do_quiet) { - colour(12, 0); - printf(" (linking)"); - colour(13, 0); - fflush(stdout); - } + IsDoing("Linking %ld", Areanr); + rc = Msg_Link(Path, do_quiet, CFG.slow_util); - if ((Total = Msg_Number()) != 0L) { - if (Msg_Lock(30L)) { - if ((Link = (MSGLINK *)malloc(Total * sizeof(MSGLINK))) != NULL) { - memset(Link, 0, Total * sizeof(MSGLINK)); - Number = Msg_Lowest(); - i = 0; - do { - Msg_ReadHeader(Number); - strcpy(Temp, Msg.Subject); - p = strupr(Temp); - if (!strncmp(p, "RE:", 3)) { - p += 3; - if (*p == ' ') - p++; - } - Link[i].Subject = StringCRC32(p); - Link[i].Number = Number; - i++; - - if (CFG.slow_util && do_quiet && ((i % 5) == 0)) - usleep(1); - - if (((i % 10) == 0) && (!do_quiet)) { - printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); - fflush(stdout); - } - } while(Msg_Next(&Number) == TRUE); - - if (!do_quiet) { - printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); - fflush(stdout); - } - - Number = Msg_Lowest(); - i = 0; - do { - Msg_ReadHeader(Number); - Prev = Next = 0; - Crc = Link[i].Subject; - - for (m = 0; m < Total; m++) { - if (m == i) - continue; - if (Link[m].Subject == Crc) { - if (m < i) - Prev = Link[m].Number; - else if (m > i) { - Next = Link[m].Number; - break; - } - } - } - - if (CFG.slow_util && do_quiet && ((i % 5) == 0)) - usleep(1); - - if (((i % 10) == 0) && (!do_quiet)) { - printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); - fflush(stdout); - } - - if (Msg.Original != Prev || Msg.Reply != Next) { - Msg.Original = Prev; - Msg.Reply = Next; - Msg_WriteHeader(Number); - processed = TRUE; - msg_link++; - } - - i++; - } while(Msg_Next(&Number) == TRUE); - - if (!do_quiet) { - printf("%6d / %6lu\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i, Total); - fflush(stdout); - } - - free(Link); - } - - if (!do_quiet) { - printf(" \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); - fflush(stdout); - } - Msg_UnLock(); - } else { - Syslog('+', "Can't lock %s", Path); - } - } - - Msg_Close(); - - if (!do_quiet) { - printf("\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b"); - fflush(stdout); - } - } + if (rc != -1) { + msg_link = rc; + processed = TRUE; + } } diff --git a/mbfido/scan.c b/mbfido/scan.c index 59458839..09c6a25a 100644 --- a/mbfido/scan.c +++ b/mbfido/scan.c @@ -141,195 +141,192 @@ void ScanMail(int DoAll) void ScanFull() { - char *sAreas, sbe[128]; - FILE *pAreas; - long arearec = 0, sysstart, nextstart; - unsigned long Total, Number; - int i; - sysconnect Link; - fa_list *sbl = NULL; + char *sAreas, sbe[128]; + FILE *pAreas; + long arearec = 0, sysstart, nextstart; + unsigned long Total, Number; + int i; + sysconnect Link; + fa_list *sbl = NULL; - Syslog('+', "Full mailscan"); - IsDoing("Scanning mail"); + Syslog('+', "Full mailscan"); + IsDoing("Scanning mail"); - if (!do_quiet) { - colour(9, 0); - printf("Scanning mail\n"); - colour(3, 0); - fflush(stdout); - } + if (!do_quiet) { + colour(9, 0); + printf("Scanning mail\n"); + colour(3, 0); + fflush(stdout); + } - sAreas = calloc(PATH_MAX, sizeof(char)); - sprintf(sAreas, "%s/etc/users.data", getenv("MBSE_ROOT")); - if ((pAreas = fopen(sAreas, "r")) != NULL) { - fread(&usrconfighdr, sizeof(usrconfighdr), 1, pAreas); + sAreas = calloc(PATH_MAX, sizeof(char)); + sprintf(sAreas, "%s/etc/users.data", getenv("MBSE_ROOT")); + if ((pAreas = fopen(sAreas, "r")) != NULL) { + fread(&usrconfighdr, sizeof(usrconfighdr), 1, pAreas); - while (fread(&usrconfig, usrconfighdr.recsize, 1, pAreas) == 1) { - if (usrconfig.Email && strlen(usrconfig.Name)) { + while (fread(&usrconfig, usrconfighdr.recsize, 1, pAreas) == 1) { + if (usrconfig.Email && strlen(usrconfig.Name)) { - Nopper(); - if (!do_quiet) { - colour(3, 0); - printf("\r%8s %-40s", usrconfig.Name, usrconfig.sUserName); - colour(13, 0); - fflush(stdout); - } - - sprintf(sAreas, "%s/%s/mailbox", CFG.bbs_usersdir, usrconfig.Name); - if (Msg_Open(sAreas)) { - if ((Total = Msg_Number()) != 0L) { - Number = Msg_Lowest(); - - do { - if (CFG.slow_util && do_quiet) - usleep(1); - - if (((Number % 10) == 0) && (!do_quiet)) { - printf("%6lu\b\b\b\b\b\b", Number); - fflush(stdout); - } - - Msg_ReadHeader(Number); - if (Msg.Local) { - if (Msg_Lock(15L)) { - Syslog('m', "Export %lu email from %s", Number, usrconfig.Name); - ExportEmail(Number); - Msg.Local = FALSE; - Msg.Arrived = time(NULL); - Msg_WriteHeader(Number); - Msg_UnLock(); - } - } - - } while (Msg_Next(&Number) == TRUE); - } - Msg_Close(); - if (!do_quiet) { - printf(" \b\b\b\b\b\b"); - fflush(stdout); - } - } - } + Nopper(); + if (!do_quiet) { + colour(3, 0); + printf("\r%8s %-40s", usrconfig.Name, usrconfig.sUserName); + colour(13, 0); + fflush(stdout); } - fclose(pAreas); - } - sprintf(sAreas, "%s/etc/mareas.data", getenv("MBSE_ROOT")); - if ((pAreas = fopen(sAreas, "r")) == NULL) { - WriteError("Can't open %s", sAreas); - free(sAreas); - return; - } - free(sAreas); - fread(&msgshdr, sizeof(msgshdr), 1, pAreas); + sprintf(sAreas, "%s/%s/mailbox", CFG.bbs_usersdir, usrconfig.Name); + if (Msg_Open(sAreas)) { + if ((Total = Msg_Number()) != 0L) { + Number = Msg_Lowest(); - while (fread(&msgs, msgshdr.recsize, 1, pAreas) == 1) { - sysstart = ftell(pAreas); - fseek(pAreas, msgshdr.syssize, SEEK_CUR); - nextstart = ftell(pAreas); - arearec++; + do { + if (CFG.slow_util && do_quiet) + usleep(1); - if ((msgs.Active) && (msgs.Type == ECHOMAIL || msgs.Type == NETMAIL || msgs.Type == NEWS)) { - - Nopper(); - if (!do_quiet) { - colour(3, 0); - printf("\r%5ld .. %-40s", arearec, msgs.Name); - colour(13, 0); + if (((Number % 10) == 0) && (!do_quiet)) { + printf("%6lu\b\b\b\b\b\b", Number); fflush(stdout); - } + } - if (Msg_Open(msgs.Base)) { - if ((Total = Msg_Number()) != 0L) { - Number = Msg_Lowest(); - - do { - if (CFG.slow_util && do_quiet) - usleep(1); - - if (((Number % 10) == 0) && (!do_quiet)) { - printf("%6lu\b\b\b\b\b\b", Number); - fflush(stdout); - } - - Msg_ReadHeader(Number); - if (Msg.Local) { - if (Msg_Lock(15L)) { - Syslog('m', "Export %lu from area %ld", Number, arearec); - - /* - * Setup SEEN-BY lines - */ - if ((msgs.Type == ECHOMAIL) || (msgs.Type == NEWS)) { - echo_in++; - fill_list(&sbl, aka2str(msgs.Aka), NULL); - for (i = 0; i < 40; i++) { - if (CFG.akavalid[i] && - (msgs.Aka.zone == CFG.aka[i].zone) && - (CFG.aka[i].point == 0) && - !((msgs.Aka.net == CFG.aka[i].net) && - (msgs.Aka.node == CFG.aka[i].node))) { - sprintf(sbe, "%u/%u", CFG.aka[i].net, - CFG.aka[i].node); - fill_list(&sbl, sbe, NULL); - } - } - fseek(pAreas, sysstart, SEEK_SET); - for (i = 0; i < (msgshdr.syssize / sizeof(sysconnect)); i++) { - fread(&Link, sizeof(sysconnect), 1, pAreas); - if ((Link.aka.zone) && (Link.sendto) && (!Link.pause)) { - fill_list(&sbl, aka2str(Link.aka), NULL); - } - } - uniq_list(&sbl); - sort_list(&sbl); - - fseek(pAreas, sysstart, SEEK_SET); - for (i = 0; i < (msgshdr.syssize / sizeof(sysconnect)); i++) { - fread(&Link, sizeof(sysconnect), 1, pAreas); - if (Link.aka.zone) - ExportEcho(Link, Number, &sbl); - } - if (strlen(msgs.Newsgroup)) - ExportNews(Number, &sbl); - - tidy_falist(&sbl); - } - if (msgs.Type == NETMAIL) { - ExportNet(Number, FALSE); - most_debug = FALSE; - } - Msg.Local = FALSE; - Msg.Arrived = time(NULL); - Msg_WriteHeader(Number); - Msg_UnLock(); - } - } - - } while (Msg_Next(&Number) == TRUE); + Msg_ReadHeader(Number); + if (Msg.Local) { + if (Msg_Lock(15L)) { + Syslog('m', "Export %lu email from %s", Number, usrconfig.Name); + ExportEmail(Number); + Msg.Local = FALSE; + Msg.Arrived = time(NULL); + Msg_WriteHeader(Number); + Msg_UnLock(); } + } - Msg_Close(); - - if (!do_quiet) { - printf(" \b\b\b\b\b\b"); - fflush(stdout); - } - } - - /* - * Make sure to start at the next area. - */ - fseek(pAreas, nextstart, SEEK_SET); + } while (Msg_Next(&Number) == TRUE); + } + Msg_Close(); + if (!do_quiet) { + printf(" \b\b\b\b\b\b"); + fflush(stdout); + } } + } } - fclose(pAreas); + } - if (!do_quiet) { - printf("\r \r"); + sprintf(sAreas, "%s/etc/mareas.data", getenv("MBSE_ROOT")); + if ((pAreas = fopen(sAreas, "r")) == NULL) { + WriteError("Can't open %s", sAreas); + free(sAreas); + return; + } + free(sAreas); + fread(&msgshdr, sizeof(msgshdr), 1, pAreas); + + while (fread(&msgs, msgshdr.recsize, 1, pAreas) == 1) { + sysstart = ftell(pAreas); + fseek(pAreas, msgshdr.syssize, SEEK_CUR); + nextstart = ftell(pAreas); + arearec++; + + if ((msgs.Active) && (msgs.Type == ECHOMAIL || msgs.Type == NETMAIL || msgs.Type == NEWS)) { + + Nopper(); + if (!do_quiet) { + colour(3, 0); + printf("\r%5ld .. %-40s", arearec, msgs.Name); + colour(13, 0); fflush(stdout); + } + + if (Msg_Open(msgs.Base)) { + if ((Total = Msg_Number()) != 0L) { + Number = Msg_Lowest(); + + do { + if (CFG.slow_util && do_quiet) + usleep(1); + + if (((Number % 10) == 0) && (!do_quiet)) { + printf("%6lu\b\b\b\b\b\b", Number); + fflush(stdout); + } + + Msg_ReadHeader(Number); + if (Msg.Local) { + if (Msg_Lock(15L)) { + Syslog('m', "Export %lu from area %ld", Number, arearec); + + /* + * Setup SEEN-BY lines + */ + if ((msgs.Type == ECHOMAIL) || (msgs.Type == NEWS)) { + echo_in++; + fill_list(&sbl, aka2str(msgs.Aka), NULL); + for (i = 0; i < 40; i++) { + if (CFG.akavalid[i] && (msgs.Aka.zone == CFG.aka[i].zone) && + (CFG.aka[i].point == 0) && !((msgs.Aka.net == CFG.aka[i].net) && + (msgs.Aka.node == CFG.aka[i].node))) { + sprintf(sbe, "%u/%u", CFG.aka[i].net, CFG.aka[i].node); + fill_list(&sbl, sbe, NULL); + } + } + fseek(pAreas, sysstart, SEEK_SET); + for (i = 0; i < (msgshdr.syssize / sizeof(sysconnect)); i++) { + fread(&Link, sizeof(sysconnect), 1, pAreas); + if ((Link.aka.zone) && (Link.sendto) && (!Link.pause)) { + fill_list(&sbl, aka2str(Link.aka), NULL); + } + } + uniq_list(&sbl); + sort_list(&sbl); + + fseek(pAreas, sysstart, SEEK_SET); + for (i = 0; i < (msgshdr.syssize / sizeof(sysconnect)); i++) { + fread(&Link, sizeof(sysconnect), 1, pAreas); + if (Link.aka.zone) + ExportEcho(Link, Number, &sbl); + } + if (strlen(msgs.Newsgroup)) + ExportNews(Number, &sbl); + + tidy_falist(&sbl); + } + if (msgs.Type == NETMAIL) { + ExportNet(Number, FALSE); + most_debug = FALSE; + } + Msg.Local = FALSE; + Msg.Arrived = time(NULL); + Msg_WriteHeader(Number); + Msg_UnLock(); + } + } + + } while (Msg_Next(&Number) == TRUE); + } + + Msg_Close(); + + if (!do_quiet) { + printf(" \b\b\b\b\b\b"); + fflush(stdout); + } + } + + /* + * Make sure to start at the next area. + */ + fseek(pAreas, nextstart, SEEK_SET); } + } + + fclose(pAreas); + + if (!do_quiet) { + printf("\r \r"); + fflush(stdout); + } } @@ -573,7 +570,7 @@ int RescanOne(faddr *L, char *marea, unsigned long Num) */ void ExportEcho(sysconnect L, unsigned long MsgNum, fa_list **sbl) { - int seenlen, oldnet, flags = 0, kludges = TRUE; + int rc, seenlen, oldnet, flags = 0, kludges = TRUE; char *p, sbe[16], ext[4]; fa_list *tmpl; FILE *qp; @@ -612,9 +609,16 @@ void ExportEcho(sysconnect L, unsigned long MsgNum, fa_list **sbl) flags |= (Msg.Private) ? M_PVT : 0; from = fido2faddr(msgs.Aka); dest = fido2faddr(L.aka); - AddMsgHdr(qp, from, dest, flags, 0, Msg.Written, Msg.To, Msg.From, Msg.Subject); + rc = AddMsgHdr(qp, from, dest, flags, 0, Msg.Written, Msg.To, Msg.From, Msg.Subject); tidy_faddr(from); tidy_faddr(dest); + + if (rc) { + Syslog('+', "Cannot export message"); + fclose(qp); + return; + } + fprintf(qp, "AREA:%s\r", msgs.Tag); if (Msg_Read(MsgNum, 78)) { diff --git a/mbsebbs/email.c b/mbsebbs/email.c index 485d1c6a..a8185aa7 100644 --- a/mbsebbs/email.c +++ b/mbsebbs/email.c @@ -360,7 +360,7 @@ int Save_Email(int IsReply) } free(temp); - Msg_Close(); + Close_Msgbase(sMailpath); return TRUE; } diff --git a/mbsebbs/mail.c b/mbsebbs/mail.c index 0ff907a6..3dcbd397 100644 --- a/mbsebbs/mail.c +++ b/mbsebbs/mail.c @@ -684,7 +684,7 @@ int Save_Msg(int IsReply, faddr *Dest) } } free(temp); - Msg_Close(); + Close_Msgbase(msgs.Base); SetMsgArea(iMsgAreaNumber); return TRUE; diff --git a/mbsebbs/msgutil.c b/mbsebbs/msgutil.c index cfbd1d6c..200afe61 100644 --- a/mbsebbs/msgutil.c +++ b/mbsebbs/msgutil.c @@ -44,6 +44,7 @@ int BaseWrite = FALSE; +int NewMessages = FALSE; static char *wdays[]={(char *)"Sun",(char *)"Mon",(char *)"Tue",(char *)"Wed", (char *)"Thu",(char *)"Fri",(char *)"Sat"}; @@ -113,6 +114,7 @@ char *rfcdate(time_t now) int Open_Msgbase(char *Base, int Mode) { BaseWrite = FALSE; + NewMessages = FALSE; if (!Msg_Open(Base)) return FALSE; @@ -134,11 +136,21 @@ int Open_Msgbase(char *Base, int Mode) /* * Close current messagebase. */ -void Close_Msgbase() +void Close_Msgbase(char *Base) { + int rc; + + Syslog('b', "Close_Msgbase(%s) BaseWrite=%s NewMessages=%s", Base, BaseWrite?"TRUE":"FALSE", NewMessages?"TRUE":"FALSE"); if (BaseWrite) { Msg_UnLock(); BaseWrite = FALSE; + if (NewMessages) { + rc = Msg_Link(Base, TRUE, CFG.slow_util); + if (rc != -1) + Syslog('+', "Linked %d message%s", rc, (rc != 1) ? "s":""); + else + Syslog('+', "Could not link messages"); + } } Msg_Close(); } @@ -297,6 +309,7 @@ void Add_Footkludges(int Quote, char *tear, int HasTear) free(aka); free(temp); + NewMessages = TRUE; } diff --git a/mbsebbs/msgutil.h b/mbsebbs/msgutil.h index 85d8a407..982c3722 100644 --- a/mbsebbs/msgutil.h +++ b/mbsebbs/msgutil.h @@ -5,7 +5,7 @@ char *rfcdate(time_t); /* Create RFC style date */ int Open_Msgbase(char *, int); /* Open msgbase for read/write */ -void Close_Msgbase(void); /* Close msgbase */ +void Close_Msgbase(char *); /* Close msgbase */ void Add_Headkludges(faddr *, int); /* Header part of kludges */ void Add_Footkludges(int, char *, int); /* Footer part of kludges */ void Sema_Mailout(void); /* Set mailout semafore */ diff --git a/mbsebbs/offline.c b/mbsebbs/offline.c index 4b34aa2e..e6f525cf 100644 --- a/mbsebbs/offline.c +++ b/mbsebbs/offline.c @@ -1692,7 +1692,7 @@ void BlueWave_Fetch() fclose(fp); } } - Msg_Close(); + Close_Msgbase(msgs.Base); } } else { /* No Write access to area */ @@ -2493,7 +2493,7 @@ void QWK_Fetch() fclose(fp); } } - Msg_Close(); + Close_Msgbase(msgs.Base); } } else { Syslog('+', "Can't post messages in area %u", Area); diff --git a/mbsebbs/pop3.c b/mbsebbs/pop3.c index a1270ae9..44d0f122 100644 --- a/mbsebbs/pop3.c +++ b/mbsebbs/pop3.c @@ -4,7 +4,7 @@ * Purpose ...............: POP3 client * ***************************************************************************** - * Copyright (C) 1997-2002 + * Copyright (C) 1997-2003 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 @@ -47,14 +47,14 @@ void error_popmail(char *); void error_popmail(char *umsg) { - char *p; + char *p; - pop3_send((char *)"QUIT\r\n"); - p = pop3_receive(); - pop3_close(); - colour(LIGHTRED, BLACK); - printf("%s\r\n", umsg); - fflush(stdout); + pop3_send((char *)"QUIT\r\n"); + p = pop3_receive(); + pop3_close(); + colour(LIGHTRED, BLACK); + printf("%s\r\n", umsg); + fflush(stdout); } @@ -62,69 +62,71 @@ void error_popmail(char *umsg) void retr_msg(int); void retr_msg(int msgnum) { - char *p, *q, temp[128]; - int Header; - unsigned long crc = -1; + char *p, *q, temp[PATH_MAX], *base; + int Header; + unsigned long crc = -1; - sprintf(temp, "RETR %d\r\n", msgnum); - if (pop3_cmd(temp) == 0) { - Msg_New(); - Header = TRUE; - sprintf(temp, "%s/%s/mailbox", CFG.bbs_usersdir, exitinfo.Name); - Open_Msgbase(temp, 'w'); - Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60); - Msg.Private = TRUE; - while (TRUE) { - p = pop3_receive(); - if ((p[0] == '.') && (strlen(p) == 1)) { - break; - } else { - if (Header) { - /* - * Check the primary message header lines. - */ - if (strncmp(p, "To: ", 4) == 0) { - if (strlen(p) > 104) - p[104] = '\0'; - sprintf(Msg.To, "%s", p+4); - } - if (strncmp(p, "From: ", 6) == 0) { - if (strlen(p) > 106) - p[106] = '\0'; - sprintf(Msg.From, "%s", p+6); - } - if (strncmp(p, "Subject: ", 9) == 0) { - if (strlen(p) > 109) - p[109] = '\0'; - sprintf(Msg.Subject, "%s", p+9); - } - if (strncmp(p, "Date: ", 6) == 0) - Msg.Written = parsedate(p+6, NULL) - (gmt_offset((time_t)0) * 60); - if (strncmp(p, "Message-Id: ", 12) == 0) { - q = xstrcpy(p+12); - Msg.MsgIdCRC = upd_crc32(q, crc, strlen(q)); - free(q); - } - Msg.ReplyCRC = 0xffffffff; - if (strlen(p) == 0) { - Header = FALSE; - } else { - sprintf(temp, "\001%s", p); - MsgText_Add2(temp); - } - } else { - MsgText_Add2(p); - } - } + sprintf(temp, "RETR %d\r\n", msgnum); + if (pop3_cmd(temp) == 0) { + Msg_New(); + Header = TRUE; + sprintf(temp, "%s/%s/mailbox", CFG.bbs_usersdir, exitinfo.Name); + base = xstrcpy(temp); + Open_Msgbase(base, 'w'); + Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60); + Msg.Private = TRUE; + while (TRUE) { + p = pop3_receive(); + if ((p[0] == '.') && (strlen(p) == 1)) { + break; + } else { + if (Header) { + /* + * Check the primary message header lines. + */ + if (strncmp(p, "To: ", 4) == 0) { + if (strlen(p) > 104) + p[104] = '\0'; + sprintf(Msg.To, "%s", p+4); + } + if (strncmp(p, "From: ", 6) == 0) { + if (strlen(p) > 106) + p[106] = '\0'; + sprintf(Msg.From, "%s", p+6); + } + if (strncmp(p, "Subject: ", 9) == 0) { + if (strlen(p) > 109) + p[109] = '\0'; + sprintf(Msg.Subject, "%s", p+9); + } + if (strncmp(p, "Date: ", 6) == 0) + Msg.Written = parsedate(p+6, NULL) - (gmt_offset((time_t)0) * 60); + if (strncmp(p, "Message-Id: ", 12) == 0) { + q = xstrcpy(p+12); + Msg.MsgIdCRC = upd_crc32(q, crc, strlen(q)); + free(q); + } + Msg.ReplyCRC = 0xffffffff; + if (strlen(p) == 0) { + Header = FALSE; + } else { + sprintf(temp, "\001%s", p); + MsgText_Add2(temp); + } + } else { + MsgText_Add2(p); } - Msg_AddMsg(); - Msg_UnLock(); - Msg_Close(); - sprintf(temp, "DELE %d\r\n", msgnum); - pop3_cmd(temp); - } else { - WriteError("POP3: Can't retrieve message %d", msgnum); + } } + Msg_AddMsg(); + Msg_UnLock(); + Close_Msgbase(base); + free(base); + sprintf(temp, "DELE %d\r\n", msgnum); + pop3_cmd(temp); + } else { + WriteError("POP3: Can't retrieve message %d", msgnum); + } }