Update msgid generation
This commit is contained in:
parent
4b6adbcbdc
commit
9a0347e47e
12
mail_menu.c
12
mail_menu.c
@ -44,6 +44,7 @@ s_JamBase *open_jam_base(char *path) {
|
|||||||
unsigned long generate_msgid() {
|
unsigned long generate_msgid() {
|
||||||
|
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
time_t unixtime;
|
||||||
|
|
||||||
unsigned long msgid;
|
unsigned long msgid;
|
||||||
unsigned long lastid;
|
unsigned long lastid;
|
||||||
@ -51,11 +52,18 @@ unsigned long generate_msgid() {
|
|||||||
|
|
||||||
snprintf(buffer, 1024, "%s/msgserial", conf.bbs_path);
|
snprintf(buffer, 1024, "%s/msgserial", conf.bbs_path);
|
||||||
|
|
||||||
|
unixtime = time(NULL);
|
||||||
|
|
||||||
fptr = fopen(buffer, "r+");
|
fptr = fopen(buffer, "r+");
|
||||||
if (fptr) {
|
if (fptr) {
|
||||||
flock(fileno(fptr), LOCK_EX);
|
flock(fileno(fptr), LOCK_EX);
|
||||||
fread(&lastid, sizeof(unsigned long), 1, fptr);
|
fread(&lastid, sizeof(unsigned long), 1, fptr);
|
||||||
lastid++;
|
|
||||||
|
if (unixtime > lastid) {
|
||||||
|
lastid = unixtime;
|
||||||
|
} else {
|
||||||
|
lastid++;
|
||||||
|
}
|
||||||
rewind(fptr);
|
rewind(fptr);
|
||||||
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
|
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
|
||||||
flock(fileno(fptr), LOCK_UN);
|
flock(fileno(fptr), LOCK_UN);
|
||||||
@ -63,7 +71,7 @@ unsigned long generate_msgid() {
|
|||||||
} else {
|
} else {
|
||||||
fptr = fopen(buffer, "w");
|
fptr = fopen(buffer, "w");
|
||||||
if (fptr) {
|
if (fptr) {
|
||||||
lastid = 1;
|
lastid = unixtime;
|
||||||
flock(fileno(fptr), LOCK_EX);
|
flock(fileno(fptr), LOCK_EX);
|
||||||
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
|
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
|
||||||
flock(fileno(fptr), LOCK_UN);
|
flock(fileno(fptr), LOCK_UN);
|
||||||
|
@ -140,11 +140,19 @@ unsigned long generate_msgid(char *bbs_path) {
|
|||||||
|
|
||||||
snprintf(buffer, 1024, "%s/msgserial", bbs_path);
|
snprintf(buffer, 1024, "%s/msgserial", bbs_path);
|
||||||
|
|
||||||
|
unixtime = time(NULL);
|
||||||
|
|
||||||
fptr = fopen(buffer, "r+");
|
fptr = fopen(buffer, "r+");
|
||||||
if (fptr) {
|
if (fptr) {
|
||||||
flock(fileno(fptr), LOCK_EX);
|
flock(fileno(fptr), LOCK_EX);
|
||||||
fread(&lastid, sizeof(unsigned long), 1, fptr);
|
fread(&lastid, sizeof(unsigned long), 1, fptr);
|
||||||
lastid++;
|
|
||||||
|
if (unixtime > lastid) {
|
||||||
|
lastid = unixtime;
|
||||||
|
} else {
|
||||||
|
lastid++;
|
||||||
|
}
|
||||||
|
|
||||||
rewind(fptr);
|
rewind(fptr);
|
||||||
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
|
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
|
||||||
flock(fileno(fptr), LOCK_UN);
|
flock(fileno(fptr), LOCK_UN);
|
||||||
@ -152,7 +160,7 @@ unsigned long generate_msgid(char *bbs_path) {
|
|||||||
} else {
|
} else {
|
||||||
fptr = fopen(buffer, "w");
|
fptr = fopen(buffer, "w");
|
||||||
if (fptr) {
|
if (fptr) {
|
||||||
lastid = 1;
|
lastid = unixtime;
|
||||||
flock(fileno(fptr), LOCK_EX);
|
flock(fileno(fptr), LOCK_EX);
|
||||||
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
|
fwrite(&lastid, sizeof(unsigned long), 1, fptr);
|
||||||
flock(fileno(fptr), LOCK_UN);
|
flock(fileno(fptr), LOCK_UN);
|
||||||
|
Reference in New Issue
Block a user