diff --git a/.gitignore b/.gitignore index 34b9245..e8a71db 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ utils/magiedit/odoors/libs-* utils/magiedit/odoors/exe-* utils/magiedit/odoors/objs-* utils/magiedit/magiedit +msgserial diff --git a/Makefile.linux.WWW b/Makefile.linux.WWW index 6fc14d9..ac304c3 100644 --- a/Makefile.linux.WWW +++ b/Makefile.linux.WWW @@ -1,5 +1,5 @@ CC=cc -CFLAGS=-I/usr/local/include -DENABLE_WWW=1 +CFLAGS=-I/usr/local/include -DENABLE_WWW=1 DEPS = bbs.h JAMLIB = jamlib/jamlib.a ZMODEM = Xmodem/libzmodem.a diff --git a/bbs.h b/bbs.h index 58b215e..68cc21a 100644 --- a/bbs.h +++ b/bbs.h @@ -106,11 +106,11 @@ struct bbs_config { char *irc_server; int irc_port; char *irc_channel; - + char *external_editor_cmd; int external_editor_stdio; int fork; - + int nodes; int newuserlvl; int automsgwritelvl; diff --git a/mail_menu.c b/mail_menu.c index c5b8ef3..16f0f17 100644 --- a/mail_menu.c +++ b/mail_menu.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "jamlib/jam.h" #include "bbs.h" @@ -40,6 +41,86 @@ s_JamBase *open_jam_base(char *path) { return jb; } +unsigned long generate_msgid() { + time_t theTime; + + char buffer[1024]; + + struct tm timeStruct; + struct tm fileStruct; + unsigned long m; + unsigned long y; + unsigned long ya; + unsigned long j; + unsigned long msgid; + unsigned long c; + unsigned long d; + time_t lastread; + unsigned long lastid; + FILE *fptr; + + theTime = time(NULL); + localtime_r(&theTime, &timeStruct); + + m = timeStruct.tm_mon + 1; + y = timeStruct.tm_year + 1900; + d = timeStruct.tm_mday; + + if (m > 2) { + m = m - 3; + } else { + m = m + 9; + y = y - 1; + } + + c = y / 100; + ya = y - 100 * c; + j = (146097 * c) / 4 + (1461 * ya) / 4 + (153 * m + 2) / 5 + d + 1721119; + + msgid = (j % 0x800) * 0x200000; + + snprintf(buffer, 1024, "%s/msgserial", conf.bbs_path); + + fptr = fopen(buffer, "rw"); + if (fptr) { + flock(fileno(fptr), LOCK_EX); + fread(&lastread, sizeof(time_t), 1, fptr); + fread(&lastid, sizeof(unsigned long), 1, fptr); + localtime_r(&lastread, &fileStruct); + + + if (fileStruct.tm_mon != timeStruct.tm_mon || fileStruct.tm_mday != timeStruct.tm_mday || fileStruct.tm_year != timeStruct.tm_year) { + lastread = time(NULL); + lastid = 1; + } else { + lastid++; + } + rewind(fptr); + fwrite(&lastread, sizeof(time_t), 1, fptr); + fwrite(&lastid, sizeof(unsigned long), 1, fptr); + flock(fileno(fptr), LOCK_UN); + fclose(fptr); + } else { + fptr = fopen(buffer, "w"); + if (fptr) { + lastread = time(NULL); + lastid = 1; + flock(fileno(fptr), LOCK_EX); + fwrite(&lastread, sizeof(time_t), 1, fptr); + fwrite(&lastid, sizeof(unsigned long), 1, fptr); + flock(fileno(fptr), LOCK_UN); + fclose(fptr); + } else { + dolog("Unable to open message id log"); + return 0; + } + } + + msgid += lastid; + + return msgid; +} + void free_message_headers(struct msg_headers *msghs) { int i; @@ -759,7 +840,6 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn char *replybody; struct fido_addr *from_addr = NULL; int i, j; - char timestr[17]; int doquit = 0; int skip_line = 0; int chars = 0; @@ -1073,13 +1153,12 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - snprintf(timestr, 16, "%016lx", time(NULL)); - sprintf(buffer, "%d:%d/%d.%d %s", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + sprintf(buffer, "%d:%d/%d.%d %08lx", 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->node, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - ×tr[strlen(timestr) - 8]); + generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; @@ -1092,7 +1171,7 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - &msghs->msgs[mailno]->msgid[strlen(timestr) - 8]); + msghs->msgs[mailno]->msgid); } jsf.LoID = JAMSFLD_REPLYID; @@ -1143,13 +1222,12 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn free(from_addr); } - snprintf(timestr, 16, "%016lx", time(NULL)); - sprintf(buffer, "%d:%d/%d.%d %s", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + sprintf(buffer, "%d:%d/%d.%d %08lx", 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->node, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - ×tr[strlen(timestr) - 8]); + generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; @@ -1162,7 +1240,7 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn conf.mail_conferences[user->cur_mail_conf]->fidoaddr->net, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->node, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - &msghs->msgs[mailno]->msgid[strlen(timestr) - 8]); + msghs->msgs[mailno]->msgid); } jsf.LoID = JAMSFLD_REPLYID; @@ -1290,7 +1368,6 @@ int mail_menu(struct user_record *user) { char *subject; char *from; char *to; - char timestr[17]; char *msg; int closed; struct fido_addr *from_addr = NULL; @@ -1547,13 +1624,11 @@ int mail_menu(struct user_record *user) { jsf.Buffer = (char *)buffer; JAM_PutSubfield(jsp, &jsf); - snprintf(timestr, 16, "%016lx", time(NULL)); - - sprintf(buffer, "%d:%d/%d.%d %s", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + sprintf(buffer, "%d:%d/%d.%d %08lx", 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->node, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - ×tr[strlen(timestr) - 8]); + generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; @@ -1604,13 +1679,12 @@ int mail_menu(struct user_record *user) { free(from_addr); from_addr = NULL; } - snprintf(timestr, 16, "%016lx", time(NULL)); - sprintf(buffer, "%d:%d/%d.%d %s", conf.mail_conferences[user->cur_mail_conf]->fidoaddr->zone, + sprintf(buffer, "%d:%d/%d.%d %08lx", 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->node, conf.mail_conferences[user->cur_mail_conf]->fidoaddr->point, - ×tr[strlen(timestr) - 8]); + generate_msgid()); jsf.LoID = JAMSFLD_MSGID; jsf.HiID = 0; diff --git a/utils/magiedit/main.c b/utils/magiedit/main.c index 2712576..731c3de 100644 --- a/utils/magiedit/main.c +++ b/utils/magiedit/main.c @@ -169,19 +169,22 @@ char *message_editor() { strcat(return_body, body_lines[i]); strcat(return_body, "\r\n"); } - - for (i=0;i 0) { + for (i=0;i 0) { + for (i=0;i