summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bbs.h2
-rwxr-xr-xsrc/mail_menu.c112
-rw-r--r--src/msglib/msglib.c97
-rw-r--r--src/msglib/msglib.h3
-rw-r--r--src/msglib/msglib_jam.c76
-rw-r--r--src/msglib/msglib_jam.h1
-rwxr-xr-xsrc/msglib/msglib_sq3.c44
-rw-r--r--src/msglib/msglib_sq3.h1
8 files changed, 196 insertions, 140 deletions
diff --git a/src/bbs.h b/src/bbs.h
index 652f835..786005b 100644
--- a/src/bbs.h
+++ b/src/bbs.h
@@ -335,8 +335,6 @@ extern time_t utc_to_local(time_t utc);
extern void mail_scan(struct user_record *user);
extern char *editor(struct user_record *user, char *quote, int qlen, char *from, int email, int sig);
extern char *external_editor(struct user_record *user, char *to, char *from, char *quote, int qlen, char *qfrom, char *subject, int email, int sig);
-extern int msg_is_to(struct user_record *user, char *addressed_to, char *address, int type, int rn, int msgconf);
-extern int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, int msgconf);
extern unsigned long generate_msgid();
extern void read_mail(struct user_record *user);
extern void list_messages(struct user_record *user);
diff --git a/src/mail_menu.c b/src/mail_menu.c
index e5a17e2..bbb4db9 100755
--- a/src/mail_menu.c
+++ b/src/mail_menu.c
@@ -84,97 +84,6 @@ unsigned long generate_msgid() {
return strtoul(&buffer[strlen(buffer) - 8], NULL, 16);
}
-int msg_is_to(struct user_record *user, char *addressed_to, char *address, int type, int rn, int msgconf) {
- char *myname;
- if (rn) {
- myname = str3dup(user->firstname, " ", user->lastname);
- } else {
- myname = strdup(user->loginname);
- }
- struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, msgconf);
- assert(mc != NULL);
- if (type == NETWORK_FIDO && address != NULL) {
- if (strcasecmp(myname, addressed_to) == 0) {
- struct fido_addr *dest = parse_fido_addr(address);
- if (mc->fidoaddr->zone == dest->zone &&
- mc->fidoaddr->net == dest->net &&
- mc->fidoaddr->node == dest->node &&
- mc->fidoaddr->point == dest->point) {
- free(dest);
- free(myname);
- return 1;
- }
- free(dest);
- }
- free(myname);
- return 0;
- } else if (type == NETWORK_MAGI && address != NULL) {
- if (strcasecmp(myname, addressed_to) == 0) {
- int magi_dest = atoi(address);
- if (magi_dest == mc->maginode) {
- free(myname);
- return 1;
- }
- }
- free(myname);
- return 0;
- } else {
- if (strcasecmp(myname, addressed_to) == 0) {
- free(myname);
- return 1;
- }
- free(myname);
- return 0;
- }
-}
-
-int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, int msgconf) {
- char *myname;
-
- if (rn) {
- myname = str3dup(user->firstname, " ", user->lastname);
- } else {
- myname = strdup(user->loginname);
- }
- struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, msgconf);
- assert(mc != NULL);
- if (type == NETWORK_FIDO && address != NULL) {
- if (strcasecmp(myname, addressed_from) == 0) {
- struct fido_addr *orig = parse_fido_addr(address);
- if (mc->fidoaddr->zone == orig->zone &&
- mc->fidoaddr->net == orig->net &&
- mc->fidoaddr->node == orig->node &&
- mc->fidoaddr->point == orig->point) {
- free(orig);
- free(myname);
- return 1;
- }
- free(orig);
- }
- free(myname);
- return 0;
- } else if (type == NETWORK_MAGI && address != NULL) {
- if (strcasecmp(myname, addressed_from) == 0) {
- int magi_orig = atoi(address);
- if (magi_orig == mc->maginode) {
- free(myname);
- return 1;
- }
- }
- free(myname);
- return 0;
- } else {
- if (strcasecmp(myname, addressed_from) == 0) {
- free(myname);
- return 1;
- }
- free(myname);
- return 0;
- }
-}
-
-
-
char *external_editor(struct user_record *user, char *to, char *from, char *quote, int qlen, char *qfrom, char *subject, int email, int sig) {
char c;
FILE *fptr;
@@ -3075,29 +2984,10 @@ void msgbase_reset_all_pointers(int readm) {
int new_messages(struct user_record *user, int conference, int area) {
int count = 0;
struct msg_base_t *mb;
- int high_read;
- struct msg_headers *msghs;
-
- struct mail_area *ma = get_area(conference, area);
mb = open_message_base(conference, area);
- if (!mb) {
- return 0;
- }
-
- high_read = get_message_highread(mb, user->id);
-
+ count = new_message_count(mb, user);
close_message_base(mb);
- msghs = read_message_headers(conference, area, user, 0);
- if (msghs != NULL) {
- if (msghs->msg_count > 0) {
- if (get_message_number(msghs, msghs->msg_count - 1) > high_read) {
- count = count_msgs_above_msgno(msghs, high_read);
- }
- }
- free_message_headers(msghs);
- }
-
return count;
}
diff --git a/src/msglib/msglib.c b/src/msglib/msglib.c
index 093fe9a..12b1a27 100644
--- a/src/msglib/msglib.c
+++ b/src/msglib/msglib.c
@@ -5,6 +5,92 @@
#include "msglib_sq3.h"
#include "../../deps/jamlib/jam.h"
+int msg_is_to(struct user_record *user, char *addressed_to, char *address, int type, int rn, struct mail_conference *mc) {
+ char *myname;
+ if (rn) {
+ myname = str3dup(user->firstname, " ", user->lastname);
+ } else {
+ myname = strdup(user->loginname);
+ }
+ if (type == NETWORK_FIDO && address != NULL) {
+ if (strcasecmp(myname, addressed_to) == 0) {
+ struct fido_addr *dest = parse_fido_addr(address);
+ if (mc->fidoaddr->zone == dest->zone &&
+ mc->fidoaddr->net == dest->net &&
+ mc->fidoaddr->node == dest->node &&
+ mc->fidoaddr->point == dest->point) {
+ free(dest);
+ free(myname);
+ return 1;
+ }
+ free(dest);
+ }
+ free(myname);
+ return 0;
+ } else if (type == NETWORK_MAGI && address != NULL) {
+ if (strcasecmp(myname, addressed_to) == 0) {
+ int magi_dest = atoi(address);
+ if (magi_dest == mc->maginode) {
+ free(myname);
+ return 1;
+ }
+ }
+ free(myname);
+ return 0;
+ } else {
+ if (strcasecmp(myname, addressed_to) == 0) {
+ free(myname);
+ return 1;
+ }
+ free(myname);
+ return 0;
+ }
+}
+
+int msg_is_from(struct user_record *user, char *addressed_from, char *address, int type, int rn, struct mail_conference *mc) {
+ char *myname;
+
+ if (rn) {
+ myname = str3dup(user->firstname, " ", user->lastname);
+ } else {
+ myname = strdup(user->loginname);
+ }
+
+ if (type == NETWORK_FIDO && address != NULL) {
+ if (strcasecmp(myname, addressed_from) == 0) {
+ struct fido_addr *orig = parse_fido_addr(address);
+ if (mc->fidoaddr->zone == orig->zone &&
+ mc->fidoaddr->net == orig->net &&
+ mc->fidoaddr->node == orig->node &&
+ mc->fidoaddr->point == orig->point) {
+ free(orig);
+ free(myname);
+ return 1;
+ }
+ free(orig);
+ }
+ free(myname);
+ return 0;
+ } else if (type == NETWORK_MAGI && address != NULL) {
+ if (strcasecmp(myname, addressed_from) == 0) {
+ int magi_orig = atoi(address);
+ if (magi_orig == mc->maginode) {
+ free(myname);
+ return 1;
+ }
+ }
+ free(myname);
+ return 0;
+ } else {
+ if (strcasecmp(myname, addressed_from) == 0) {
+ free(myname);
+ return 1;
+ }
+ free(myname);
+ return 0;
+ }
+}
+
void free_message_hdr(struct msg_t *msg) {
free(msg->msg_h);
free(msg->from);
@@ -190,3 +276,14 @@ struct msg_t *load_message_hdr(struct msg_base_t *mb, int id) {
return jam_message_header(mb->data.jam, id);
}
}
+
+int new_message_count(struct msg_base_t *mb, struct user_record *user) {
+ switch (mb->base_type) {
+ case BASE_TYPE_SQ3:
+ return sq3_new_message_count(mb, user);
+ case BASE_TYPE_JAM:
+ default:
+ return jam_new_message_count(mb, user);
+
+ }
+}
diff --git a/src/msglib/msglib.h b/src/msglib/msglib.h
index efc835b..42ff1ca 100644
--- a/src/msglib/msglib.h
+++ b/src/msglib/msglib.h
@@ -35,6 +35,8 @@ struct msg_base_t {
} data;
};
+extern int msg_is_to(struct user_record *user, const char *addressed_from, const char *address, int type, int rn, struct mail_conference *mc);
+extern int msg_is_from(struct user_record *user, const char *addressed_from, const char *address, int type, int rn, struct mail_conference *mc);
extern void free_message_headers(struct msg_headers *msghs);
extern struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_record *user, int personal);
extern struct msg_base_t *open_message_base(int msgconf, int msgarea);
@@ -50,4 +52,5 @@ 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);
+int new_message_count(struct msg_base_t *mb, struct user_record *user);
#endif
diff --git a/src/msglib/msglib_jam.c b/src/msglib/msglib_jam.c
index 3dde2e0..e15fe1d 100644
--- a/src/msglib/msglib_jam.c
+++ b/src/msglib/msglib_jam.c
@@ -7,7 +7,7 @@
#include "../../deps/libuuid/uuid.h"
#include "../../deps/jamlib/jam.h"
#include "../bbs.h"
-
+#include "../mail_utils.h"
extern struct bbs_config conf;
void *jam_open_base(char *path) {
@@ -33,8 +33,7 @@ void *jam_open_base(char *path) {
return jb;
}
-struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct user_record *user, int personal) {
- s_JamBase *jb;
+struct msg_headers *do_jam_read_message_headers(struct mail_conference * mc, struct mail_area *area, struct user_record *user, int personal, s_JamBase *jb) {
s_JamBaseHeader jbh;
s_JamMsgHeader jmh;
s_JamSubPacket *jsp;
@@ -48,22 +47,13 @@ struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct us
int failed = 0;
struct fido_addr *dest;
struct msg_headers *msghs = NULL;
- struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, msgconf);
- assert(mc != NULL);
- struct mail_area *area = ptr_vector_get(&mc->mail_areas, msgarea);
- assert(area != NULL);
- jb = jam_open_base(area->path);
- if (!jb) {
- dolog("Error opening JAM base.. %s", area->path);
- return NULL;
- }
+
JAM_ReadMBHeader(jb, &jbh);
if (jbh.ActiveMsgs <= 0) {
- JAM_CloseMB(jb);
- free(jb);
+
return NULL;
}
init_ptr_vector(&vec);
@@ -143,10 +133,10 @@ struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct us
jamm->to = strdup("(No Recipient)");
}
if (jmh.Attribute & JAM_MSG_PRIVATE) {
- if (!msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, mc->realnames, msgconf) &&
- !msg_is_from(user, jamm->from, jamm->oaddress, mc->nettype, mc->realnames, msgconf) &&
- !msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, !mc->realnames, msgconf) &&
- !msg_is_from(user, jamm->from, jamm->oaddress, mc->nettype, !mc->realnames, msgconf)) {
+ if (!msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, mc->realnames, mc) &&
+ !msg_is_from(user, jamm->from, jamm->oaddress, mc->nettype, mc->realnames, mc) &&
+ !msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, !mc->realnames, mc) &&
+ !msg_is_from(user, jamm->from, jamm->oaddress, mc->nettype, !mc->realnames, mc)) {
free(jamm->subject);
free(jamm->from);
free(jamm->to);
@@ -160,8 +150,8 @@ struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct us
continue;
}
} else if (personal) {
- if (!msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, mc->realnames, msgconf) &&
- !msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, !mc->realnames, msgconf)) {
+ if (!msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, mc->realnames, mc) &&
+ !msg_is_to(user, jamm->to, jamm->daddress, mc->nettype, !mc->realnames, mc)) {
free(jamm->subject);
free(jamm->from);
@@ -183,9 +173,6 @@ struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct us
msghs->msg_count = ptr_vector_len(&vec);
msghs->msgs = (struct msg_t **)consume_ptr_vector(&vec);
- JAM_CloseMB(jb);
- free(jb);
-
if (failed > 0) {
dolog("Failed to read %d messages, possible corrupt msg base (%s -> %s)?", failed, mc->name, area->name);
}
@@ -193,6 +180,28 @@ struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct us
return msghs;
}
+struct msg_headers *jam_read_message_headers(int msgconf, int msgarea, struct user_record *user, int personal) {
+ s_JamBase *jb;
+
+ struct mail_conference *mc = ptr_vector_get(&conf.mail_conferences, msgconf);
+ assert(mc != NULL);
+ struct mail_area *area = ptr_vector_get(&mc->mail_areas, msgarea);
+ assert(area != NULL);
+
+ jb = jam_open_base(get_area(msgconf, msgarea)->path);
+ if (!jb) {
+ dolog("Error opening JAM base.. %s", get_area(msgconf, msgarea)->path);
+ return NULL;
+ }
+
+ struct msg_headers *ret = do_jam_read_message_headers(mc, area, user, personal, jb);
+
+ JAM_CloseMB(jb);
+ free(jb);
+
+ return ret;
+}
+
int jam_message_lastread(s_JamBase *jb, int uid) {
s_JamLastRead jlr;
if (JAM_ReadLastRead(jb, uid, &jlr) == JAM_NO_USER) {
@@ -504,3 +513,24 @@ struct msg_t *jam_message_header(s_JamBase *jb, int id) {
return jamm;
}
+
+int jam_new_message_count(struct msg_base_t *mb, struct user_record *user) {
+ int count = 0;
+ int high_read;
+
+ struct msg_headers *msghs;
+
+ high_read = jam_message_highread(mb->data.jam, user->id);
+
+ msghs = do_jam_read_message_headers(mb->mc, mb->ma, user, 0, mb->data.jam);
+ if (msghs != NULL) {
+ if (msghs->msg_count > 0) {
+ if (get_message_number(msghs, msghs->msg_count - 1) > high_read) {
+ count = count_msgs_above_msgno(msghs, high_read);
+ }
+ }
+ free_message_headers(msghs);
+ }
+
+ return count;
+}
diff --git a/src/msglib/msglib_jam.h b/src/msglib/msglib_jam.h
index c89e8ca..09f2843 100644
--- a/src/msglib/msglib_jam.h
+++ b/src/msglib/msglib_jam.h
@@ -12,4 +12,5 @@ extern int jam_message_highread(s_JamBase *jb, int uid);
extern void jam_write_lasthighread(s_JamBase *jb, struct user_record *user, int lastread, int highread);
extern int jam_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);
extern struct msg_t *jam_message_header(s_JamBase *jb, int id);
+extern int jam_new_message_count(struct msg_base_t *mb, struct user_record *user);
#endif
diff --git a/src/msglib/msglib_sq3.c b/src/msglib/msglib_sq3.c
index 453f759..4e7546d 100755
--- a/src/msglib/msglib_sq3.c
+++ b/src/msglib/msglib_sq3.c
@@ -126,10 +126,10 @@ struct msg_headers *sq3_read_message_headers(int msgconf, int msgarea, struct us
msg->seenby = NULL;
if (mattrib & SQ3_MSG_PRIVATE) {
- if (!msg_is_to(user, msg->to, msg->daddress, mc->nettype, mc->realnames, msgconf) &&
- !msg_is_from(user, msg->from, msg->oaddress, mc->nettype, mc->realnames, msgconf) &&
- !msg_is_to(user, msg->to, msg->daddress, mc->nettype, !mc->realnames, msgconf) &&
- !msg_is_from(user, msg->from, msg->oaddress, mc->nettype, !mc->realnames, msgconf)) {
+ if (!msg_is_to(user, msg->to, msg->daddress, mc->nettype, mc->realnames, mc) &&
+ !msg_is_from(user, msg->from, msg->oaddress, mc->nettype, mc->realnames, mc) &&
+ !msg_is_to(user, msg->to, msg->daddress, mc->nettype, !mc->realnames, mc) &&
+ !msg_is_from(user, msg->from, msg->oaddress, mc->nettype, !mc->realnames, mc)) {
free(msg->replyid);
free(msg->msgid);
@@ -504,3 +504,39 @@ char *sq3_fetch_body(const char *db, int mid) {
return body;
}
+
+int sq3_new_message_count(struct msg_base_t *mb, struct user_record *user) {
+ static const char *sql = "SELECT sender, recipient, oaddress, daddress, mattribs FROM msgs WHERE id > ?";
+ sqlite3 *dbase;
+ sqlite3_stmt *res;
+ int count = 0;
+ int last_read = sq3_message_lastread(mb->ma->path, user->id);
+ if (!open_sq3_database(mb->ma->path, &dbase)) {
+ return 0;
+ }
+ if (sqlite3_prepare_v2(dbase, sql, strlen(sql), &res, NULL) != SQLITE_OK) {
+ sqlite3_close(dbase);
+ return 0;
+ }
+ sqlite3_bind_int(res, 1, last_read);
+ while(sqlite3_step(res) == SQLITE_ROW) {
+ const char *to = sqlite3_column_text(res, 1);
+ const char *from = sqlite3_column_text(res, 0);
+ const char *oaddress = sqlite3_column_text(res, 2);
+ const char *daddress = sqlite3_column_text(res, 3);
+ if (sqlite3_column_int(res, 4) & SQ3_MSG_PRIVATE) {
+ if (!(!msg_is_to(user, to, daddress, mb->mc->nettype, mb->mc->realnames, mb->mc) &&
+ !msg_is_from(user, from, oaddress, mb->mc->nettype, mb->mc->realnames, mb->mc) &&
+ !msg_is_to(user, to, daddress, mb->mc->nettype, !mb->mc->realnames, mb->mc) &&
+ !msg_is_from(user, from, oaddress, mb->mc->nettype, !mb->mc->realnames, mb->mc))) {
+
+ count++;
+ }
+ } else {
+ count++;
+ }
+ }
+
+ sqlite3_finalize(res);
+ sqlite3_close(dbase);
+}
diff --git a/src/msglib/msglib_sq3.h b/src/msglib/msglib_sq3.h
index 4ef4a75..9e93bec 100644
--- a/src/msglib/msglib_sq3.h
+++ b/src/msglib/msglib_sq3.h
@@ -15,4 +15,5 @@ extern void sq3_write_lasthighread(const char *db, struct user_record *user, int
extern int sq3_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);
extern struct msg_t *sq3_message_header(const char *db, int id);
extern char *sq3_fetch_body(const char *db, int mid);
+extern int sq3_new_message_count(struct msg_base_t *mb, struct user_record *user);
#endif