mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-26 07:30:13 +01:00
added -a command line swith to reindex to reindex all stored emails
This commit is contained in:
parent
34568e7d82
commit
26df94f5e5
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#define VERSION "0.1.22"
|
#define VERSION "0.1.22"
|
||||||
|
|
||||||
#define BUILD 731
|
#define BUILD 732
|
||||||
|
|
||||||
#define HOSTID "mailarchiver"
|
#define HOSTID "mailarchiver"
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ void usage(){
|
|||||||
printf(" [-c|--config <config file>] \n");
|
printf(" [-c|--config <config file>] \n");
|
||||||
printf(" -f <from id>\n");
|
printf(" -f <from id>\n");
|
||||||
printf(" -t <to id>\n");
|
printf(" -t <to id>\n");
|
||||||
|
printf(" -a\n");
|
||||||
printf(" [-p]\n");
|
printf(" [-p]\n");
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -41,6 +42,31 @@ void p_clean_exit(char *msg, int rc){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint64 get_max_meta_id(struct session_data *sdata){
|
||||||
|
MYSQL_RES *res;
|
||||||
|
MYSQL_ROW row;
|
||||||
|
char s[SMALLBUFSIZE];
|
||||||
|
int rc;
|
||||||
|
uint64 id=0;
|
||||||
|
|
||||||
|
snprintf(s, sizeof(s)-1, "SELECT MAX(`id`) FROM %s", SQL_METADATA_TABLE);
|
||||||
|
|
||||||
|
rc = mysql_real_query(&(sdata->mysql), s, strlen(s));
|
||||||
|
|
||||||
|
if(rc == 0){
|
||||||
|
res = mysql_store_result(&(sdata->mysql));
|
||||||
|
if(res){
|
||||||
|
row = mysql_fetch_row(res);
|
||||||
|
if(row){
|
||||||
|
id = strtoull(row[0], NULL, 10);
|
||||||
|
}
|
||||||
|
mysql_free_result(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *data, uint64 from_id, uint64 to_id, struct __config *cfg){
|
uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *data, uint64 from_id, uint64 to_id, struct __config *cfg){
|
||||||
MYSQL_RES *res;
|
MYSQL_RES *res;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
@ -111,7 +137,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct __data *
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int c;
|
int c, all=0;
|
||||||
uint64 from_id=0, to_id=0, n=0;
|
uint64 from_id=0, to_id=0, n=0;
|
||||||
char *configfile=CONFIG_FILE, *folder=NULL;
|
char *configfile=CONFIG_FILE, *folder=NULL;
|
||||||
struct session_data sdata;
|
struct session_data sdata;
|
||||||
@ -120,7 +146,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
c = getopt(argc, argv, "c:f:t:F:phv?");
|
c = getopt(argc, argv, "c:f:t:F:pahv?");
|
||||||
|
|
||||||
if(c == -1) break;
|
if(c == -1) break;
|
||||||
|
|
||||||
@ -138,6 +164,10 @@ int main(int argc, char **argv){
|
|||||||
to_id = strtoull(optarg, NULL, 10);
|
to_id = strtoull(optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'a' :
|
||||||
|
all = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'F' :
|
case 'F' :
|
||||||
folder = optarg;
|
folder = optarg;
|
||||||
break;
|
break;
|
||||||
@ -156,7 +186,7 @@ int main(int argc, char **argv){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(from_id <= 0 || to_id <= 0) usage();
|
if(all == 0 && (from_id <= 0 || to_id <= 0) ) usage();
|
||||||
|
|
||||||
|
|
||||||
(void) openlog("reindex", LOG_PID, LOG_MAIL);
|
(void) openlog("reindex", LOG_PID, LOG_MAIL);
|
||||||
@ -195,6 +225,11 @@ int main(int argc, char **argv){
|
|||||||
mysql_real_query(&(sdata.mysql), "SET CHARACTER SET utf8", strlen("SET CHARACTER SET utf8"));
|
mysql_real_query(&(sdata.mysql), "SET CHARACTER SET utf8", strlen("SET CHARACTER SET utf8"));
|
||||||
|
|
||||||
|
|
||||||
|
if(all == 1){
|
||||||
|
from_id = 1;
|
||||||
|
to_id = get_max_meta_id(&sdata);
|
||||||
|
}
|
||||||
|
|
||||||
n = retrieve_email_by_metadata_id(&sdata, &data, from_id, to_id, &cfg);
|
n = retrieve_email_by_metadata_id(&sdata, &data, from_id, to_id, &cfg);
|
||||||
|
|
||||||
printf("put %llu messages to %s table for reindexing\n", n, SQL_SPHINX_TABLE);
|
printf("put %llu messages to %s table for reindexing\n", n, SQL_SPHINX_TABLE);
|
||||||
|
Loading…
Reference in New Issue
Block a user