email clean up.. hope i didnt break everything
This commit is contained in:
parent
995a062f29
commit
23e30e07d7
2
bbs.h
2
bbs.h
@ -165,7 +165,7 @@ extern void main_menu(int socket, struct user_record *user);
|
|||||||
|
|
||||||
extern void mail_scan(int socket, struct user_record *user);
|
extern void mail_scan(int socket, struct user_record *user);
|
||||||
extern int mail_menu(int socket, struct user_record *user);
|
extern int mail_menu(int socket, struct user_record *user);
|
||||||
extern char *editor(int socket, struct user_record *user, char *quote, char *from);
|
extern char *editor(int socket, struct user_record *user, char *quote, char *from, int email);
|
||||||
extern char *external_editor(int socket, struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email);
|
extern char *external_editor(int socket, struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email);
|
||||||
|
|
||||||
extern int door_menu(int socket, struct user_record *user);
|
extern int door_menu(int socket, struct user_record *user);
|
||||||
|
91
email.c
91
email.c
@ -11,12 +11,12 @@ extern struct bbs_config conf;
|
|||||||
void send_email(int socket, struct user_record *user) {
|
void send_email(int socket, struct user_record *user) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
char *recipient;
|
char *recipient;
|
||||||
char *subject;
|
char *subject;
|
||||||
char *msg;
|
char *msg;
|
||||||
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||||
"id INTEGER PRIMARY KEY,"
|
"id INTEGER PRIMARY KEY,"
|
||||||
"sender TEXT COLLATE NOCASE,"
|
"sender TEXT COLLATE NOCASE,"
|
||||||
"recipient TEXT COLLATE NOCASE,"
|
"recipient TEXT COLLATE NOCASE,"
|
||||||
@ -24,8 +24,8 @@ void send_email(int socket, struct user_record *user) {
|
|||||||
"body TEXT,"
|
"body TEXT,"
|
||||||
"date INTEGER,"
|
"date INTEGER,"
|
||||||
"seen INTEGER);";
|
"seen INTEGER);";
|
||||||
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
|
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
|
||||||
char *err_msg = 0;
|
char *err_msg = 0;
|
||||||
|
|
||||||
s_putstring(socket, "\r\nTO: ");
|
s_putstring(socket, "\r\nTO: ");
|
||||||
s_readstring(socket, buffer, 16);
|
s_readstring(socket, buffer, 16);
|
||||||
@ -103,12 +103,12 @@ void send_email(int socket, struct user_record *user) {
|
|||||||
void show_email(int socket, struct user_record *user, int msgno) {
|
void show_email(int socket, struct user_record *user, int msgno) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
char *sql = "SELECT id,sender,subject,body,date FROM email WHERE recipient LIKE ? LIMIT ?, 1";
|
char *sql = "SELECT id,sender,subject,body,date FROM email WHERE recipient LIKE ? LIMIT ?, 1";
|
||||||
char *dsql = "DELETE FROM email WHERE id=?";
|
char *dsql = "DELETE FROM email WHERE id=?";
|
||||||
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
|
char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)";
|
||||||
char *ssql = "UPDATE email SET seen=1 WHERE id=?";
|
char *ssql = "UPDATE email SET seen=1 WHERE id=?";
|
||||||
int id;
|
int id;
|
||||||
char *sender;
|
char *sender;
|
||||||
char *subject;
|
char *subject;
|
||||||
@ -268,16 +268,16 @@ void show_email(int socket, struct user_record *user, int msgno) {
|
|||||||
void list_emails(int socket, struct user_record *user) {
|
void list_emails(int socket, struct user_record *user) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
char *sql = "SELECT sender,subject,seen,date FROM email WHERE recipient LIKE ?";
|
char *sql = "SELECT sender,subject,seen,date FROM email WHERE recipient LIKE ?";
|
||||||
char *subject;
|
char *subject;
|
||||||
char *from;
|
char *from;
|
||||||
char *to;
|
char *to;
|
||||||
char *body;
|
char *body;
|
||||||
time_t date;
|
time_t date;
|
||||||
int seen;
|
int seen;
|
||||||
int msgid;
|
int msgid;
|
||||||
int msgtoread;
|
int msgtoread;
|
||||||
struct tm msg_date;
|
struct tm msg_date;
|
||||||
|
|
||||||
@ -285,35 +285,35 @@ void list_emails(int socket, struct user_record *user) {
|
|||||||
|
|
||||||
rc = sqlite3_open(buffer, &db);
|
rc = sqlite3_open(buffer, &db);
|
||||||
if (rc != SQLITE_OK) {
|
if (rc != SQLITE_OK) {
|
||||||
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
dolog("Cannot open database: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
|
||||||
|
|
||||||
if (rc == SQLITE_OK) {
|
if (rc == SQLITE_OK) {
|
||||||
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
sqlite3_bind_text(res, 1, user->loginname, -1, 0);
|
||||||
} else {
|
} else {
|
||||||
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
dolog("Failed to execute statement: %s", sqlite3_errmsg(db));
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
s_putstring(socket, "\r\nYou have no email\r\n");
|
s_putstring(socket, "\r\nYou have no email\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgid = 0;
|
msgid = 0;
|
||||||
|
s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m");
|
||||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||||
from = strdup((char *)sqlite3_column_text(res, 0));
|
from = strdup((char *)sqlite3_column_text(res, 0));
|
||||||
subject = strdup((char *)sqlite3_column_text(res, 1));
|
subject = strdup((char *)sqlite3_column_text(res, 1));
|
||||||
seen = sqlite3_column_int(res, 2);
|
seen = sqlite3_column_int(res, 2);
|
||||||
date = (time_t)sqlite3_column_int(res, 3);
|
date = (time_t)sqlite3_column_int(res, 3);
|
||||||
localtime_r(&date, &msg_date);
|
localtime_r(&date, &msg_date);
|
||||||
if (seen == 0) {
|
if (seen == 0) {
|
||||||
sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||||
} else {
|
} else {
|
||||||
sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100);
|
||||||
}
|
}
|
||||||
s_putstring(socket, buffer);
|
s_putstring(socket, buffer);
|
||||||
|
|
||||||
@ -321,8 +321,7 @@ void list_emails(int socket, struct user_record *user) {
|
|||||||
free(subject);
|
free(subject);
|
||||||
|
|
||||||
if (msgid % 22 == 0 && msgid != 0) {
|
if (msgid % 22 == 0 && msgid != 0) {
|
||||||
s_putstring(socket, "Enter # to read, Q to quit or Enter to continue\r\n");
|
s_putstring(socket, "\e[1;37mEnter \e[1;36m# \e[1;37mto read, \e[1;36mQ \e[1;37mto quit or \e[1;36mEnter\e[1;37m to continue\e[0m\r\n");
|
||||||
|
|
||||||
s_readstring(socket, buffer, 5);
|
s_readstring(socket, buffer, 5);
|
||||||
if (strlen(buffer) > 0) {
|
if (strlen(buffer) > 0) {
|
||||||
if (tolower(buffer[0]) == 'q') {
|
if (tolower(buffer[0]) == 'q') {
|
||||||
@ -330,31 +329,29 @@ void list_emails(int socket, struct user_record *user) {
|
|||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
msgtoread = atoi(buffer);
|
msgtoread = atoi(buffer) - 1;
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
show_email(socket, user, msgtoread);
|
show_email(socket, user, msgtoread);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m");
|
||||||
}
|
}
|
||||||
|
|
||||||
msgid++;
|
msgid++;
|
||||||
}
|
}
|
||||||
if (msgid == 0) {
|
if (msgid == 0) {
|
||||||
s_putstring(socket, "\r\nYou have no email\r\n");
|
s_putstring(socket, "\r\nYou have no email\r\n");
|
||||||
} else {
|
} else {
|
||||||
s_putstring(socket, "Enter # to read, or Enter to quit\r\n");
|
s_putstring(socket, "\e[1;37mEnter \e[1;36m# \e[1;37mto read, or \e[1;36mEnter\e[1;37m to quit\e[0m\r\n");
|
||||||
s_readstring(socket, buffer, 5);
|
s_readstring(socket, buffer, 5);
|
||||||
if (strlen(buffer) > 0) {
|
if (strlen(buffer) > 0) {
|
||||||
msgtoread = atoi(buffer);
|
msgtoread = atoi(buffer) - 1;
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
show_email(socket, user, msgtoread);
|
show_email(socket, user, msgtoread);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
sqlite3_finalize(res);
|
sqlite3_finalize(res);
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
|
@ -376,7 +376,8 @@ char *external_editor(int socket, struct user_record *user, char *to, char *from
|
|||||||
|
|
||||||
uname(&name);
|
uname(&name);
|
||||||
|
|
||||||
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) {
|
|
||||||
|
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) {
|
||||||
if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) {
|
if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) {
|
||||||
snprintf(buffer, 256, "\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[user->cur_mail_conf]->fidoaddr->zone,
|
snprintf(buffer, 256, "\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[user->cur_mail_conf]->fidoaddr->zone,
|
||||||
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net,
|
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net,
|
||||||
@ -412,10 +413,10 @@ char *external_editor(int socket, struct user_record *user, char *to, char *from
|
|||||||
return body2;
|
return body2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return editor(socket, user, quote, qfrom);
|
return editor(socket, user, quote, qfrom, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *editor(int socket, struct user_record *user, char *quote, char *from) {
|
char *editor(int socket, struct user_record *user, char *quote, char *from, int email) {
|
||||||
int lines = 0;
|
int lines = 0;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
char linebuffer[80];
|
char linebuffer[80];
|
||||||
@ -494,7 +495,7 @@ char *editor(int socket, struct user_record *user, char *quote, char *from) {
|
|||||||
tagline = conf.default_tagline;
|
tagline = conf.default_tagline;
|
||||||
}
|
}
|
||||||
uname(&name);
|
uname(&name);
|
||||||
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) {
|
if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO && !email) {
|
||||||
if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) {
|
if (conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point == 0) {
|
||||||
snprintf(buffer, 256, "\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[user->cur_mail_conf]->fidoaddr->zone,
|
snprintf(buffer, 256, "\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[user->cur_mail_conf]->fidoaddr->zone,
|
||||||
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net,
|
conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net,
|
||||||
|
3
main.c
3
main.c
@ -329,6 +329,7 @@ void server(int port) {
|
|||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
sa.sa_flags = SA_RESTART;
|
sa.sa_flags = SA_RESTART;
|
||||||
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
|
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
|
||||||
|
remove(conf.pid_file);
|
||||||
perror("sigaction");
|
perror("sigaction");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -336,12 +337,14 @@ void server(int port) {
|
|||||||
st.sa_handler = sigterm_handler;
|
st.sa_handler = sigterm_handler;
|
||||||
sigemptyset(&st.sa_mask);
|
sigemptyset(&st.sa_mask);
|
||||||
if (sigaction(SIGTERM, &st, NULL) == -1) {
|
if (sigaction(SIGTERM, &st, NULL) == -1) {
|
||||||
|
remove(conf.pid_file);
|
||||||
perror("sigaction");
|
perror("sigaction");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket_desc = socket(AF_INET, SOCK_STREAM, 0);
|
socket_desc = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (socket_desc == -1) {
|
if (socket_desc == -1) {
|
||||||
|
remove(conf.pid_file);
|
||||||
fprintf(stderr, "Couldn't create socket..\n");
|
fprintf(stderr, "Couldn't create socket..\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user