deleting emails via WWW
This commit is contained in:
parent
439fd48f4a
commit
5d7a3c184c
1
bbs.h
1
bbs.h
@ -210,6 +210,7 @@ extern char *www_email_summary(struct user_record *user);
|
|||||||
extern char *www_email_display(struct user_record *user, int email);
|
extern char *www_email_display(struct user_record *user, int email);
|
||||||
extern int www_send_email(struct user_record *user, char *recipient, char *subject, char *body);
|
extern int www_send_email(struct user_record *user, char *recipient, char *subject, char *body);
|
||||||
extern char *www_new_email();
|
extern char *www_new_email();
|
||||||
|
extern int www_email_delete(struct user_record *user, int id);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
83
www.c
83
www.c
@ -50,20 +50,20 @@ void www_request_completed(void *cls, struct MHD_Connection *connection, void **
|
|||||||
free(con_info->values);
|
free(con_info->values);
|
||||||
free(con_info->keys);
|
free(con_info->keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (con_info->user != NULL) {
|
|
||||||
free(con_info->user->loginname);
|
|
||||||
free(con_info->user->password);
|
|
||||||
free(con_info->user->firstname);
|
|
||||||
free(con_info->user->lastname);
|
|
||||||
free(con_info->user->email);
|
|
||||||
free(con_info->user->location);
|
|
||||||
free(con_info->user->sec_info);
|
|
||||||
free(con_info->user);
|
|
||||||
}
|
|
||||||
|
|
||||||
MHD_destroy_post_processor(con_info->pp);
|
MHD_destroy_post_processor(con_info->pp);
|
||||||
}
|
}
|
||||||
|
if (con_info->user != NULL) {
|
||||||
|
free(con_info->user->loginname);
|
||||||
|
free(con_info->user->password);
|
||||||
|
free(con_info->user->firstname);
|
||||||
|
free(con_info->user->lastname);
|
||||||
|
free(con_info->user->email);
|
||||||
|
free(con_info->user->location);
|
||||||
|
free(con_info->user->sec_info);
|
||||||
|
free(con_info->user);
|
||||||
|
}
|
||||||
|
|
||||||
free(con_info->url);
|
free(con_info->url);
|
||||||
free(con_info);
|
free(con_info);
|
||||||
}
|
}
|
||||||
@ -367,7 +367,6 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
|||||||
int i;
|
int i;
|
||||||
int fno;
|
int fno;
|
||||||
const char *url_ = url;
|
const char *url_ = url;
|
||||||
struct user_record *user;
|
|
||||||
char *subj, *to, *body;
|
char *subj, *to, *body;
|
||||||
struct connection_info_s *con_inf;
|
struct connection_info_s *con_inf;
|
||||||
|
|
||||||
@ -499,15 +498,15 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
|||||||
|
|
||||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||||
} else if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) {
|
} else if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) {
|
||||||
user = www_auth_ok(connection, url_);
|
con_inf->user = www_auth_ok(connection, url_);
|
||||||
|
|
||||||
if (user == NULL) {
|
if (con_inf->user == NULL) {
|
||||||
www_401(header, footer, connection);
|
www_401(header, footer, connection);
|
||||||
free(header);
|
free(header);
|
||||||
free(footer);
|
free(footer);
|
||||||
return MHD_YES;
|
return MHD_YES;
|
||||||
}
|
}
|
||||||
page = www_email_summary(user);
|
page = www_email_summary(con_inf->user);
|
||||||
if (page == NULL) {
|
if (page == NULL) {
|
||||||
free(header);
|
free(header);
|
||||||
free(footer);
|
free(footer);
|
||||||
@ -517,9 +516,9 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
|||||||
|
|
||||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||||
} else if(strcasecmp(url, "/email/new") == 0) {
|
} else if(strcasecmp(url, "/email/new") == 0) {
|
||||||
user = www_auth_ok(connection, url_);
|
con_inf->user = www_auth_ok(connection, url_);
|
||||||
|
|
||||||
if (user == NULL) {
|
if (con_inf->user == NULL) {
|
||||||
www_401(header, footer, connection);
|
www_401(header, footer, connection);
|
||||||
free(header);
|
free(header);
|
||||||
free(footer);
|
free(footer);
|
||||||
@ -534,16 +533,51 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
|||||||
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
|
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
|
||||||
|
|
||||||
sprintf(whole_page, "%s%s%s", header, page, footer);
|
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||||
} else if (strncasecmp(url, "/email/", 7) == 0) {
|
} else if (strncasecmp(url, "/email/delete/", 14) == 0) {
|
||||||
user = www_auth_ok(connection, url_);
|
con_inf->user = www_auth_ok(connection, url_);
|
||||||
|
|
||||||
if (user == NULL) {
|
if (con_inf->user == NULL) {
|
||||||
www_401(header, footer, connection);
|
www_401(header, footer, connection);
|
||||||
free(header);
|
free(header);
|
||||||
free(footer);
|
free(footer);
|
||||||
return MHD_YES;
|
return MHD_YES;
|
||||||
}
|
}
|
||||||
page = www_email_display(user, atoi(&url[7]));
|
|
||||||
|
if (!www_email_delete(con_inf->user, atoi(&url[14]))) {
|
||||||
|
page = (char *)malloc(31);
|
||||||
|
if (page == NULL) {
|
||||||
|
free(header);
|
||||||
|
free(footer);
|
||||||
|
return MHD_NO;
|
||||||
|
}
|
||||||
|
sprintf(page, "<h1>Error Deleting Email.</h1>");
|
||||||
|
} else {
|
||||||
|
page = (char *)malloc(24);
|
||||||
|
if (page == NULL) {
|
||||||
|
free(header);
|
||||||
|
free(footer);
|
||||||
|
return MHD_NO;
|
||||||
|
}
|
||||||
|
sprintf(page, "<h1>Email Deleted!</h1>");
|
||||||
|
}
|
||||||
|
if (page == NULL) {
|
||||||
|
free(header);
|
||||||
|
free(footer);
|
||||||
|
return MHD_NO;
|
||||||
|
}
|
||||||
|
whole_page = (char *)malloc(strlen(header) + strlen(page) + strlen(footer) + 1);
|
||||||
|
|
||||||
|
sprintf(whole_page, "%s%s%s", header, page, footer);
|
||||||
|
} else if (strncasecmp(url, "/email/", 7) == 0) {
|
||||||
|
con_inf->user = www_auth_ok(connection, url_);
|
||||||
|
|
||||||
|
if (con_inf->user == NULL) {
|
||||||
|
www_401(header, footer, connection);
|
||||||
|
free(header);
|
||||||
|
free(footer);
|
||||||
|
return MHD_YES;
|
||||||
|
}
|
||||||
|
page = www_email_display(con_inf->user, atoi(&url[7]));
|
||||||
if (page == NULL) {
|
if (page == NULL) {
|
||||||
free(header);
|
free(header);
|
||||||
free(footer);
|
free(footer);
|
||||||
@ -611,9 +645,8 @@ int www_handler(void * cls, struct MHD_Connection * connection, const char * url
|
|||||||
} else if (strcmp(method, "POST") == 0) {
|
} else if (strcmp(method, "POST") == 0) {
|
||||||
if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) {
|
if (strcasecmp(url, "/email/") == 0 || strcasecmp(url, "/email") == 0) {
|
||||||
con_inf->user = www_auth_ok(connection, url_);
|
con_inf->user = www_auth_ok(connection, url_);
|
||||||
user = www_auth_ok(connection, url_);
|
|
||||||
|
if (con_inf->user == NULL) {
|
||||||
if (user == NULL) {
|
|
||||||
www_401(header, footer, connection);
|
www_401(header, footer, connection);
|
||||||
free(header);
|
free(header);
|
||||||
free(footer);
|
free(footer);
|
||||||
|
BIN
www/static/delete.png
Normal file
BIN
www/static/delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 292 B |
@ -48,6 +48,12 @@
|
|||||||
width: 200px;
|
width: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.email-delete {
|
||||||
|
float: left;
|
||||||
|
display: table-column;
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
.email-view-header {
|
.email-view-header {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
border: 1px solid #666666;
|
border: 1px solid #666666;
|
||||||
|
67
www_email.c
67
www_email.c
@ -10,6 +10,57 @@
|
|||||||
|
|
||||||
extern struct bbs_config conf;
|
extern struct bbs_config conf;
|
||||||
|
|
||||||
|
int www_email_delete(struct user_record *user, int id) {
|
||||||
|
char buffer[256];
|
||||||
|
sqlite3 *db;
|
||||||
|
sqlite3_stmt *res;
|
||||||
|
int rc;
|
||||||
|
char *csql = "CREATE TABLE IF NOT EXISTS email ("
|
||||||
|
"id INTEGER PRIMARY KEY,"
|
||||||
|
"sender TEXT COLLATE NOCASE,"
|
||||||
|
"recipient TEXT COLLATE NOCASE,"
|
||||||
|
"subject TEXT,"
|
||||||
|
"body TEXT,"
|
||||||
|
"date INTEGER,"
|
||||||
|
"seen INTEGER);";
|
||||||
|
char *dsql = "DELETE FROM email WHERE id=? AND recipient LIKE ?";
|
||||||
|
char *err_msg = 0;
|
||||||
|
|
||||||
|
sprintf(buffer, "%s/email.sq3", conf.bbs_path);
|
||||||
|
|
||||||
|
rc = sqlite3_open(buffer, &db);
|
||||||
|
if (rc != SQLITE_OK) {
|
||||||
|
sqlite3_close(db);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rc = sqlite3_exec(db, csql, 0, 0, &err_msg);
|
||||||
|
if (rc != SQLITE_OK ) {
|
||||||
|
sqlite3_free(err_msg);
|
||||||
|
sqlite3_close(db);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0);
|
||||||
|
|
||||||
|
if (rc == SQLITE_OK) {
|
||||||
|
sqlite3_bind_int(res, 1, id);
|
||||||
|
sqlite3_bind_text(res, 2, user->loginname, -1, 0);
|
||||||
|
} else {
|
||||||
|
sqlite3_finalize(res);
|
||||||
|
sqlite3_close(db);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
sqlite3_step(res);
|
||||||
|
|
||||||
|
sqlite3_finalize(res);
|
||||||
|
sqlite3_close(db);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int www_send_email(struct user_record *user, char *recipient, char *subject, char *ibody) {
|
int www_send_email(struct user_record *user, char *recipient, char *subject, char *ibody) {
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
@ -406,12 +457,13 @@ char *www_email_summary(struct user_record *user) {
|
|||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
sqlite3_stmt *res;
|
sqlite3_stmt *res;
|
||||||
int rc;
|
int rc;
|
||||||
char *email_summary_sql = "SELECT sender,subject,seen,date FROM email WHERE recipient LIKE ?";
|
char *email_summary_sql = "SELECT id,sender,subject,seen,date FROM email WHERE recipient LIKE ?";
|
||||||
struct tm msg_date;
|
struct tm msg_date;
|
||||||
time_t date;
|
time_t date;
|
||||||
char *from;
|
char *from;
|
||||||
char *subject;
|
char *subject;
|
||||||
int seen;
|
int seen;
|
||||||
|
int id;
|
||||||
int msgid = 0;
|
int msgid = 0;
|
||||||
char *err_msg = 0;
|
char *err_msg = 0;
|
||||||
char *email_create_sql = "CREATE TABLE IF NOT EXISTS email ("
|
char *email_create_sql = "CREATE TABLE IF NOT EXISTS email ("
|
||||||
@ -482,13 +534,14 @@ char *www_email_summary(struct user_record *user) {
|
|||||||
len += strlen(buffer);
|
len += strlen(buffer);
|
||||||
|
|
||||||
while (sqlite3_step(res) == SQLITE_ROW) {
|
while (sqlite3_step(res) == SQLITE_ROW) {
|
||||||
from = strdup((char *)sqlite3_column_text(res, 0));
|
id = sqlite3_column_int(res, 0);
|
||||||
subject = strdup((char *)sqlite3_column_text(res, 1));
|
from = strdup((char *)sqlite3_column_text(res, 1));
|
||||||
seen = sqlite3_column_int(res, 2);
|
subject = strdup((char *)sqlite3_column_text(res, 2));
|
||||||
date = (time_t)sqlite3_column_int(res, 3);
|
seen = sqlite3_column_int(res, 3);
|
||||||
|
date = (time_t)sqlite3_column_int(res, 4);
|
||||||
localtime_r(&date, &msg_date);
|
localtime_r(&date, &msg_date);
|
||||||
if (seen == 0) {
|
if (seen == 0) {
|
||||||
sprintf(buffer, "<div class=\"email-summary\"><div class=\"email-id\">%d</div><div class=\"email-subject\"><a href=\"/email/%d\">%s</a></div><div class=\"email-from\">%s</div><div class=\"email-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", msgid + 1, 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);
|
sprintf(buffer, "<div class=\"email-summary\"><div class=\"email-id\">%d</div><div class=\"email-subject\"><a href=\"/email/%d\">%s</a></div><div class=\"email-from\">%s</div><div class=\"email-date\">%.2d:%.2d %.2d-%.2d-%.2d</div><div class=\"email-delete\"><a href=\"/email/delete/%d\"><img src=\"/static/delete.png\" alt=\"delete\" /></a></div></div>\n", msgid + 1, 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, id);
|
||||||
if (len + strlen(buffer) > max_len - 1) {
|
if (len + strlen(buffer) > max_len - 1) {
|
||||||
max_len += 4096;
|
max_len += 4096;
|
||||||
page = (char *)realloc(page, max_len);
|
page = (char *)realloc(page, max_len);
|
||||||
@ -496,7 +549,7 @@ char *www_email_summary(struct user_record *user) {
|
|||||||
strcat(page, buffer);
|
strcat(page, buffer);
|
||||||
len += strlen(buffer);
|
len += strlen(buffer);
|
||||||
} else {
|
} else {
|
||||||
sprintf(buffer, "<div class=\"email-summary-seen\"><div class=\"email-id\">%d</div><div class=\"email-subject\"><a href=\"/email/%d\">%s</a></div><div class=\"email-from\">%s</div><div class=\"email-date\">%.2d:%.2d %.2d-%.2d-%.2d</div></div>\n", msgid + 1, 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);
|
sprintf(buffer, "<div class=\"email-summary-seen\"><div class=\"email-id\">%d</div><div class=\"email-subject\"><a href=\"/email/%d\">%s</a></div><div class=\"email-from\">%s</div><div class=\"email-date\">%.2d:%.2d %.2d-%.2d-%.2d</div><div class=\"email-delete\"><a href=\"/email/delete/%d\"><img src=\"/static/delete.png\" alt=\"delete\" /></a></div></div>\n", msgid + 1, 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, id);
|
||||||
if (len + strlen(buffer) > max_len - 1) {
|
if (len + strlen(buffer) > max_len - 1) {
|
||||||
max_len += 4096;
|
max_len += 4096;
|
||||||
page = (char *)realloc(page, max_len);
|
page = (char *)realloc(page, max_len);
|
||||||
|
Reference in New Issue
Block a user