diff --git a/src/www_msgs.c b/src/www_msgs.c index 3f229a2..9806fab 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -91,9 +91,7 @@ char *www_msgs_arealist(struct user_record *user) { char *www_msgs_messagelist(struct user_record *user, int conference, int area, int skip) { struct msg_headers *mhrs; - char *page; - int max_len; - int len; + stralloc page = EMPTY_STRALLOC; char buffer[4096]; int i; struct tm msg_date; @@ -109,51 +107,32 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) { return NULL; } - page = (char *)malloz(4096); - max_len = 4096; - len = 0; - - sprintf(buffer, "

%s - %s

\n", conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + stralloc_copys(&page, "

"); + stralloc_cats(&page, conf.mail_conferences[conference]->name); + stralloc_cats(&page, " - "); + stralloc_cats(&page, conf.mail_conferences[conference]->mail_areas[area]->name); + stralloc_cats(&page, "

\n"); if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { - sprintf(buffer, "
New Message
\n", conf.www_url, conference, area); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + stralloc_cats(&page, "
New Message
\n"); } mhrs = read_message_headers(conference, area, user, 0); if (mhrs == NULL) { - sprintf(buffer, "

No Messages

\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - return page; + stralloc_cats(&page, "

No Messages

\n"); } - sprintf(buffer, "
\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + stralloc_cats(&page, "
\n"); jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); if (!jb) { - free(page); + free(page.s); free_message_headers(mhrs); return NULL; } @@ -177,21 +156,21 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i subject = www_sanitize(mhrs->msgs[i]->subject); if (msgbase_is_flagged(user, conference, area, mhrs->msgs[i]->msg_h->MsgNum)) { if (conf.date_style == 1) { - sprintf(buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - sprintf(buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } else if (mhrs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg) { if (conf.date_style == 1) { - sprintf(buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - sprintf(buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } else { if (conf.date_style == 1) { - sprintf(buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); } else { - sprintf(buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + snprintf(buffer, sizeof buffer, "
%d
%s
%s
%.2d:%.2d %.2d-%.2d-%.2d
\n", mhrs->msgs[i]->msg_no + 1, conf.www_url, conference, area, mhrs->msgs[i]->msg_h->MsgNum, subject, from, to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } } @@ -199,46 +178,28 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i free(from); free(subject); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + stralloc_cats(&page, buffer); } - sprintf(buffer, "
\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + stralloc_cats(&page, "
\n"); if (skip + 50 <= mhrs->msg_count) { - sprintf(buffer, "
Next
\n", conf.www_url, conference, area, skip + 50); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + snprintf(buffer, sizeof buffer, +"
Next
\n", +conf.www_url, conference, area, skip + 50); + stralloc_cats(&page, buffer); } if (skip > 0) { if (skip - 50 < 0) { - sprintf(buffer, "
Prev
\n", conf.www_url, conference, area); + snprintf(buffer, sizeof buffer, "
Prev
\n", conf.www_url, conference, area); } else { - sprintf(buffer, "
Prev
\n", conf.www_url, conference, area, skip - 50); + snprintf(buffer, sizeof buffer, "
Prev
\n", conf.www_url, conference, area, skip - 50); } - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); + stralloc_cats(&page, buffer); } + stralloc_0(&page); free_message_headers(mhrs); - return page; + return page.s; } char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) { @@ -262,9 +223,7 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i int z; struct tm msg_date; time_t date; - char *page; - int max_len; - int len; + stralloc page = EMPTY_STRALLOC; char buffer[4096]; int chars; int i; @@ -281,428 +240,270 @@ char *www_msgs_messageview(struct user_record *user, int conference, int area, i return NULL; } - if (conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level) { - jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); - if (!jb) { - return NULL; - } - - JAM_ReadMBHeader(jb, &jbh); - - memset(&jmh, 0, sizeof(s_JamMsgHeader)); - z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp); - if (z != 0) { - JAM_CloseMB(jb); - free(jb); - return NULL; - } - if (jmh.Attribute & JAM_MSG_DELETED) { - JAM_DelSubPacket(jsp); - JAM_CloseMB(jb); - free(jb); - return NULL; - } - - for (z = 0; z < jsp->NumFields; z++) { - if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { - subject = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) { - from = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) { - to = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) { - daddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) { - oaddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) { - msgid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } else if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) { - replyid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); - } - } - JAM_DelSubPacket(jsp); - - if (subject == NULL) { - subject = strdup("(No Subject)"); - } - - if (from == NULL) { - from = strdup("(No Sender)"); - } - - if (to == NULL) { - to = strdup("(No Recipient)"); - } - - if (jmh.Attribute & JAM_MSG_PRIVATE) { - if (!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && - !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && - !msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) && - !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) { - - if (subject != NULL) { - free(subject); - } - if (from != NULL) { - free(from); - } - if (to != NULL) { - free(to); - } - if (oaddress != NULL) { - free(oaddress); - } - if (daddress != NULL) { - free(daddress); - } - if (msgid != NULL) { - free(msgid); - } - if (replyid != NULL) { - free(replyid); - } - JAM_CloseMB(jb); - free(jb); - return NULL; - } - } - body = (char *)malloz(jmh.TxtLen + 1); - - JAM_ReadMsgText(jb, jmh.TxtOffset, jmh.TxtLen, (char *)body); - - if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { - jlr.UserCRC = JAM_Crc32(user->loginname, strlen(user->loginname)); - jlr.UserID = user->id; - jlr.HighReadMsg = msg; - } - - jlr.LastReadMsg = msg; - if (jlr.HighReadMsg < msg) { - jlr.HighReadMsg = msg; - } - - JAM_WriteLastRead(jb, user->id, &jlr); - JAM_CloseMB(jb); - free(jb); - - page = (char *)malloz(4096); - max_len = 4096; - len = 0; - - sprintf(buffer, "

%s - %s

\n", conf.www_url, conference, area, conf.mail_conferences[conference]->name, conf.mail_conferences[conference]->mail_areas[area]->name); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - if (msgbase_is_flagged(user, conference, area, msg)) { - sprintf(buffer, "
\n"); - } else { - sprintf(buffer, "
\n"); - } - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - subject_s = www_sanitize(subject); - sprintf(buffer, "
%s
\n", subject_s); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - free(subject_s); - strcat(page, buffer); - len += strlen(buffer); - - from_s = www_sanitize(from); - if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) { - - if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { - sprintf(buffer, "
From: %s (@%s)
\n", from_s, oaddress); - } else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { - nodeno = parse_fido_addr(oaddress); - if (nodeno != NULL) { - nodename = nl_get_bbsname(nodeno, conf.mail_conferences[conference]->domain); - if (strcmp(nodename, "Unknown") == 0) { - sprintf(buffer, "
From: %s (%s)
\n", from_s, oaddress); - } else { - sprintf(buffer, "
From: %s (%s - %s)
\n", from_s, nodename, oaddress); - } - free(nodename); - free(nodeno); - } else { - sprintf(buffer, "
From: %s (%s)
\n", from_s, oaddress); - } - } else { - sprintf(buffer, "
From: %s (%s)
\n", from_s, oaddress); - } - } else { - sprintf(buffer, "
From: %s
\n", from_s); - } - free(from_s); - - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - to_s = www_sanitize(to); - sprintf(buffer, "
To: %s
\n", to_s); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - free(to_s); - strcat(page, buffer); - len += strlen(buffer); - - date = (time_t)jmh.DateWritten; - gmtime_r(&date, &msg_date); - if (conf.date_style == 1) { - sprintf(buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); - } else { - sprintf(buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); - } - - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "
", conf.www_url, conference, area, msg, conf.www_url); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "
\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - sprintf(buffer, "
\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - aha_text = (char *)malloz(jmh.TxtLen + 1); - - memcpy(aha_text, body, jmh.TxtLen); - aha_text[jmh.TxtLen] = '\0'; - aha_out = aha(aha_text); - while (len + strlen(aha_out) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, aha_out); - len += strlen(aha_out); - - free(aha_out); - free(aha_text); - - sprintf(buffer, "
\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "
\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { - sprintf(buffer, "

Reply

\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - sprintf(buffer, "
\n", conf.www_url); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "\n", conference); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - sprintf(buffer, "\n", area); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "\n", msgid); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "To :
\n", from); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - if (strncasecmp(subject, "re:", 3) == 0) { - sprintf(buffer, "Subject :
\n", subject); - } else { - sprintf(buffer, "Subject :
\n", subject); - } - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "\n
"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "\n
"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "
\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - - sprintf(buffer, "
\n"); - if (len + strlen(buffer) > max_len - 1) { - max_len += 4096; - page = (char *)realloc(page, max_len); - } - strcat(page, buffer); - len += strlen(buffer); - } - if (subject != NULL) { - free(subject); - } - if (from != NULL) { - free(from); - } - if (to != NULL) { - free(to); - } - if (oaddress != NULL) { - free(oaddress); - } - if (daddress != NULL) { - free(daddress); - } - if (msgid != NULL) { - free(msgid); - } - if (replyid != NULL) { - free(replyid); - } - return page; - } else { + if (!(conf.mail_conferences[conference]->sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->read_sec_level <= user->sec_level)) { return NULL; } + jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path); + if (!jb) { + return NULL; + } + + JAM_ReadMBHeader(jb, &jbh); + + memset(&jmh, 0, sizeof(s_JamMsgHeader)); + z = JAM_ReadMsgHeader(jb, msg - 1, &jmh, &jsp); + if (z != 0) { + JAM_CloseMB(jb); + free(jb); + return NULL; + } + if (jmh.Attribute & JAM_MSG_DELETED) { + JAM_DelSubPacket(jsp); + JAM_CloseMB(jb); + free(jb); + return NULL; + } + + for (z = 0; z < jsp->NumFields; z++) { + if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) { + subject = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_SENDERNAME) { + from = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_RECVRNAME) { + to = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_DADDRESS) { + daddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_OADDRESS) { + oaddress = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_MSGID) { + msgid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } else if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) { + replyid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen); + } + } + JAM_DelSubPacket(jsp); + + if (subject == NULL) { + subject = strdup("(No Subject)"); + } + + if (from == NULL) { + from = strdup("(No Sender)"); + } + + if (to == NULL) { + to = strdup("(No Recipient)"); + } + + if (jmh.Attribute & JAM_MSG_PRIVATE) { + if (!msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && + !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, conf.mail_conferences[conference]->realnames, conference) && + !msg_is_to(user, to, daddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference) && + !msg_is_from(user, from, oaddress, conf.mail_conferences[conference]->nettype, !conf.mail_conferences[conference]->realnames, conference)) { + + free(subject); + free(from); + free(to); + free(oaddress); + free(daddress); + free(msgid); + free(replyid); + JAM_CloseMB(jb); + free(jb); + return NULL; + } + } + body = (char *)malloz(jmh.TxtLen + 1); + + JAM_ReadMsgText(jb, jmh.TxtOffset, jmh.TxtLen, (char *)body); + + if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { + jlr.UserCRC = JAM_Crc32(user->loginname, strlen(user->loginname)); + jlr.UserID = user->id; + jlr.HighReadMsg = msg; + } + + jlr.LastReadMsg = msg; + if (jlr.HighReadMsg < msg) { + jlr.HighReadMsg = msg; + } + + JAM_WriteLastRead(jb, user->id, &jlr); + JAM_CloseMB(jb); + free(jb); + + stralloc_copys(&page, "

"); + stralloc_cats(&page, conf.mail_conferences[conference]->name); + stralloc_cats(&page, " - "); + stralloc_cats(&page, conf.mail_conferences[conference]->mail_areas[area]->name); + stralloc_cats(&page, "

\n"); + + if (msgbase_is_flagged(user, conference, area, msg)) { + stralloc_cats(&page, "
\n"); + } else { + stralloc_cats(&page, "
\n"); + } + + subject_s = www_sanitize(subject); + stralloc_cats(&page, "
"); + stralloc_cats(&page, subject_s); + stralloc_cats(&page, "
\n"); + free(subject_s); + + from_s = www_sanitize(from); + if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_LOCAL_AREA && oaddress != NULL) { + if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { + snprintf(buffer, sizeof buffer, "
From: %s (@%s)
\n", from_s, oaddress); + } else if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { + nodeno = parse_fido_addr(oaddress); + if (nodeno != NULL) { + nodename = nl_get_bbsname(nodeno, conf.mail_conferences[conference]->domain); + if (strcmp(nodename, "Unknown") == 0) { + snprintf(buffer, sizeof buffer, "
From: %s (%s)
\n", from_s, oaddress); + } else { + snprintf(buffer, sizeof buffer, "
From: %s (%s - %s)
\n", from_s, nodename, oaddress); + } + free(nodename); + free(nodeno); + } else { + snprintf(buffer, sizeof buffer, "
From: %s (%s)
\n", from_s, oaddress); + } + } else { + snprintf(buffer, sizeof buffer, "
From: %s (%s)
\n", from_s, oaddress); + } + } else { + snprintf(buffer, sizeof buffer, "
From: %s
\n", from_s); + } + free(from_s); + + stralloc_cats(&page, buffer); + + to_s = www_sanitize(to); + stralloc_cats(&page, "
To: "); + stralloc_cats(&page, to_s); + stralloc_cats(&page, "
\n"); + free(to_s); + + date = (time_t)jmh.DateWritten; + gmtime_r(&date, &msg_date); + if (conf.date_style == 1) { + snprintf(buffer, sizeof buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mon + 1, msg_date.tm_mday, msg_date.tm_year - 100); + } else { + snprintf(buffer, sizeof buffer, "
Date: %.2d:%.2d %.2d-%.2d-%.2d
\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + } + + stralloc_cats(&page, buffer); + + snprintf(buffer, sizeof buffer, "
", conf.www_url, conference, area, msg, conf.www_url); + stralloc_cats(&page, buffer); + + stralloc_cats(&page, "
\n"); + stralloc_cats(&page, "
\n"); + + aha_text = strndup(body, jmh.TxtLen); + aha_out = aha(aha_text); + stralloc_cats(&page, aha_out); + + free(aha_out); + free(aha_text); + + stralloc_cats(&page, "
\n"); + + stralloc_cats(&page, "
\n"); + if (conf.mail_conferences[conference]->mail_areas[area]->write_sec_level <= user->sec_level && conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) { + stralloc_cats(&page, "

Reply

\n"); + stralloc_cats(&page, "
\n"); + + stralloc_cats(&page, "\n"); + + stralloc_cats(&page, "\n"); + + stralloc_cats(&page, "\n"); + + stralloc_cats(&page, "To :
\n"); + + stralloc_cats(&page, "Subject :
\n"); + + stralloc_cats(&page, "\n
"); + stralloc_cats(&page, "\n
"); + stralloc_cats(&page, "
\n"); + stralloc_cats(&page, "
\n"); + } + stralloc_0(&page); + + free(subject); + free(from); + free(to); + free(oaddress); + free(daddress); + free(msgid); + free(replyid); + + return page.s; } static char *www_wordwrap(char *content, int cutoff) { @@ -899,12 +700,14 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) { if (conf.mail_conferences[conference]->fidoaddr->point) { - sprintf(buffer, "%d:%d/%d.%d", conf.mail_conferences[conference]->fidoaddr->zone, + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d", + conf.mail_conferences[conference]->fidoaddr->zone, conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->node, conf.mail_conferences[conference]->fidoaddr->point); } else { - sprintf(buffer, "%d:%d/%d", conf.mail_conferences[conference]->fidoaddr->zone, + snprintf(buffer, sizeof buffer, "%d:%d/%d", + conf.mail_conferences[conference]->fidoaddr->zone, conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->node); } @@ -914,7 +717,8 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - sprintf(buffer, "%d:%d/%d.%d %08lx", conf.mail_conferences[conference]->fidoaddr->zone, + snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx", + conf.mail_conferences[conference]->fidoaddr->zone, conf.mail_conferences[conference]->fidoaddr->net, conf.mail_conferences[conference]->fidoaddr->node, conf.mail_conferences[conference]->fidoaddr->point, @@ -936,7 +740,7 @@ int www_send_msg(struct user_record *user, char *to, char *subj, int conference, jmh.ReplyCRC = JAM_Crc32(buffer, strlen(replyid)); } } else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) { - sprintf(buffer, "%d", conf.mail_conferences[conference]->maginode); + snprintf(buffer, sizeof buffer, "%d", conf.mail_conferences[conference]->maginode); jsf.LoID = JAMSFLD_OADDRESS; jsf.HiID = 0; jsf.DatLen = strlen(buffer);