Fossil SCM
Enhance the backoffice to automatically purge stale entries from the emailblob table, if that table exists.
Commit
4c7edd4cfd252ec94ecb3e0f1fa042fcdf6db295a055fc8bdd7daf103c2c8bd1
Parent
731836b8698a2ab…
2 files changed
+1
+19
-8
+1
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -519,10 +519,11 @@ | ||
| 519 | 519 | } |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /* Here is where the actual work of the backoffice happens */ |
| 523 | 523 | email_backoffice(0); |
| 524 | + smtp_cleanup(); | |
| 524 | 525 | } |
| 525 | 526 | |
| 526 | 527 | /* |
| 527 | 528 | ** COMMAND: backoffice |
| 528 | 529 | ** |
| 529 | 530 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -519,10 +519,11 @@ | |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /* Here is where the actual work of the backoffice happens */ |
| 523 | email_backoffice(0); |
| 524 | } |
| 525 | |
| 526 | /* |
| 527 | ** COMMAND: backoffice |
| 528 | ** |
| 529 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -519,10 +519,11 @@ | |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /* Here is where the actual work of the backoffice happens */ |
| 523 | email_backoffice(0); |
| 524 | smtp_cleanup(); |
| 525 | } |
| 526 | |
| 527 | /* |
| 528 | ** COMMAND: backoffice |
| 529 | ** |
| 530 |
+19
-8
| --- src/smtp.c | ||
| +++ src/smtp.c | ||
| @@ -636,12 +636,12 @@ | ||
| 636 | 636 | |
| 637 | 637 | /* |
| 638 | 638 | ** Schema used by the email processing system. |
| 639 | 639 | */ |
| 640 | 640 | static const char zEmailSchema[] = |
| 641 | -@ -- bulk storage is in a separate table. This table can store either | |
| 642 | -@ -- the body of email messages or transcripts of smtp sessions. | |
| 641 | +@ -- bulk storage is in this table. This table can store either | |
| 642 | +@ -- the body of email messages or transcripts of an smtp session. | |
| 643 | 643 | @ CREATE TABLE IF NOT EXISTS repository.emailblob( |
| 644 | 644 | @ emailid INTEGER PRIMARY KEY AUTOINCREMENT, -- numeric idea for the entry |
| 645 | 645 | @ enref INT, -- Number of references to this blob |
| 646 | 646 | @ ets INT, -- Corresponding transcript, or NULL |
| 647 | 647 | @ etime INT, -- insertion time, secs since 1970 |
| @@ -669,12 +669,12 @@ | ||
| 669 | 669 | @ ) WITHOUT ROWID; |
| 670 | 670 | @ |
| 671 | 671 | @ -- Outgoing email queue |
| 672 | 672 | @ CREATE TABLE IF NOT EXISTS repository.emailoutq( |
| 673 | 673 | @ edomain TEXT, -- Destination domain. (ex: "fossil-scm.org") |
| 674 | -@ efrom TEXT, -- Sender email address | |
| 675 | -@ eto TEXT, -- Recipient email address | |
| 674 | +@ efrom TEXT, -- Sender email address (envelope "from") | |
| 675 | +@ eto TEXT, -- Recipient email address (envelope "to") | |
| 676 | 676 | @ emsgid INT, -- Message body in the emailblob table |
| 677 | 677 | @ ectime INT, -- Time enqueued. Seconds since 1970 |
| 678 | 678 | @ emtime INT, -- Time of last send attempt. Sec since 1970 |
| 679 | 679 | @ ensend INT, -- Number of send attempts |
| 680 | 680 | @ ets INT -- Transcript of last failed attempt |
| @@ -1141,10 +1141,24 @@ | ||
| 1141 | 1141 | /* Finish the transaction after all changes are implemented */ |
| 1142 | 1142 | db_commit_transaction(); |
| 1143 | 1143 | } |
| 1144 | 1144 | smtp_server_clear(p, SMTPSRV_CLEAR_MSG); |
| 1145 | 1145 | } |
| 1146 | + | |
| 1147 | +/* | |
| 1148 | +** Remove stale content from the emailblob table. | |
| 1149 | +*/ | |
| 1150 | +void smtp_cleanup(void){ | |
| 1151 | + if( db_table_exists("repository","emailblob") ){ | |
| 1152 | + db_begin_transaction(); | |
| 1153 | + db_multi_exec( | |
| 1154 | + "UPDATE emailblob SET ets=NULL WHERE enref<=0;" | |
| 1155 | + "DELETE FROM emailblob WHERE enref<=0;" | |
| 1156 | + ); | |
| 1157 | + db_end_transaction(0); | |
| 1158 | + } | |
| 1159 | +} | |
| 1146 | 1160 | |
| 1147 | 1161 | /* |
| 1148 | 1162 | ** COMMAND: test-emailblob-refcheck |
| 1149 | 1163 | ** |
| 1150 | 1164 | ** Usage: %fossil test-emailblob-refcheck [--repair] [--full] [--clean] |
| @@ -1185,14 +1199,11 @@ | ||
| 1185 | 1199 | if( doRepair ){ |
| 1186 | 1200 | db_multi_exec( |
| 1187 | 1201 | "UPDATE emailblob SET enref=(SELECT n FROM refcnt WHERE id=emailid)" |
| 1188 | 1202 | ); |
| 1189 | 1203 | if( doClean ){ |
| 1190 | - db_multi_exec( | |
| 1191 | - "UPDATE emailblob SET ets=NULL WHERE enref<=0;" | |
| 1192 | - "DELETE FROM emailblob WHERE enref<=0;" | |
| 1193 | - ); | |
| 1204 | + smtp_cleanup(); | |
| 1194 | 1205 | } |
| 1195 | 1206 | } |
| 1196 | 1207 | blob_init(&sql, 0, 0); |
| 1197 | 1208 | blob_append_sql(&sql, |
| 1198 | 1209 | "SELECT a.emailid, a.enref, b.n" |
| 1199 | 1210 |
| --- src/smtp.c | |
| +++ src/smtp.c | |
| @@ -636,12 +636,12 @@ | |
| 636 | |
| 637 | /* |
| 638 | ** Schema used by the email processing system. |
| 639 | */ |
| 640 | static const char zEmailSchema[] = |
| 641 | @ -- bulk storage is in a separate table. This table can store either |
| 642 | @ -- the body of email messages or transcripts of smtp sessions. |
| 643 | @ CREATE TABLE IF NOT EXISTS repository.emailblob( |
| 644 | @ emailid INTEGER PRIMARY KEY AUTOINCREMENT, -- numeric idea for the entry |
| 645 | @ enref INT, -- Number of references to this blob |
| 646 | @ ets INT, -- Corresponding transcript, or NULL |
| 647 | @ etime INT, -- insertion time, secs since 1970 |
| @@ -669,12 +669,12 @@ | |
| 669 | @ ) WITHOUT ROWID; |
| 670 | @ |
| 671 | @ -- Outgoing email queue |
| 672 | @ CREATE TABLE IF NOT EXISTS repository.emailoutq( |
| 673 | @ edomain TEXT, -- Destination domain. (ex: "fossil-scm.org") |
| 674 | @ efrom TEXT, -- Sender email address |
| 675 | @ eto TEXT, -- Recipient email address |
| 676 | @ emsgid INT, -- Message body in the emailblob table |
| 677 | @ ectime INT, -- Time enqueued. Seconds since 1970 |
| 678 | @ emtime INT, -- Time of last send attempt. Sec since 1970 |
| 679 | @ ensend INT, -- Number of send attempts |
| 680 | @ ets INT -- Transcript of last failed attempt |
| @@ -1141,10 +1141,24 @@ | |
| 1141 | /* Finish the transaction after all changes are implemented */ |
| 1142 | db_commit_transaction(); |
| 1143 | } |
| 1144 | smtp_server_clear(p, SMTPSRV_CLEAR_MSG); |
| 1145 | } |
| 1146 | |
| 1147 | /* |
| 1148 | ** COMMAND: test-emailblob-refcheck |
| 1149 | ** |
| 1150 | ** Usage: %fossil test-emailblob-refcheck [--repair] [--full] [--clean] |
| @@ -1185,14 +1199,11 @@ | |
| 1185 | if( doRepair ){ |
| 1186 | db_multi_exec( |
| 1187 | "UPDATE emailblob SET enref=(SELECT n FROM refcnt WHERE id=emailid)" |
| 1188 | ); |
| 1189 | if( doClean ){ |
| 1190 | db_multi_exec( |
| 1191 | "UPDATE emailblob SET ets=NULL WHERE enref<=0;" |
| 1192 | "DELETE FROM emailblob WHERE enref<=0;" |
| 1193 | ); |
| 1194 | } |
| 1195 | } |
| 1196 | blob_init(&sql, 0, 0); |
| 1197 | blob_append_sql(&sql, |
| 1198 | "SELECT a.emailid, a.enref, b.n" |
| 1199 |
| --- src/smtp.c | |
| +++ src/smtp.c | |
| @@ -636,12 +636,12 @@ | |
| 636 | |
| 637 | /* |
| 638 | ** Schema used by the email processing system. |
| 639 | */ |
| 640 | static const char zEmailSchema[] = |
| 641 | @ -- bulk storage is in this table. This table can store either |
| 642 | @ -- the body of email messages or transcripts of an smtp session. |
| 643 | @ CREATE TABLE IF NOT EXISTS repository.emailblob( |
| 644 | @ emailid INTEGER PRIMARY KEY AUTOINCREMENT, -- numeric idea for the entry |
| 645 | @ enref INT, -- Number of references to this blob |
| 646 | @ ets INT, -- Corresponding transcript, or NULL |
| 647 | @ etime INT, -- insertion time, secs since 1970 |
| @@ -669,12 +669,12 @@ | |
| 669 | @ ) WITHOUT ROWID; |
| 670 | @ |
| 671 | @ -- Outgoing email queue |
| 672 | @ CREATE TABLE IF NOT EXISTS repository.emailoutq( |
| 673 | @ edomain TEXT, -- Destination domain. (ex: "fossil-scm.org") |
| 674 | @ efrom TEXT, -- Sender email address (envelope "from") |
| 675 | @ eto TEXT, -- Recipient email address (envelope "to") |
| 676 | @ emsgid INT, -- Message body in the emailblob table |
| 677 | @ ectime INT, -- Time enqueued. Seconds since 1970 |
| 678 | @ emtime INT, -- Time of last send attempt. Sec since 1970 |
| 679 | @ ensend INT, -- Number of send attempts |
| 680 | @ ets INT -- Transcript of last failed attempt |
| @@ -1141,10 +1141,24 @@ | |
| 1141 | /* Finish the transaction after all changes are implemented */ |
| 1142 | db_commit_transaction(); |
| 1143 | } |
| 1144 | smtp_server_clear(p, SMTPSRV_CLEAR_MSG); |
| 1145 | } |
| 1146 | |
| 1147 | /* |
| 1148 | ** Remove stale content from the emailblob table. |
| 1149 | */ |
| 1150 | void smtp_cleanup(void){ |
| 1151 | if( db_table_exists("repository","emailblob") ){ |
| 1152 | db_begin_transaction(); |
| 1153 | db_multi_exec( |
| 1154 | "UPDATE emailblob SET ets=NULL WHERE enref<=0;" |
| 1155 | "DELETE FROM emailblob WHERE enref<=0;" |
| 1156 | ); |
| 1157 | db_end_transaction(0); |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | /* |
| 1162 | ** COMMAND: test-emailblob-refcheck |
| 1163 | ** |
| 1164 | ** Usage: %fossil test-emailblob-refcheck [--repair] [--full] [--clean] |
| @@ -1185,14 +1199,11 @@ | |
| 1199 | if( doRepair ){ |
| 1200 | db_multi_exec( |
| 1201 | "UPDATE emailblob SET enref=(SELECT n FROM refcnt WHERE id=emailid)" |
| 1202 | ); |
| 1203 | if( doClean ){ |
| 1204 | smtp_cleanup(); |
| 1205 | } |
| 1206 | } |
| 1207 | blob_init(&sql, 0, 0); |
| 1208 | blob_append_sql(&sql, |
| 1209 | "SELECT a.emailid, a.enref, b.n" |
| 1210 |