summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pamment <apamment@yandex.com>2019-02-25 22:04:04 +1000
committerAndrew Pamment <apamment@yandex.com>2019-02-25 22:04:04 +1000
commitfeb05a41ac9e719031bbb7db31f384c2a113178e (patch)
tree61ab2481bffe798653e9637373f1e9cad4d3ed4d
parentce59f74a1b23303fe27e2fb0855da410f21b80d6 (diff)
Experimental viewing of seenbys
-rwxr-xr-xsrc/mail_menu.c16
-rw-r--r--src/msglib/msglib.h3
-rw-r--r--src/msglib/msglib_jam.c25
-rwxr-xr-xsrc/msglib/msglib_sq3.c71
-rw-r--r--utils/magimail/src/magimail/mb_sq3.c40
5 files changed, 147 insertions, 8 deletions
diff --git a/src/mail_menu.c b/src/mail_menu.c
index 3138931..6083822 100755
--- a/src/mail_menu.c
+++ b/src/mail_menu.c
@@ -1385,6 +1385,7 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno
int should_break;
int position;
int y;
+ int view_seenbys = 0;
struct ptr_vector msg_lines;
init_ptr_vector(&msg_lines);
@@ -1436,11 +1437,23 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno
write_lasthighread(mb, user, last_read, high_read);
}
+ if (view_seenbys == 1 && msghs->msgs[mailno]->seenby != NULL) {
+ stralloc body_salloc = EMPTY_STRALLOC;
+ stralloc_cats(&body_salloc, "\e[1;30m");
+ stralloc_cats(&body_salloc, msghs->msgs[mailno]->seenby);
+ stralloc_cats(&body_salloc, "\e[0m");
+ stralloc_cats(&body_salloc, body);
+ free(body);
+ body = body_salloc.s;
+ }
+
z2 = strlen(body);
lines = 0;
chars = 0;
+
+
body2 = body;
z = z2;
@@ -1517,6 +1530,9 @@ int read_message(struct user_record *user, struct msg_headers *msghs, int mailno
should_break = 1;
} else if (tolower(c) == 'f') {
should_break = 1;
+ } else if (tolower(c) == 'v') {
+ view_seenbys = !view_seenbys;
+ should_break = 1;
} else if (c == '\e') {
c = s_getc();
if (c == 91) {
diff --git a/src/msglib/msglib.h b/src/msglib/msglib.h
index dc1a8cb..efc835b 100644
--- a/src/msglib/msglib.h
+++ b/src/msglib/msglib.h
@@ -17,6 +17,7 @@ struct msg_t {
char *msgid;
char *replyid;
time_t msgwritten;
+ char *seenby;
};
struct msg_headers {
@@ -49,4 +50,4 @@ extern struct msg_t *load_message_hdr(struct msg_base_t *mb, int id);
extern char *load_message_text(struct msg_base_t *mb, struct msg_t *msg);
extern void free_message_hdr(struct msg_t *msg);
extern int write_message(struct msg_base_t *mb, const char *to, const char *from, const char *subj, const char *body, const char *destaddr, struct msg_t *inreplyto, time_t *dwritten, int dosem);
-#endif \ No newline at end of file
+#endif
diff --git a/src/msglib/msglib_jam.c b/src/msglib/msglib_jam.c
index f462932..9e7d452 100644
--- a/src/msglib/msglib_jam.c
+++ b/src/msglib/msglib_jam.c
@@ -88,6 +88,8 @@ struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct us
continue;
}
+ stralloc seenbybuff = EMPTY_STRALLOC;
+
jamm = (struct msg_t *)malloz(sizeof(struct msg_t));
jamm->msg_no = jmh.MsgNum;
jamm->msg_h = (s_JamMsgHeader *)malloz(sizeof(s_JamMsgHeader));
@@ -100,7 +102,8 @@ struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct us
jamm->msgid = NULL;
jamm->replyid = NULL;
jamm->msgwritten = jmh.DateWritten;
-
+ jamm->seenby = NULL;
+
for (z = 0; z < jsp->NumFields; z++) {
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
jamm->subject = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
@@ -116,10 +119,18 @@ struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct us
jamm->msgid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) {
jamm->replyid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
+ } else if (jsp->Fields[z]->LoID == JAMSFLD_SEENBY2D) {
+ stralloc_cats(&seenbybuff, "SEENBY: ");
+ stralloc_catb(&seenbybuff, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
+ stralloc_append1(&seenbybuff, '\r');
}
}
JAM_DelSubPacket(jsp);
+ if (seenbybuff.len > 0) {
+ jamm->seenby = seenbybuff.s;
+ }
+
if (jamm->subject == NULL) {
jamm->subject = strdup("(No Subject)");
}
@@ -446,6 +457,9 @@ struct msg_t *jam_message_header(s_JamBase *jb, int id) {
jamm->msgid = NULL;
jamm->replyid = NULL;
jamm->msgwritten = jmh.DateWritten;
+ jamm->seenby = NULL;
+
+ stralloc seenbybuff = EMPTY_STRALLOC;
for (z = 0; z < jsp->NumFields; z++) {
if (jsp->Fields[z]->LoID == JAMSFLD_SUBJECT) {
@@ -462,8 +476,17 @@ struct msg_t *jam_message_header(s_JamBase *jb, int id) {
jamm->msgid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
} else if (jsp->Fields[z]->LoID == JAMSFLD_REPLYID) {
jamm->replyid = strndup(jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
+ } else if (jsp->Fields[z]->LoID == JAMSFLD_SEENBY2D) {
+ stralloc_cats(&seenbybuff, "SEENBY: ");
+ stralloc_catb(&seenbybuff, jsp->Fields[z]->Buffer, jsp->Fields[z]->DatLen);
+ stralloc_append1(&seenbybuff, '\r');
}
}
+
+ if (seenbybuff.len > 0) {
+ jamm->seenby = seenbybuff.s;
+ }
+
JAM_DelSubPacket(jsp);
if (jamm->subject == NULL) {
diff --git a/src/msglib/msglib_sq3.c b/src/msglib/msglib_sq3.c
index 67456d2..453f759 100755
--- a/src/msglib/msglib_sq3.c
+++ b/src/msglib/msglib_sq3.c
@@ -20,6 +20,7 @@ char *safe_strdup(const char *str) {
static int open_sq3_database(const char *path, sqlite3 **db) {
const char *create_sql = "CREATE TABLE IF NOT EXISTS msgs(id INTEGER PRIMARY KEY, sender TEXT, recipient TEXT, subject TEXT, date INTEGER, mattribs INTEGER, daddress TEXT, oaddress TEXT, msgid TEXT, replyid TEXT, body TEXT);";
const char *create_sql2 = "CREATE TABLE IF NOT EXISTS lastread(userid INTEGER, messageid INTEGER);";
+ const char *create_sql3 = "CREATE TABLE IF NOT EXISTS seenbys(msgid INTEGER, seenby TEXT);";
int rc;
char *err_msg;
@@ -47,7 +48,15 @@ static int open_sq3_database(const char *path, sqlite3 **db) {
sqlite3_close(*db);
return 0;
}
-
+
+ rc = sqlite3_exec(*db, create_sql3, 0, 0, &err_msg);
+ if (rc != SQLITE_OK) {
+ dolog("Unable to create seenbys table: %s", err_msg);
+ free(err_msg);
+ sqlite3_close(*db);
+ return 0;
+ }
+
return 1;
}
@@ -62,9 +71,12 @@ struct msg_headers *sq3_read_message_headers(int msgconf, int msgarea, struct us
char buffer[256];
const char *sql = "SELECT id, sender, recipient, subject, date, mattribs, daddress, oaddress, msgid, replyid FROM msgs";
const char *sql2 = "SELECT id, sender, recipient, subject, date, mattribs, daddress, oaddress, msgid, replyid FROM msgs WHERE recipient = ? or recipient = ? COLLATE NOCASE";
+ const char *sql3 = "SELECT seenby FROM seenbys WHERE msgid = ?";
+
sqlite3 *dbase;
sqlite3_stmt *res;
-
+ sqlite3_stmt *res2;
+
struct fido_addr *dest;
struct msg_headers *msghs = NULL;
struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, msgconf);
@@ -111,6 +123,7 @@ struct msg_headers *sq3_read_message_headers(int msgconf, int msgarea, struct us
msg->daddress = safe_strdup(sqlite3_column_text(res, 6));
msg->msgid = safe_strdup(sqlite3_column_text(res, 8));
msg->replyid = safe_strdup(sqlite3_column_text(res, 9));
+ msg->seenby = NULL;
if (mattrib & SQ3_MSG_PRIVATE) {
if (!msg_is_to(user, msg->to, msg->daddress, mc->nettype, mc->realnames, msgconf) &&
@@ -130,7 +143,25 @@ struct msg_headers *sq3_read_message_headers(int msgconf, int msgarea, struct us
continue;
}
}
-
+
+ if (sqlite3_prepare_v2(dbase, sql3, strlen(sql3), &res2, NULL) != SQLITE_OK) {
+ dolog("Error preparing SQL for seenbys");
+ free(msg->replyid);
+ free(msg->msgid);
+ free(msg->daddress);
+ free(msg->oaddress);
+ free(msg->msg_h);
+ free(msg->subject);
+ free(msg->to);
+ free(msg->from);
+ free(msg);
+ continue;
+ }
+ sqlite3_bind_int(res2, 1, msg->msg_no);
+ if (sqlite3_step(res2) == SQLITE_ROW) {
+ msg->seenby = safe_strdup(sqlite3_column_text(res2, 0));
+ }
+ sqlite3_finalize(res2);
ptr_vector_append(&vec, msg);
}
@@ -380,11 +411,14 @@ int sq3_write_message(struct msg_base_t *mb, const char *to, const char *from, c
struct msg_t *sq3_message_header(const char *db, int id) {
static const char *sql = "SELECT id, sender, recipient, subject, date, mattribs, daddress, oaddress, msgid, replyid FROM msgs WHERE id=?";
-
+ static const char *sql3 = "SELECT seenby FROM seenbys WHERE msgid = ?";
+
sqlite3 *dbase;
sqlite3_stmt *res;
+ sqlite3_stmt *res2;
struct msg_t *msg = NULL;
-
+ uint32_t mattrib;
+
if (!open_sq3_database(db, &dbase)) {
return NULL;
}
@@ -405,11 +439,36 @@ struct msg_t *sq3_message_header(const char *db, int id) {
msg->subject = safe_strdup(sqlite3_column_text(res, 3));
msg->msgwritten = sqlite3_column_int(res, 4);
msg->msg_h = (uint32_t *)malloz(sizeof(uint32_t));
- *(uint32_t *)(msg->msg_h) = sqlite3_column_int(res, 5);
+ mattrib = sqlite3_column_int(res, 5);
+ *(uint32_t *)(msg->msg_h) = mattrib;
msg->oaddress = safe_strdup(sqlite3_column_text(res, 7));
msg->daddress = safe_strdup(sqlite3_column_text(res, 6));
msg->msgid = safe_strdup(sqlite3_column_text(res, 8));
msg->replyid = safe_strdup(sqlite3_column_text(res, 9));
+ msg->seenby = NULL;
+
+ if (sqlite3_prepare_v2(dbase, sql3, strlen(sql3), &res2, NULL) != SQLITE_OK) {
+ dolog("Error preparing SQL for seenbys");
+ free(msg->replyid);
+ free(msg->msgid);
+ free(msg->daddress);
+ free(msg->oaddress);
+ free(msg->msg_h);
+ free(msg->subject);
+ free(msg->to);
+ free(msg->from);
+ free(msg);
+ sqlite3_finalize(res);
+ sqlite3_close(dbase);
+ return NULL;
+ }
+
+
+ sqlite3_bind_int(res2, 1, msg->msg_no);
+ if (sqlite3_step(res2) == SQLITE_ROW) {
+ msg->seenby = safe_strdup(sqlite3_column_text(res2, 0));
+ }
+ sqlite3_finalize(res2);
}
sqlite3_finalize(res);
sqlite3_close(dbase);
diff --git a/utils/magimail/src/magimail/mb_sq3.c b/utils/magimail/src/magimail/mb_sq3.c
index f8b6a72..109fa2e 100644
--- a/utils/magimail/src/magimail/mb_sq3.c
+++ b/utils/magimail/src/magimail/mb_sq3.c
@@ -13,6 +13,8 @@ long sq3_utcoffset;
static int open_sq3_database(const char *path, sqlite3 **db) {
const char *create_sql = "CREATE TABLE IF NOT EXISTS msgs(id INTEGER PRIMARY KEY, sender TEXT, recipient TEXT, subject TEXT, date INTEGER, mattribs INTEGER, daddress TEXT, oaddress TEXT, msgid TEXT, replyid TEXT, body TEXT);";
const char *create_sql2 = "CREATE TABLE IF NOT EXISTS lastread(userid INTEGER, messageid INTEGER);";
+ const char *create_sql3 = "CREATE TABLE IF NOT EXISTS seenbys(msgid INTEGER, seenby TEXT);";
+
int rc;
char *err_msg;
@@ -38,6 +40,13 @@ static int open_sq3_database(const char *path, sqlite3 **db) {
return 0;
}
+ rc = sqlite3_exec(*db, create_sql3, 0, 0, &err_msg);
+ if (rc != SQLITE_OK) {
+ free(err_msg);
+ sqlite3_close(*db);
+ return 0;
+ }
+
return 1;
}
@@ -62,6 +71,7 @@ bool sq3_importfunc(struct MemMessage *mm,struct Area *area) {
sqlite3_stmt *res;
int rc;
char *sql = "INSERT INTO msgs (sender, recipient, subject, date, mattribs, daddress, oaddress, msgid, replyid, body) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ char *sql2 = "INSERT INTO seenbys(msgid, seenby) VALUES(?, ?)";
char *sender;
char *recipient;
char *subject;
@@ -75,6 +85,7 @@ bool sq3_importfunc(struct MemMessage *mm,struct Area *area) {
uint32_t c,linebegin,linelen;
char *msgtext;
char *body;
+ char *seenbybuf;
uint32_t msgsize,msgpos;
if (mm->From[0]) {
@@ -192,6 +203,13 @@ bool sq3_importfunc(struct MemMessage *mm,struct Area *area) {
msgtext = "";
msgpos = 1;
}
+
+ seenbybuf = NULL;
+
+ if(config.cfg_Flags & CFG_IMPORTSEENBY)
+ {
+ seenbybuf = mmMakeSeenByBuf(&mm->SeenBy);
+ }
body = (char *)osAlloc(msgpos + 1);
@@ -226,7 +244,29 @@ bool sq3_importfunc(struct MemMessage *mm,struct Area *area) {
sqlite3_step(res);
sqlite3_finalize(res);
+
+ if (seenbybuf != NULL) {
+ int lastid = sqlite3_last_insert_rowid(db);
+
+ rc = sqlite3_prepare_v2(db, sql2, -1, &res, 0);
+ if (rc != SQLITE_OK) {
+ sqlite3_close(db);
+ return FALSE;
+ }
+
+ sqlite3_bind_int(res, 1, lastid);
+ sqlite3_bind_text(res, 2, seenbybuf, -1, 0);
+ sqlite3_step(res);
+ sqlite3_finalize(res);
+
+ osFree(seenbybuf);
+ }
+
+
sqlite3_close(db);
+
+
+
if (sender != NULL) {
osFree(sender);