int Read_a_Email(unsigned int Num) { char *p = NULL, *fn, *charset = NULL, *charsin = NULL; lastread LR; unsigned int mycrc; LastNum = Num; iLineCount = 7; WhosDoingWhat(READ_POST, NULL); /* * The area data is already set, so we can do the next things */ if (EmailBase.Total == 0) { Enter(1); /* There are no messages in this area */ pout(WHITE, BLACK, (char *) Language(205)); Enter(2); sleep(3); return FALSE; } if (!Msg_Open(sMailpath)) { WriteError("Error open JAM base %s", sMailpath); return FALSE; } if (!Msg_ReadHeader(Num)) { Enter(1); pout(WHITE, BLACK, (char *)Language(77)); Enter(2); Msg_Close(); sleep(3); return FALSE; } /* * Fill Quote file in case the user wants to reply. Note that line * wrapping is set lower then normal message read, to create room * for the Quote> strings at the start of each line. */ fn = calloc(PATH_MAX, sizeof(char)); snprintf(fn, PATH_MAX, "%s/%s/.quote", CFG.bbs_usersdir, exitinfo.Name); if ((qf = fopen(fn, "w")) != NULL) { if (Msg_Read(Num, 75)) { if ((p = (char *)MsgText_First()) != NULL) do { if (p[0] == '\001') { /* * Check CHRS kludge */ if (strncmp(p, "\001CHRS: ", 7) == 0) { charset = xstrcpy(p + 7); } /* * While doing this, store the original Message-id in case * a reply will be made. */ if (strncasecmp(p, "\001Message-id: ", 13) == 0) { snprintf(Msg.Msgid, sizeof(Msg.Msgid), "%s", p+13); Syslog('m', "Stored Msgid \"%s\"", Msg.Msgid); } if (Kludges) { p[0] = 'a'; fprintf(qf, "^%s\n", p); } } else fprintf(qf, "%s\n", p); } while ((p = (char *)MsgText_Next()) != NULL); } fclose(qf); } else { WriteError("$Can't open %s", p); } free(fn); if (charset == NULL) { charsin = xstrcpy((char *)"CP437"); } else { charsin = xstrcpy(get_ic_ftn(find_ftn_charset(charset))); } /* * Setup character translation */ chartran_init(charsin, get_ic_ftn(exitinfo.Charset), 'b'); ShowEmailHdr(); /* * Show message text */ colour(CFG.TextColourF, CFG.TextColourB); if (Msg_Read(Num, 79)) { if ((p = (char *)MsgText_First()) != NULL) { do { if (p[0] == '\001') { if (Kludges) { colour(LIGHTGRAY, BLACK); if (p[0] == '\001') p[0] = 'a'; PUTSTR(chartran(p)); Enter(1); if (CheckLine(CFG.TextColourF, CFG.TextColourB, TRUE)) break; } } else { colour(CFG.TextColourF, CFG.TextColourB); if (strchr(p, '>') != NULL) if ((strlen(p) - strlen(strchr(p, '>'))) < 10) colour(CFG.HiliteF, CFG.HiliteB); PUTSTR(chartran(p)); Enter(1); if (CheckLine(CFG.TextColourF, CFG.TextColourB, TRUE)) break; } } while ((p = (char *)MsgText_Next()) != NULL); } } if (charset) free(charset); if (charsin) free(charsin); chartran_close(); /* * Set the Received status on this message. */ if (!Msg.Received) { Syslog('m', "Marking message received"); Msg.Received = TRUE; Msg.Read = time(NULL) - (gmt_offset((time_t)0) * 60); if (Msg_Lock(30L)) { Msg_WriteHeader(Num); Msg_UnLock(); } } /* * Update lastread pointer. */ p = xstrcpy(exitinfo.sUserName); mycrc = StringCRC32(tl(p)); free(p); if (Msg_Lock(30L)) { LR.UserID = grecno; LR.UserCRC = mycrc; if (Msg_GetLastRead(&LR) == TRUE) { LR.LastReadMsg = Num; if (Num > LR.HighReadMsg) LR.HighReadMsg = Num; if (LR.HighReadMsg > EmailBase.Highest) LR.HighReadMsg = EmailBase.Highest; LR.UserCRC = mycrc; if (!Msg_SetLastRead(LR)) WriteError("Error update lastread"); } else { /* * Append new lastread pointer */ LR.UserCRC = mycrc; LR.UserID = grecno; LR.LastReadMsg = Num; LR.HighReadMsg = Num; if (!Msg_NewLastRead(LR)) WriteError("Can't append lastread"); } Msg_UnLock(); } Msg_Close(); return TRUE; }
/* * 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 int Number, Prev, Next, Crc, Total; char Temp[128], *p; MSGLINK *Link; if (! Msg_Open(Path)) { return -1; } if (!do_quiet) { msg_colour(LIGHTRED, BLACK); printf(" (linking)"); msg_colour(LIGHTMAGENTA, BLACK); fflush(stdout); } if ((Total = Msg_Number()) != 0L) { if (Msg_Lock(30L)) { if ((Link = (MSGLINK *)malloc((Total + 1) * sizeof(MSGLINK))) != NULL) { memset(Link, 0, (Total + 1) * 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 (((i % 10) == 0) && (!do_quiet)) { printf("%6d / %6u\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 / %6u\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 (((i % 10) == 0) && (!do_quiet)) { printf("%6d / %6u\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 / %6u\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; }