diff --git a/src/www_msgs.c b/src/www_msgs.c index 9faadf3..9654062 100644 --- a/src/www_msgs.c +++ b/src/www_msgs.c @@ -134,79 +134,80 @@ char *www_msgs_messagelist(struct user_record *user, int conference, int area, i if (mhrs == NULL) { stralloc_cats(&page, "

No Messages

\n"); - } + } else { - stralloc_cats(&page, "
\n"); + stralloc_cats(&page, "
\n"); - jb = open_jam_base(ma->path); - if (!jb) { - free(page.s); + jb = open_jam_base(ma->path); + if (!jb) { + free(page.s); + free_message_headers(mhrs); + return NULL; + } + if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { + jlr.LastReadMsg = 0; + jlr.HighReadMsg = 0; + } + JAM_CloseMB(jb); + free(jb); + skip_f = mhrs->msg_count - skip; + skip_t = mhrs->msg_count - skip - 50; + if (skip_t < 0) { + skip_t = 0; + } + + for (i = skip_f - 1; i >= skip_t; i--) { + date = (time_t)mhrs->msgs[i]->msg_h->DateWritten; + gmtime_r(&date, &msg_date); + to = www_sanitize(mhrs->msgs[i]->to); + from = www_sanitize(mhrs->msgs[i]->from); + 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) { + 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 { + 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) { + 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 { + 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) { + 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 { + 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); + } + } + + free(to); + free(from); + free(subject); + + stralloc_cats(&page, buffer); + } + stralloc_cats(&page, "
\n"); + if (skip + 50 <= mhrs->msg_count) { + snprintf(buffer, sizeof buffer, + "
Next
\n", + conf.www_url, conference, area, skip + 50); + stralloc_cats(&page, buffer); + } + + if (skip > 0) { + if (skip - 50 < 0) { + snprintf(buffer, sizeof buffer, "
Prev
\n", conf.www_url, conference, area); + } else { + snprintf(buffer, sizeof buffer, "
Prev
\n", conf.www_url, conference, area, skip - 50); + } + stralloc_cats(&page, buffer); + } free_message_headers(mhrs); - return NULL; - } - if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) { - jlr.LastReadMsg = 0; - jlr.HighReadMsg = 0; - } - JAM_CloseMB(jb); - free(jb); - skip_f = mhrs->msg_count - skip; - skip_t = mhrs->msg_count - skip - 50; - if (skip_t < 0) { - skip_t = 0; - } - - for (i = skip_f - 1; i >= skip_t; i--) { - date = (time_t)mhrs->msgs[i]->msg_h->DateWritten; - gmtime_r(&date, &msg_date); - to = www_sanitize(mhrs->msgs[i]->to); - from = www_sanitize(mhrs->msgs[i]->from); - 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) { - 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 { - 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) { - 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 { - 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) { - 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 { - 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); - } - } - - free(to); - free(from); - free(subject); - - stralloc_cats(&page, buffer); - } - stralloc_cats(&page, "
\n"); - if (skip + 50 <= mhrs->msg_count) { - snprintf(buffer, sizeof buffer, - "
Next
\n", - conf.www_url, conference, area, skip + 50); - stralloc_cats(&page, buffer); - } - - if (skip > 0) { - if (skip - 50 < 0) { - snprintf(buffer, sizeof buffer, "
Prev
\n", conf.www_url, conference, area); - } else { - snprintf(buffer, sizeof buffer, "
Prev
\n", conf.www_url, conference, area, skip - 50); - } - stralloc_cats(&page, buffer); } stralloc_0(&page); - free_message_headers(mhrs); return page.s; }