2016-08-20 03:52:02 +00:00
|
|
|
#if defined(ENABLE_WWW)
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/utsname.h>
|
2017-03-17 09:50:37 +00:00
|
|
|
#include <sys/stat.h>
|
2018-05-23 07:21:53 +00:00
|
|
|
#include <iconv.h>
|
2016-08-20 03:52:02 +00:00
|
|
|
#include "bbs.h"
|
|
|
|
#include "jamlib/jam.h"
|
2018-05-22 11:02:22 +00:00
|
|
|
#include "libuuid/uuid.h"
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2016-08-21 09:32:09 +00:00
|
|
|
#define IN 0
|
|
|
|
#define OUT 1
|
2018-10-08 14:13:11 +00:00
|
|
|
extern char *aha(char *input);
|
2016-08-20 03:52:02 +00:00
|
|
|
extern struct bbs_config conf;
|
|
|
|
|
2018-02-05 05:07:50 +00:00
|
|
|
static char *www_wordwrap(char *content, int cutoff);
|
2018-02-15 04:43:37 +00:00
|
|
|
char *www_sanitize(char *inp) {
|
2017-04-28 08:27:01 +00:00
|
|
|
int i;
|
|
|
|
char *result;
|
|
|
|
int len = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
for (i = 0; i < strlen(inp); i++) {
|
2017-04-28 08:27:01 +00:00
|
|
|
if ((inp[i] == '<') || (inp[i] == '>')) {
|
|
|
|
len += 4;
|
|
|
|
} else if (inp[i] == '&') {
|
|
|
|
len += 5;
|
|
|
|
} else {
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:55:13 +00:00
|
|
|
result = (char *)malloz(len + 1);
|
2017-04-28 08:27:01 +00:00
|
|
|
len = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
for (i = 0; i < strlen(inp); i++) {
|
|
|
|
if (inp[i] == '<') {
|
2017-04-28 08:27:01 +00:00
|
|
|
result[len++] = '&';
|
|
|
|
result[len++] = 'l';
|
|
|
|
result[len++] = 't';
|
|
|
|
result[len++] = ';';
|
|
|
|
} else if (inp[i] == '>') {
|
|
|
|
result[len++] = '&';
|
|
|
|
result[len++] = 'g';
|
|
|
|
result[len++] = 't';
|
2018-10-08 14:13:11 +00:00
|
|
|
result[len++] = ';';
|
2017-04-28 08:27:01 +00:00
|
|
|
} else if (inp[i] == '&') {
|
|
|
|
result[len++] = '&';
|
|
|
|
result[len++] = 'a';
|
|
|
|
result[len++] = 'm';
|
|
|
|
result[len++] = 'p';
|
|
|
|
result[len++] = ';';
|
|
|
|
} else {
|
|
|
|
result[len++] = inp[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
char *www_msgs_arealist(struct user_record *user) {
|
2018-10-11 01:46:12 +00:00
|
|
|
stralloc page = EMPTY_STRALLOC;
|
2016-08-20 03:52:02 +00:00
|
|
|
int i, j;
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 01:46:12 +00:00
|
|
|
stralloc_copys(&page, "<div class=\"content-header\"><h2>Message Conferences</h2></div>\n");
|
2018-10-08 14:13:11 +00:00
|
|
|
for (i = 0; i < conf.mail_conference_count; i++) {
|
2016-08-20 03:52:02 +00:00
|
|
|
if (conf.mail_conferences[i]->sec_level <= user->sec_level) {
|
2018-10-11 01:46:12 +00:00
|
|
|
stralloc_cats(&page, "<div class=\"conference-list-item\">");
|
|
|
|
stralloc_cats(&page, conf.mail_conferences[i]->name);
|
|
|
|
stralloc_cats(&page, "</div>\n");
|
2018-10-08 14:13:11 +00:00
|
|
|
for (j = 0; j < conf.mail_conferences[i]->mail_area_count; j++) {
|
2018-10-11 01:46:12 +00:00
|
|
|
if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level > user->sec_level) {
|
|
|
|
continue;
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-11 01:46:12 +00:00
|
|
|
stralloc_cats(&page, "<div class=\"area-list-");
|
|
|
|
stralloc_cats(&page, (new_messages(user, i, j) > 0) ? "new" : "item");
|
|
|
|
stralloc_cats(&page, "\"><a href=\"");
|
|
|
|
stralloc_cats(&page, conf.www_url);
|
|
|
|
stralloc_cats(&page, "msgs/");
|
|
|
|
stralloc_cat_long(&page, i);
|
|
|
|
stralloc_append1(&page, '/');
|
|
|
|
stralloc_cat_long(&page, j);
|
|
|
|
stralloc_cats(&page, "/\">");
|
|
|
|
stralloc_cats(&page, conf.mail_conferences[i]->mail_areas[j]->name);
|
|
|
|
stralloc_cats(&page, "</a></div>\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-11 01:46:12 +00:00
|
|
|
stralloc_0(&page);
|
|
|
|
return page.s;
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *www_msgs_messagelist(struct user_record *user, int conference, int area, int skip) {
|
|
|
|
struct msg_headers *mhrs;
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc page = EMPTY_STRALLOC;
|
2016-08-20 03:52:02 +00:00
|
|
|
char buffer[4096];
|
|
|
|
int i;
|
|
|
|
struct tm msg_date;
|
|
|
|
time_t date;
|
|
|
|
s_JamBase *jb;
|
|
|
|
s_JamLastRead jlr;
|
|
|
|
int skip_f;
|
|
|
|
int skip_t;
|
2017-04-28 08:27:01 +00:00
|
|
|
char *to;
|
|
|
|
char *from;
|
|
|
|
char *subject;
|
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_copys(&page, "<div class=\"content-header\"><h2>");
|
|
|
|
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, "</h2></div>\n");
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2016-08-20 10:26:38 +00:00
|
|
|
if (conf.mail_conferences[conference]->mail_areas[area]->type != TYPE_NETMAIL_AREA) {
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "<div class=\"button\"><a href=\"");
|
|
|
|
stralloc_cats(&page, conf.www_url);
|
|
|
|
stralloc_cats(&page, "msgs/new/");
|
|
|
|
stralloc_cat_long(&page, conference);
|
|
|
|
stralloc_append1(&page, '/');
|
|
|
|
stralloc_cat_long(&page, area);
|
|
|
|
stralloc_cats(&page, "\">New Message</a></div>\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-02-18 03:51:39 +00:00
|
|
|
mhrs = read_message_headers(conference, area, user, 0);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (mhrs == NULL) {
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "<h3>No Messages</h3>\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "<div class=\"div-table\">\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
|
|
|
|
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
|
|
|
|
if (!jb) {
|
2018-10-11 20:43:04 +00:00
|
|
|
free(page.s);
|
2018-02-10 06:01:30 +00:00
|
|
|
free_message_headers(mhrs);
|
2016-08-20 03:52:02 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) {
|
|
|
|
jlr.LastReadMsg = 0;
|
|
|
|
jlr.HighReadMsg = 0;
|
|
|
|
}
|
|
|
|
JAM_CloseMB(jb);
|
2018-02-10 06:01:30 +00:00
|
|
|
free(jb);
|
2016-08-20 03:52:02 +00:00
|
|
|
skip_f = mhrs->msg_count - skip;
|
|
|
|
skip_t = mhrs->msg_count - skip - 50;
|
|
|
|
if (skip_t < 0) {
|
|
|
|
skip_t = 0;
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
|
|
|
for (i = skip_f - 1; i >= skip_t; i--) {
|
2016-08-20 03:52:02 +00:00
|
|
|
date = (time_t)mhrs->msgs[i]->msg_h->DateWritten;
|
2017-04-21 10:31:41 +00:00
|
|
|
gmtime_r(&date, &msg_date);
|
2017-04-28 08:27:01 +00:00
|
|
|
to = www_sanitize(mhrs->msgs[i]->to);
|
|
|
|
from = www_sanitize(mhrs->msgs[i]->from);
|
|
|
|
subject = www_sanitize(mhrs->msgs[i]->subject);
|
2018-05-30 06:21:55 +00:00
|
|
|
if (msgbase_is_flagged(user, conference, area, mhrs->msgs[i]->msg_h->MsgNum)) {
|
2018-05-21 22:55:44 +00:00
|
|
|
if (conf.date_style == 1) {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-flag\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\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);
|
2018-05-21 22:55:44 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-flag\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\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);
|
2018-05-21 22:55:44 +00:00
|
|
|
}
|
|
|
|
} else if (mhrs->msgs[i]->msg_h->MsgNum > jlr.HighReadMsg) {
|
2017-10-03 02:09:50 +00:00
|
|
|
if (conf.date_style == 1) {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-summary\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\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);
|
2017-10-03 02:09:50 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-summary\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\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);
|
2017-10-03 02:09:50 +00:00
|
|
|
}
|
2016-08-20 03:52:02 +00:00
|
|
|
} else {
|
2017-10-03 02:09:50 +00:00
|
|
|
if (conf.date_style == 1) {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-seen\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\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);
|
2017-10-03 02:09:50 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-seen\"><div class=\"msg-summary-id\">%d</div><div class=\"msg-summary-subject\"><a href=\"%smsgs/%d/%d/%d\">%s</a></div><div class=\"msg-summary-from\">%s</div><div class=\"msg-summary-to\">%s</div><div class=\"msg-summary-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\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);
|
2017-10-03 02:09:50 +00:00
|
|
|
}
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2017-04-28 08:27:01 +00:00
|
|
|
|
|
|
|
free(to);
|
|
|
|
free(from);
|
|
|
|
free(subject);
|
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, buffer);
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "</div>\n");
|
2018-05-31 04:00:18 +00:00
|
|
|
if (skip + 50 <= mhrs->msg_count) {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer,
|
|
|
|
"<div class=\"msg-summary-next\"><a href=\"%smsgs/%d/%d/?skip=%d\">Next</a></div>\n",
|
|
|
|
conf.www_url, conference, area, skip + 50);
|
|
|
|
stralloc_cats(&page, buffer);
|
2018-05-31 04:00:18 +00:00
|
|
|
}
|
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (skip > 0) {
|
|
|
|
if (skip - 50 < 0) {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-prev\"><a href=\"%smsgs/%d/%d/\">Prev</a></div>\n", conf.www_url, conference, area);
|
2016-08-20 03:52:02 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-summary-prev\"><a href=\"%smsgs/%d/%d/?skip=%d\">Prev</a></div>\n", conf.www_url, conference, area, skip - 50);
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, buffer);
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_0(&page);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
free_message_headers(mhrs);
|
2018-10-11 20:43:04 +00:00
|
|
|
return page.s;
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *www_msgs_messageview(struct user_record *user, int conference, int area, int msg) {
|
|
|
|
s_JamBase *jb;
|
|
|
|
s_JamMsgHeader jmh;
|
2018-10-08 14:13:11 +00:00
|
|
|
s_JamSubPacket *jsp;
|
2016-08-20 03:52:02 +00:00
|
|
|
s_JamSubfield jsf;
|
|
|
|
s_JamLastRead jlr;
|
|
|
|
s_JamBaseHeader jbh;
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
char *subject = NULL;
|
|
|
|
char *from = NULL;
|
|
|
|
char *to = NULL;
|
|
|
|
char *daddress = NULL;
|
|
|
|
char *oaddress = NULL;
|
|
|
|
char *msgid = NULL;
|
|
|
|
char *replyid = NULL;
|
|
|
|
char *body = NULL;
|
2018-02-05 05:07:50 +00:00
|
|
|
char *body2 = NULL;
|
2018-04-20 06:20:05 +00:00
|
|
|
char *replybody = NULL;
|
2016-08-20 03:52:02 +00:00
|
|
|
int z;
|
|
|
|
struct tm msg_date;
|
|
|
|
time_t date;
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc page = EMPTY_STRALLOC;
|
2018-10-08 14:13:11 +00:00
|
|
|
char buffer[4096];
|
2016-08-20 11:19:11 +00:00
|
|
|
int chars;
|
|
|
|
int i;
|
2017-04-28 08:27:01 +00:00
|
|
|
char *from_s;
|
|
|
|
char *subject_s;
|
|
|
|
char *to_s;
|
2018-04-20 06:20:05 +00:00
|
|
|
int l1, l2;
|
2017-03-30 12:49:49 +00:00
|
|
|
char *aha_text;
|
|
|
|
char *aha_out;
|
2018-05-25 12:26:22 +00:00
|
|
|
char *nodename;
|
2018-05-25 12:30:54 +00:00
|
|
|
struct fido_addr *nodeno;
|
2017-03-30 23:30:23 +00:00
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
JAM_ReadMBHeader(jb, &jbh);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
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) {
|
2018-10-08 14:13:11 +00:00
|
|
|
JAM_DelSubPacket(jsp);
|
2018-10-11 20:43:04 +00:00
|
|
|
JAM_CloseMB(jb);
|
|
|
|
free(jb);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
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);
|
2018-01-22 02:48:43 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
}
|
|
|
|
JAM_DelSubPacket(jsp);
|
2018-01-22 02:48:43 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
if (subject == NULL) {
|
|
|
|
subject = strdup("(No Subject)");
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
if (from == NULL) {
|
|
|
|
from = strdup("(No Sender)");
|
|
|
|
}
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
if (to == NULL) {
|
|
|
|
to = strdup("(No Recipient)");
|
|
|
|
}
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
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)) {
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
free(subject);
|
|
|
|
free(from);
|
|
|
|
free(to);
|
|
|
|
free(oaddress);
|
|
|
|
free(daddress);
|
|
|
|
free(msgid);
|
|
|
|
free(replyid);
|
|
|
|
JAM_CloseMB(jb);
|
|
|
|
free(jb);
|
|
|
|
return NULL;
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
}
|
|
|
|
body = (char *)malloz(jmh.TxtLen + 1);
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
JAM_ReadMsgText(jb, jmh.TxtOffset, jmh.TxtLen, (char *)body);
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
jlr.LastReadMsg = msg;
|
|
|
|
if (jlr.HighReadMsg < msg) {
|
|
|
|
jlr.HighReadMsg = msg;
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
JAM_WriteLastRead(jb, user->id, &jlr);
|
|
|
|
JAM_CloseMB(jb);
|
|
|
|
free(jb);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_copys(&page, "<div class=\"content-header\"><a href=\"");
|
|
|
|
stralloc_cats(&page, conf.www_url);
|
|
|
|
stralloc_cats(&page, "msgs/");
|
|
|
|
stralloc_cat_long(&page, conference);
|
|
|
|
stralloc_append1(&page, '/');
|
|
|
|
stralloc_cat_long(&page, area);
|
|
|
|
stralloc_cats(&page, "\"><h2>");
|
|
|
|
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, "</h2></a></div>\n");
|
|
|
|
|
|
|
|
if (msgbase_is_flagged(user, conference, area, msg)) {
|
|
|
|
stralloc_cats(&page, "<div class=\"msg-view-header-flagged\">\n");
|
|
|
|
} else {
|
|
|
|
stralloc_cats(&page, "<div class=\"msg-view-header\">\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
subject_s = www_sanitize(subject);
|
|
|
|
stralloc_cats(&page, "<div class=\"msg-view-subject\">");
|
|
|
|
stralloc_cats(&page, subject_s);
|
|
|
|
stralloc_cats(&page, "</div>\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, "<div class=\"msg-view-from\">From: %s (@%s)</div>\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, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress);
|
2018-05-25 12:26:22 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (<span class=\"bbsname\">%s</span> - %s)</div>\n", from_s, nodename, oaddress);
|
2018-05-25 12:26:22 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
free(nodename);
|
|
|
|
free(nodeno);
|
2018-05-25 12:26:22 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress);
|
2018-05-25 12:26:22 +00:00
|
|
|
}
|
2016-08-20 03:52:02 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s (%s)</div>\n", from_s, oaddress);
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
} else {
|
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-view-from\">From: %s</div>\n", from_s);
|
|
|
|
}
|
|
|
|
free(from_s);
|
2017-04-28 08:27:01 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, buffer);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
to_s = www_sanitize(to);
|
|
|
|
stralloc_cats(&page, "<div class=\"msg-view-to\">To: ");
|
|
|
|
stralloc_cats(&page, to_s);
|
|
|
|
stralloc_cats(&page, "</div>\n");
|
|
|
|
free(to_s);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
date = (time_t)jmh.DateWritten;
|
|
|
|
gmtime_r(&date, &msg_date);
|
|
|
|
if (conf.date_style == 1) {
|
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\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, "<div class=\"msg-view-date\">Date: %.2d:%.2d %.2d-%.2d-%.2d</div>\n", msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
|
|
|
}
|
2018-05-22 02:20:38 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, buffer);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "<div class=\"msg-view-options\"><a href=\"%smsgs/flag/%d/%d/%d\"><img src=\"%sstatic/flag.png\" /></a></div>", conf.www_url, conference, area, msg, conf.www_url);
|
|
|
|
stralloc_cats(&page, buffer);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "</div>\n");
|
|
|
|
stralloc_cats(&page, "<div id=\"msgbody\">\n");
|
2017-03-30 21:39:04 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
aha_text = strndup(body, jmh.TxtLen);
|
|
|
|
aha_out = aha(aha_text);
|
|
|
|
stralloc_cats(&page, aha_out);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
free(aha_out);
|
|
|
|
free(aha_text);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "</div>\n");
|
2016-08-20 11:19:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "<div class=\"msg-reply-form\">\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, "<h3>Reply</h3>\n");
|
|
|
|
stralloc_cats(&page, "<form action=\"");
|
|
|
|
stralloc_cats(&page, conf.www_url);
|
|
|
|
stralloc_cats(&page, "msgs/\" method=\"POST\" enctype=\"application/x-www-form-urlencoded;charset=UTF-8\">\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "<input type=\"hidden\" name=\"conference\" value=\"");
|
|
|
|
stralloc_cat_long(&page, conference);
|
|
|
|
stralloc_cats(&page, "\" />\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "<input type=\"hidden\" name=\"area\" value=\"");
|
|
|
|
stralloc_cat_long(&page, area);
|
|
|
|
stralloc_cats(&page, "\" />\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "<input type=\"hidden\" name=\"replyid\" value=\"");
|
2018-10-12 01:11:44 +00:00
|
|
|
if (msgid == NULL) {
|
|
|
|
stralloc_cats(&page, "NULL");
|
|
|
|
} else {
|
|
|
|
stralloc_cats(&page, msgid);
|
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "\" />\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "To : <input type=\"text\" name=\"recipient\" value=\"");
|
|
|
|
stralloc_cats(&page, from);
|
|
|
|
stralloc_cats(&page, "\" /><br />\n");
|
2016-08-20 11:19:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "Subject : <input type=\"text\" name=\"subject\" value=\"");
|
2018-10-12 07:25:30 +00:00
|
|
|
if (strncasecmp(subject, "re:", 3) != 0) {
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "RE: ");
|
|
|
|
}
|
|
|
|
stralloc_cats(&page, subject);
|
|
|
|
stralloc_cats(&page, "\" /><br />\n");
|
2016-08-20 11:19:11 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, "<textarea name=\"body\" rows=\"25\" cols=\"79\" wrap=\"soft\" id=\"replybody\">");
|
2018-04-20 06:20:05 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_append1(&page, ' ');
|
|
|
|
stralloc_append1(&page, from[0]);
|
|
|
|
stralloc_cats(&page, "> ");
|
2018-04-20 06:20:05 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
replybody = (char *)malloz(strlen(body) + 1);
|
2018-02-05 05:07:50 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
l2 = 0;
|
|
|
|
for (l1 = 0; l1 < strlen(body); l1++) {
|
|
|
|
if (body[l1] == '\e' && body[l1 + 1] == '[') {
|
|
|
|
while (strchr("ABCDEFGHIGJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", body[l1]) == NULL && l1 < strlen(body))
|
|
|
|
l1++;
|
2018-02-05 05:07:50 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
replybody[l2++] = body[l1];
|
|
|
|
replybody[l2] = '\0';
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
}
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
free(body);
|
|
|
|
chars = 0;
|
|
|
|
body2 = www_wordwrap(replybody, 69);
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
if (body2 == NULL) {
|
|
|
|
body2 = replybody;
|
|
|
|
} else {
|
|
|
|
free(replybody);
|
|
|
|
}
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
for (i = 0; i < strlen(body2); i++) {
|
|
|
|
if (body2[i] == '\r') {
|
|
|
|
snprintf(buffer, sizeof buffer, "\n %c> ", from[0]);
|
|
|
|
chars = 0;
|
|
|
|
} else if (chars == 73) {
|
|
|
|
snprintf(buffer, sizeof buffer, "\n %c> %c", from[0], body2[i]);
|
|
|
|
chars = 1;
|
|
|
|
} else {
|
|
|
|
snprintf(buffer, sizeof buffer, "%c", body2[i]);
|
|
|
|
chars++;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_cats(&page, buffer);
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
free(body2);
|
|
|
|
stralloc_cats(&page, "</textarea>\n<br />");
|
|
|
|
stralloc_cats(&page, "<input type=\"submit\" name=\"submit\" value=\"Reply\" />\n<br />");
|
|
|
|
stralloc_cats(&page, "</form>\n");
|
|
|
|
stralloc_cats(&page, "</div>\n");
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-11 20:43:04 +00:00
|
|
|
stralloc_0(&page);
|
|
|
|
|
|
|
|
free(subject);
|
|
|
|
free(from);
|
|
|
|
free(to);
|
|
|
|
free(oaddress);
|
|
|
|
free(daddress);
|
|
|
|
free(msgid);
|
|
|
|
free(replyid);
|
|
|
|
|
|
|
|
return page.s;
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
|
|
|
|
2018-02-05 05:07:50 +00:00
|
|
|
static char *www_wordwrap(char *content, int cutoff) {
|
2018-01-26 05:02:48 +00:00
|
|
|
int len = strlen(content);
|
|
|
|
int i;
|
2018-02-05 09:48:21 +00:00
|
|
|
int line_count = 0;
|
2018-01-26 05:02:48 +00:00
|
|
|
char *last_space = NULL;
|
2018-02-27 11:50:22 +00:00
|
|
|
char *ret;
|
2018-01-26 05:02:48 +00:00
|
|
|
int at = 0;
|
2018-02-05 06:23:33 +00:00
|
|
|
int extra = 0;
|
2018-02-27 23:10:27 +00:00
|
|
|
int quote_line = 0;
|
2018-05-25 12:38:11 +00:00
|
|
|
int z;
|
2018-02-27 11:59:04 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2018-02-27 11:59:04 +00:00
|
|
|
if (content[i] == '\n') {
|
|
|
|
continue;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
2018-02-27 11:59:04 +00:00
|
|
|
content[at++] = content[i];
|
|
|
|
}
|
2018-02-27 12:28:28 +00:00
|
|
|
|
2018-02-27 11:59:04 +00:00
|
|
|
content[at] = '\0';
|
2018-02-27 11:36:32 +00:00
|
|
|
at = 0;
|
2018-02-27 11:59:04 +00:00
|
|
|
len = strlen(content);
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
for (i = 0; i < len - 1; i++) {
|
2018-02-27 23:10:27 +00:00
|
|
|
if (content[i] == '>' && line_count < 4) {
|
|
|
|
quote_line = 1;
|
|
|
|
}
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
if (content[i] == '\r' && content[i + 1] != '\r') {
|
|
|
|
if (content[i + 1] == ' ' && quote_line != 1) {
|
2018-02-27 12:28:28 +00:00
|
|
|
content[at++] = '\r';
|
2018-02-27 23:10:27 +00:00
|
|
|
line_count = 0;
|
|
|
|
quote_line = 0;
|
2018-02-27 23:40:07 +00:00
|
|
|
} else if (quote_line != 1) {
|
2018-10-08 14:13:11 +00:00
|
|
|
for (z = i + 1; content[z] != ' ' && z < len; z++)
|
|
|
|
;
|
|
|
|
if (at > 0 && content[at - 1] != '\r' && content[at - 1] != ' ' && cutoff - line_count < z - i) {
|
2018-02-27 23:40:07 +00:00
|
|
|
content[at++] = ' ';
|
|
|
|
line_count++;
|
2018-05-25 12:42:35 +00:00
|
|
|
} else {
|
|
|
|
content[at++] = '\r';
|
|
|
|
line_count = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
quote_line = 0;
|
2018-05-25 12:42:35 +00:00
|
|
|
}
|
2018-02-27 23:42:10 +00:00
|
|
|
} else if (quote_line == 1) {
|
|
|
|
content[at++] = '\r';
|
|
|
|
line_count = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
quote_line = 0;
|
2018-02-27 12:28:28 +00:00
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
} else if (content[i] == '\r' && content[i + 1] == '\r') {
|
2018-02-27 12:28:28 +00:00
|
|
|
content[at++] = '\r';
|
2018-02-27 11:36:32 +00:00
|
|
|
content[at++] = '\r';
|
2018-02-27 23:10:27 +00:00
|
|
|
line_count = 0;
|
|
|
|
quote_line = 0;
|
2018-02-27 11:36:32 +00:00
|
|
|
i++;
|
|
|
|
} else {
|
|
|
|
content[at++] = content[i];
|
2018-02-27 23:10:27 +00:00
|
|
|
line_count++;
|
2018-02-27 11:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-27 23:58:07 +00:00
|
|
|
content[at++] = content[i];
|
2018-02-27 11:36:32 +00:00
|
|
|
content[at] = '\0';
|
2018-02-27 12:28:28 +00:00
|
|
|
|
2018-02-27 11:36:32 +00:00
|
|
|
at = 0;
|
2018-01-26 05:02:48 +00:00
|
|
|
|
2018-02-27 11:50:22 +00:00
|
|
|
len = strlen(content);
|
2018-10-09 15:55:13 +00:00
|
|
|
ret = (char *)malloz(len + 1);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-02-27 23:10:27 +00:00
|
|
|
line_count = 0;
|
|
|
|
quote_line = 0;
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2018-01-26 05:02:48 +00:00
|
|
|
if (content[i] != '\r') {
|
|
|
|
ret[at] = content[i];
|
|
|
|
if (content[i] == ' ') {
|
|
|
|
last_space = &ret[at];
|
|
|
|
}
|
|
|
|
at++;
|
2018-02-27 23:46:18 +00:00
|
|
|
if (content[i] == '>' && line_count < 4) {
|
|
|
|
quote_line = 1;
|
|
|
|
}
|
2018-01-26 05:02:48 +00:00
|
|
|
} else {
|
2018-02-05 05:30:45 +00:00
|
|
|
ret[at++] = content[i];
|
2018-01-26 05:02:48 +00:00
|
|
|
}
|
2018-02-05 05:30:45 +00:00
|
|
|
ret[at] = '\0';
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-02-05 05:30:45 +00:00
|
|
|
if (content[i] == '\r') {
|
2018-01-26 05:02:48 +00:00
|
|
|
line_count = 0;
|
|
|
|
last_space = NULL;
|
2018-02-27 23:19:55 +00:00
|
|
|
quote_line = 0;
|
2018-02-05 05:07:50 +00:00
|
|
|
} else if (line_count == cutoff) {
|
2018-01-26 05:02:48 +00:00
|
|
|
// wrap
|
2018-02-27 23:10:27 +00:00
|
|
|
if (quote_line == 1) {
|
2018-02-27 23:17:02 +00:00
|
|
|
while (i < len - 1 && content[i + 1] != '\r') {
|
2018-02-27 23:10:27 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
last_space = NULL;
|
|
|
|
line_count = 0;
|
2018-10-08 14:13:11 +00:00
|
|
|
quote_line = 0;
|
2018-02-27 23:10:27 +00:00
|
|
|
} else if (last_space != NULL) {
|
2018-01-26 05:02:48 +00:00
|
|
|
*last_space = '\r';
|
2018-02-05 05:51:44 +00:00
|
|
|
line_count = strlen(&last_space[1]);
|
2018-01-26 05:02:48 +00:00
|
|
|
last_space = NULL;
|
2018-02-27 23:10:27 +00:00
|
|
|
quote_line = 0;
|
2018-02-05 05:07:50 +00:00
|
|
|
} else {
|
2018-02-05 06:23:33 +00:00
|
|
|
extra++;
|
|
|
|
ret = (char *)realloc(ret, strlen(content) + extra + 1);
|
2018-02-05 05:07:50 +00:00
|
|
|
if (ret == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ret[at++] = '\r';
|
|
|
|
ret[at] = '\0';
|
|
|
|
last_space = NULL;
|
2018-02-05 05:51:00 +00:00
|
|
|
line_count = 0;
|
2018-02-27 23:10:27 +00:00
|
|
|
quote_line = 0;
|
2018-01-26 05:02:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
line_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
int www_send_msg(struct user_record *user, char *to, char *subj, int conference, int area, char *replyid, char *body) {
|
|
|
|
s_JamBase *jb;
|
|
|
|
s_JamMsgHeader jmh;
|
2018-10-08 14:13:11 +00:00
|
|
|
s_JamSubPacket *jsp;
|
2016-08-20 03:52:02 +00:00
|
|
|
s_JamSubfield jsf;
|
|
|
|
s_JamLastRead jlr;
|
|
|
|
s_JamBaseHeader jbh;
|
|
|
|
int z;
|
|
|
|
int sem_fd;
|
|
|
|
char *page;
|
|
|
|
int max_len;
|
|
|
|
int len;
|
2018-10-08 14:13:11 +00:00
|
|
|
char buffer[256];
|
2016-08-20 03:52:02 +00:00
|
|
|
char *body2;
|
|
|
|
char *tagline;
|
|
|
|
struct utsname name;
|
2018-01-26 05:02:48 +00:00
|
|
|
char *body3;
|
2018-05-23 07:24:29 +00:00
|
|
|
|
2018-05-23 07:21:53 +00:00
|
|
|
iconv_t ic;
|
|
|
|
size_t inc;
|
|
|
|
size_t ouc;
|
|
|
|
size_t sz;
|
|
|
|
char *inbuf, *oubuf;
|
2018-05-23 07:24:29 +00:00
|
|
|
|
2018-05-22 11:02:22 +00:00
|
|
|
uuid_t magi_msgid;
|
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (conference < 0 || conference >= conf.mail_conference_count || area < 0 || area >= conf.mail_conferences[conference]->mail_area_count) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-01-21 05:02:21 +00:00
|
|
|
if (subj == NULL || to == NULL || body == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-08-20 03:52:02 +00:00
|
|
|
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) {
|
|
|
|
jb = open_jam_base(conf.mail_conferences[conference]->mail_areas[area]->path);
|
|
|
|
if (!jb) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
|
|
|
JAM_ClearMsgHeader(&jmh);
|
2017-04-21 10:31:41 +00:00
|
|
|
jmh.DateWritten = (uint32_t)utc_to_local(time(NULL));
|
2018-10-08 14:13:11 +00:00
|
|
|
jmh.Attribute |= JAM_MSG_LOCAL;
|
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (conf.mail_conferences[conference]->realnames == 0) {
|
2018-10-11 02:49:23 +00:00
|
|
|
strlcpy(buffer, user->loginname, sizeof buffer);
|
2016-08-20 03:52:02 +00:00
|
|
|
} else {
|
2018-10-11 02:49:23 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "%s %s", user->firstname, user->lastname);
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
|
|
|
jsp = JAM_NewSubPacket();
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_SENDERNAME;
|
|
|
|
jsf.HiID = 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
jsf.DatLen = strlen(buffer);
|
|
|
|
jsf.Buffer = (char *)buffer;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_RECVRNAME;
|
|
|
|
jsf.HiID = 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
jsf.DatLen = strlen(to);
|
|
|
|
jsf.Buffer = (char *)to;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_SUBJECT;
|
|
|
|
jsf.HiID = 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
jsf.DatLen = strlen(subj);
|
|
|
|
jsf.Buffer = (char *)subj;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) {
|
2017-03-16 07:57:03 +00:00
|
|
|
jmh.Attribute |= JAM_MSG_TYPEECHO;
|
2016-08-20 03:52:02 +00:00
|
|
|
|
|
|
|
if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
|
|
|
|
if (conf.mail_conferences[conference]->fidoaddr->point) {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "%d:%d/%d.%d",
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->zone,
|
2018-10-08 14:13:11 +00:00
|
|
|
conf.mail_conferences[conference]->fidoaddr->net,
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->node,
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->point);
|
2016-08-20 03:52:02 +00:00
|
|
|
} else {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "%d:%d/%d",
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->zone,
|
2018-10-08 14:13:11 +00:00
|
|
|
conf.mail_conferences[conference]->fidoaddr->net,
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->node);
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_OADDRESS;
|
|
|
|
jsf.HiID = 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
jsf.DatLen = strlen(buffer);
|
|
|
|
jsf.Buffer = (char *)buffer;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
|
|
|
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "%d:%d/%d.%d %08lx",
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->zone,
|
2018-10-08 14:13:11 +00:00
|
|
|
conf.mail_conferences[conference]->fidoaddr->net,
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->node,
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->point,
|
|
|
|
generate_msgid());
|
2016-08-20 03:52:02 +00:00
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_MSGID;
|
|
|
|
jsf.HiID = 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
jsf.DatLen = strlen(buffer);
|
|
|
|
jsf.Buffer = (char *)buffer;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
|
|
|
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-05-22 11:02:22 +00:00
|
|
|
if (strcasecmp(replyid, "NULL") != 0) {
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_REPLYID;
|
|
|
|
jsf.HiID = 0;
|
2018-05-22 11:02:22 +00:00
|
|
|
jsf.DatLen = strlen(replyid);
|
|
|
|
jsf.Buffer = (char *)replyid;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
|
|
|
jmh.ReplyCRC = JAM_Crc32(buffer, strlen(replyid));
|
|
|
|
}
|
|
|
|
} else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
|
2018-10-11 20:43:04 +00:00
|
|
|
snprintf(buffer, sizeof buffer, "%d", conf.mail_conferences[conference]->maginode);
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_OADDRESS;
|
|
|
|
jsf.HiID = 0;
|
2018-05-22 11:02:22 +00:00
|
|
|
jsf.DatLen = strlen(buffer);
|
|
|
|
jsf.Buffer = (char *)buffer;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
|
|
|
|
|
|
|
uuid_generate(magi_msgid);
|
|
|
|
uuid_unparse_lower(magi_msgid, buffer);
|
|
|
|
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_MSGID;
|
|
|
|
jsf.HiID = 0;
|
2018-05-22 11:02:22 +00:00
|
|
|
jsf.DatLen = strlen(buffer);
|
|
|
|
jsf.Buffer = (char *)buffer;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
|
|
|
jmh.MsgIdCRC = JAM_Crc32(buffer, strlen(buffer));
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (strcasecmp(replyid, "NULL") != 0) {
|
2018-10-08 14:13:11 +00:00
|
|
|
jsf.LoID = JAMSFLD_REPLYID;
|
|
|
|
jsf.HiID = 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
jsf.DatLen = strlen(replyid);
|
|
|
|
jsf.Buffer = (char *)replyid;
|
|
|
|
JAM_PutSubfield(jsp, &jsf);
|
|
|
|
jmh.ReplyCRC = JAM_Crc32(buffer, strlen(replyid));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (1) {
|
|
|
|
z = JAM_LockMB(jb, 100);
|
|
|
|
if (z == 0) {
|
|
|
|
break;
|
|
|
|
} else if (z == JAM_LOCK_FAILED) {
|
|
|
|
sleep(1);
|
|
|
|
} else {
|
|
|
|
JAM_CloseMB(jb);
|
2018-02-10 06:01:30 +00:00
|
|
|
free(jb);
|
2016-08-20 03:52:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (z != 0) {
|
|
|
|
JAM_CloseMB(jb);
|
2018-02-10 06:01:30 +00:00
|
|
|
free(jb);
|
2016-08-20 03:52:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-05-23 07:21:53 +00:00
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
if (conf.mail_conferences[conference]->tagline != NULL) {
|
|
|
|
tagline = conf.mail_conferences[conference]->tagline;
|
|
|
|
} else {
|
|
|
|
tagline = conf.default_tagline;
|
2018-10-08 14:13:11 +00:00
|
|
|
}
|
|
|
|
|
2016-08-20 03:52:02 +00:00
|
|
|
uname(&name);
|
|
|
|
|
|
|
|
if (conf.mail_conferences[conference]->nettype == NETWORK_FIDO) {
|
|
|
|
if (conf.mail_conferences[conference]->fidoaddr->point == 0) {
|
2018-01-26 05:02:48 +00:00
|
|
|
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone,
|
2018-10-08 14:13:11 +00:00
|
|
|
conf.mail_conferences[conference]->fidoaddr->net,
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->node);
|
2016-08-20 03:52:02 +00:00
|
|
|
} else {
|
2018-01-26 05:02:48 +00:00
|
|
|
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (%d:%d/%d.%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->fidoaddr->zone,
|
2018-10-08 14:13:11 +00:00
|
|
|
conf.mail_conferences[conference]->fidoaddr->net,
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->node,
|
|
|
|
conf.mail_conferences[conference]->fidoaddr->point);
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-05-22 11:02:22 +00:00
|
|
|
} else if (conf.mail_conferences[conference]->nettype == NETWORK_MAGI) {
|
|
|
|
snprintf(buffer, 256, "\r\r--- MagickaBBS v%d.%d%s (%s/%s)\r * Origin: %s (@%d)\r", VERSION_MAJOR, VERSION_MINOR, VERSION_STR, name.sysname, name.machine, tagline, conf.mail_conferences[conference]->maginode);
|
2016-08-20 03:52:02 +00:00
|
|
|
} else {
|
2018-05-22 11:02:22 +00:00
|
|
|
snprintf(buffer, 256, "\r");
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-02-05 05:07:50 +00:00
|
|
|
body2 = www_wordwrap(body, 73);
|
2018-01-26 05:02:48 +00:00
|
|
|
if (body2 == NULL) {
|
|
|
|
JAM_UnlockMB(jb);
|
|
|
|
JAM_DelSubPacket(jsp);
|
|
|
|
JAM_CloseMB(jb);
|
2018-02-10 06:01:30 +00:00
|
|
|
free(jb);
|
2018-01-26 05:02:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-10-09 15:55:13 +00:00
|
|
|
body3 = str2dup(body2, buffer);
|
2018-01-26 05:02:48 +00:00
|
|
|
if (body3 == NULL) {
|
|
|
|
free(body2);
|
|
|
|
JAM_UnlockMB(jb);
|
|
|
|
JAM_DelSubPacket(jsp);
|
|
|
|
JAM_CloseMB(jb);
|
2018-02-10 06:01:30 +00:00
|
|
|
free(jb);
|
2018-01-26 05:02:48 +00:00
|
|
|
return 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
2018-05-23 07:21:53 +00:00
|
|
|
|
|
|
|
free(body2);
|
2018-10-09 15:55:13 +00:00
|
|
|
body2 = (char *)malloz(strlen(body3) + 1);
|
2018-05-23 07:21:53 +00:00
|
|
|
|
|
|
|
ic = iconv_open("CP437", "UTF-8");
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-05-23 07:21:53 +00:00
|
|
|
inc = strlen(body3);
|
|
|
|
ouc = strlen(body3);
|
|
|
|
|
|
|
|
inbuf = body3;
|
|
|
|
oubuf = body2;
|
|
|
|
sz = iconv(ic, &inbuf, &inc, &oubuf, &ouc);
|
|
|
|
free(body3);
|
|
|
|
|
2018-05-23 09:45:55 +00:00
|
|
|
if (JAM_AddMessage(jb, &jmh, jsp, (char *)body2, oubuf - body2)) {
|
2018-10-08 14:13:11 +00:00
|
|
|
free(body2);
|
2018-01-26 05:02:48 +00:00
|
|
|
JAM_UnlockMB(jb);
|
|
|
|
JAM_DelSubPacket(jsp);
|
|
|
|
JAM_CloseMB(jb);
|
2018-02-10 06:01:30 +00:00
|
|
|
free(jb);
|
2018-05-31 09:13:43 +00:00
|
|
|
iconv_close(ic);
|
2018-01-26 05:02:48 +00:00
|
|
|
return 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
} else {
|
|
|
|
if (conf.mail_conferences[conference]->mail_areas[area]->type == TYPE_ECHOMAIL_AREA) {
|
|
|
|
if (conf.echomail_sem != NULL) {
|
|
|
|
sem_fd = open(conf.echomail_sem, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
|
|
|
|
close(sem_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(body2);
|
|
|
|
|
|
|
|
JAM_UnlockMB(jb);
|
|
|
|
|
|
|
|
JAM_DelSubPacket(jsp);
|
2018-10-08 14:13:11 +00:00
|
|
|
JAM_CloseMB(jb);
|
2018-02-10 06:01:30 +00:00
|
|
|
free(jb);
|
2018-05-31 09:13:43 +00:00
|
|
|
iconv_close(ic);
|
2016-08-20 03:52:02 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2018-01-22 09:21:57 +00:00
|
|
|
return 0;
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *www_new_msg(struct user_record *user, int conference, int area) {
|
2018-10-11 01:46:12 +00:00
|
|
|
stralloc page = EMPTY_STRALLOC;
|
|
|
|
|
|
|
|
stralloc_copys(&page, "<div class=\"content-header\"><h2>New Message</h2></div>\n");
|
|
|
|
stralloc_cats(&page, "<form action=\"");
|
|
|
|
stralloc_cats(&page, conf.www_url);
|
|
|
|
stralloc_cats(&page, "msgs/\" method=\"POST\" onsubmit=\"return validate()\" "
|
2018-10-11 14:02:55 +00:00
|
|
|
"enctype=\"application/x-www-form-urlencoded;charset=UTF-8\">\n");
|
2018-10-11 01:46:12 +00:00
|
|
|
stralloc_cats(&page, "<input type=\"hidden\" name=\"conference\" value=\"");
|
|
|
|
stralloc_cat_long(&page, conference);
|
|
|
|
stralloc_cats(&page, "\" />\n");
|
|
|
|
stralloc_cats(&page, "<input type=\"hidden\" name=\"area\" value=\"");
|
|
|
|
stralloc_cat_long(&page, area);
|
|
|
|
stralloc_cats(&page, "\" />\n");
|
|
|
|
stralloc_cats(&page, "<input type=\"hidden\" name=\"replyid\" value=\"NULL\" />\n");
|
|
|
|
stralloc_cats(&page, "To : <input type=\"text\" name=\"recipient\" value=\"All\" id=\"recipient\"/><br />\n");
|
|
|
|
stralloc_cats(&page, "Subject : <input type=\"text\" name=\"subject\" id=\"subject\" /><br />\n");
|
|
|
|
stralloc_cats(&page, "<textarea name=\"body\" id=\"body\" rows=\"25\" cols=\"79\" wrap=\"soft\"></textarea>\n<br />");
|
|
|
|
stralloc_cats(&page, "<input type=\"submit\" name=\"submit\" value=\"Send\" />\n<br />");
|
|
|
|
stralloc_cats(&page, "</form>\n");
|
|
|
|
stralloc_0(&page);
|
|
|
|
|
|
|
|
return page.s;
|
2016-08-20 03:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|