redesigned the top storing directory structure

This commit is contained in:
SJ 2012-12-15 09:57:24 +01:00
parent 83224cd9d3
commit fee08e9de8
5 changed files with 31 additions and 9 deletions

View File

@ -206,6 +206,8 @@ int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct _
int i, attachments; int i, attachments;
char *buffer=NULL, *saved_buffer, *p, filename[SMALLBUFSIZE], pointer[SMALLBUFSIZE]; char *buffer=NULL, *saved_buffer, *p, filename[SMALLBUFSIZE], pointer[SMALLBUFSIZE];
struct ptr_array ptr_arr[MAX_ATTACHMENTS]; struct ptr_array ptr_arr[MAX_ATTACHMENTS];
struct stat st;
if(strlen(sdata->ttmpfile) != RND_STR_LEN){ if(strlen(sdata->ttmpfile) != RND_STR_LEN){
printf("invalid piler-id: %s\n", sdata->ttmpfile); printf("invalid piler-id: %s\n", sdata->ttmpfile);
@ -219,7 +221,10 @@ int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct _
return 1; return 1;
} }
snprintf(filename, sizeof(filename)-1, "%s/%c%c%c/%c%c/%c%c/%s.m", cfg->queuedir, *(sdata->ttmpfile+8), *(sdata->ttmpfile+9), *(sdata->ttmpfile+10), *(sdata->ttmpfile+RND_STR_LEN-4), *(sdata->ttmpfile+RND_STR_LEN-3), *(sdata->ttmpfile+RND_STR_LEN-2), *(sdata->ttmpfile+RND_STR_LEN-1), sdata->ttmpfile);
if(stat(filename, &st)){
snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.m", cfg->queuedir, *(sdata->ttmpfile+RND_STR_LEN-6), *(sdata->ttmpfile+RND_STR_LEN-5), *(sdata->ttmpfile+RND_STR_LEN-4), *(sdata->ttmpfile+RND_STR_LEN-3), *(sdata->ttmpfile+RND_STR_LEN-2), *(sdata->ttmpfile+RND_STR_LEN-1), sdata->ttmpfile); snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.m", cfg->queuedir, *(sdata->ttmpfile+RND_STR_LEN-6), *(sdata->ttmpfile+RND_STR_LEN-5), *(sdata->ttmpfile+RND_STR_LEN-4), *(sdata->ttmpfile+RND_STR_LEN-3), *(sdata->ttmpfile+RND_STR_LEN-2), *(sdata->ttmpfile+RND_STR_LEN-1), sdata->ttmpfile);
}
if(attachments == 0){ if(attachments == 0){
retrieve_file_from_archive(filename, WRITE_TO_STDOUT, &buffer, dest, cfg); retrieve_file_from_archive(filename, WRITE_TO_STDOUT, &buffer, dest, cfg);
@ -240,7 +245,11 @@ int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct _
buffer = p + strlen(pointer); buffer = p + strlen(pointer);
if(strlen(ptr_arr[i].piler_id) == RND_STR_LEN){ if(strlen(ptr_arr[i].piler_id) == RND_STR_LEN){
snprintf(filename, sizeof(filename)-1, "%s/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, ptr_arr[i].piler_id[8], ptr_arr[i].piler_id[9], ptr_arr[i].piler_id[10], ptr_arr[i].piler_id[RND_STR_LEN-4], ptr_arr[i].piler_id[RND_STR_LEN-3], ptr_arr[i].piler_id[RND_STR_LEN-2], ptr_arr[i].piler_id[RND_STR_LEN-1], ptr_arr[i].piler_id, ptr_arr[i].attachment_id);
if(stat(filename, &st)){
snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, ptr_arr[i].piler_id[RND_STR_LEN-6], ptr_arr[i].piler_id[RND_STR_LEN-5], ptr_arr[i].piler_id[RND_STR_LEN-4], ptr_arr[i].piler_id[RND_STR_LEN-3], ptr_arr[i].piler_id[RND_STR_LEN-2], ptr_arr[i].piler_id[RND_STR_LEN-1], ptr_arr[i].piler_id, ptr_arr[i].attachment_id); snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, ptr_arr[i].piler_id[RND_STR_LEN-6], ptr_arr[i].piler_id[RND_STR_LEN-5], ptr_arr[i].piler_id[RND_STR_LEN-4], ptr_arr[i].piler_id[RND_STR_LEN-3], ptr_arr[i].piler_id[RND_STR_LEN-2], ptr_arr[i].piler_id[RND_STR_LEN-1], ptr_arr[i].piler_id, ptr_arr[i].attachment_id);
}
retrieve_file_from_archive(filename, WRITE_TO_STDOUT, NULL, dest, cfg); retrieve_file_from_archive(filename, WRITE_TO_STDOUT, NULL, dest, cfg);
} }

View File

@ -13,7 +13,7 @@
#define VERSION "0.1.23-master-branch" #define VERSION "0.1.23-master-branch"
#define BUILD 741 #define BUILD 742
#define HOSTID "mailarchiver" #define HOSTID "mailarchiver"

View File

@ -19,6 +19,7 @@
int main(int argc, char **argv){ int main(int argc, char **argv){
int readkey=1; int readkey=1;
char filename[SMALLBUFSIZE]; char filename[SMALLBUFSIZE];
struct stat st;
struct __config cfg; struct __config cfg;
@ -43,7 +44,10 @@ int main(int argc, char **argv){
return 1; return 1;
} }
snprintf(filename, sizeof(filename)-1, "%s/%c%c%c/%c%c/%c%c/%s.a%d", cfg.queuedir, argv[1][8], argv[1][9], argv[1][10], argv[1][RND_STR_LEN-4], argv[1][RND_STR_LEN-3], argv[1][RND_STR_LEN-2], argv[1][RND_STR_LEN-1], argv[1], atoi(argv[2]));
if(stat(filename, &st)){
snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.a%d", cfg.queuedir, argv[1][RND_STR_LEN-6], argv[1][RND_STR_LEN-5], argv[1][RND_STR_LEN-4], argv[1][RND_STR_LEN-3], argv[1][RND_STR_LEN-2], argv[1][RND_STR_LEN-1], argv[1], atoi(argv[2])); snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.a%d", cfg.queuedir, argv[1][RND_STR_LEN-6], argv[1][RND_STR_LEN-5], argv[1][RND_STR_LEN-4], argv[1][RND_STR_LEN-3], argv[1][RND_STR_LEN-2], argv[1][RND_STR_LEN-1], argv[1], atoi(argv[2]));
}
retrieve_file_from_archive(filename, WRITE_TO_STDOUT, NULL, stdout, &cfg); retrieve_file_from_archive(filename, WRITE_TO_STDOUT, NULL, stdout, &cfg);

View File

@ -53,13 +53,18 @@ int is_purge_allowed(struct session_data *sdata, struct __config *cfg){
int remove_message_frame_files(char *s, char *update_meta_sql, struct session_data *sdata, struct __config *cfg){ int remove_message_frame_files(char *s, char *update_meta_sql, struct session_data *sdata, struct __config *cfg){
char *p, puf[SMALLBUFSIZE], filename[SMALLBUFSIZE]; char *p, puf[SMALLBUFSIZE], filename[SMALLBUFSIZE];
int n=0; int n=0;
struct stat st;
p = s; p = s;
do { do {
p = split(p, ' ', puf, sizeof(puf)-1); p = split(p, ' ', puf, sizeof(puf)-1);
if(strlen(puf) == RND_STR_LEN){ if(strlen(puf) == RND_STR_LEN){
snprintf(filename, sizeof(filename)-1, "%s/%c%c%c/%c%c/%c%c/%s.m", cfg->queuedir, puf[8], puf[9], puf[10], puf[RND_STR_LEN-4], puf[RND_STR_LEN-3], puf[RND_STR_LEN-2], puf[RND_STR_LEN-1], puf);
if(stat(filename, &st)){
snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.m", cfg->queuedir, puf[RND_STR_LEN-6], puf[RND_STR_LEN-5], puf[RND_STR_LEN-4], puf[RND_STR_LEN-3], puf[RND_STR_LEN-2], puf[RND_STR_LEN-1], puf); snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.m", cfg->queuedir, puf[RND_STR_LEN-6], puf[RND_STR_LEN-5], puf[RND_STR_LEN-4], puf[RND_STR_LEN-3], puf[RND_STR_LEN-2], puf[RND_STR_LEN-1], puf);
}
if(dryrun == 1){ if(dryrun == 1){
n++; n++;
@ -92,6 +97,7 @@ int remove_attachments(char *in, struct session_data *sdata, struct __config *cf
int n=0, len; int n=0, len;
MYSQL_RES *res; MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
struct stat st;
if(strlen(in) < 10) return 0; if(strlen(in) < 10) return 0;
@ -123,7 +129,10 @@ int remove_attachments(char *in, struct session_data *sdata, struct __config *cf
while((row = mysql_fetch_row(res))){ while((row = mysql_fetch_row(res))){
if(!row[0]) continue; if(!row[0]) continue;
snprintf(filename, sizeof(filename)-1, "%s/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, row[0][8], row[0][9], row[0][10], row[0][RND_STR_LEN-4], row[0][RND_STR_LEN-3], row[0][RND_STR_LEN-2], row[0][RND_STR_LEN-1], row[0], atoi(row[1]));
if(stat(filename, &st)){
snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, row[0][RND_STR_LEN-6], row[0][RND_STR_LEN-5], row[0][RND_STR_LEN-4], row[0][RND_STR_LEN-3], row[0][RND_STR_LEN-2], row[0][RND_STR_LEN-1], row[0], atoi(row[1])); snprintf(filename, sizeof(filename)-1, "%s/%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, row[0][RND_STR_LEN-6], row[0][RND_STR_LEN-5], row[0][RND_STR_LEN-4], row[0][RND_STR_LEN-3], row[0][RND_STR_LEN-2], row[0][RND_STR_LEN-1], row[0], atoi(row[1]));
}
if(dryrun == 1){ if(dryrun == 1){
printf("removing attachment: *%s*\n", filename); printf("removing attachment: *%s*\n", filename);

View File

@ -113,7 +113,7 @@ int store_file(struct session_data *sdata, char *filename, int startpos, int len
p = strchr(filename, '.'); p = strchr(filename, '.');
if(p) *p = '\0'; if(p) *p = '\0';
snprintf(s, sizeof(s)-1, "%s/%c%c/%c%c/%c%c/%s", cfg->queuedir, filename[RND_STR_LEN-6], filename[RND_STR_LEN-5], filename[RND_STR_LEN-4], filename[RND_STR_LEN-3], filename[RND_STR_LEN-2], filename[RND_STR_LEN-1], filename); snprintf(s, sizeof(s)-1, "%s/%c%c%c/%c%c/%c%c/%s", cfg->queuedir, filename[8], filename[9], filename[10], filename[RND_STR_LEN-4], filename[RND_STR_LEN-3], filename[RND_STR_LEN-2], filename[RND_STR_LEN-1], filename);
if(p){ if(p){
*p = '.'; *p = '.';
@ -180,7 +180,7 @@ int remove_stored_message_files(struct session_data *sdata, struct _state *state
if(state->n_attachments > 0){ if(state->n_attachments > 0){
for(i=1; i<=state->n_attachments; i++){ for(i=1; i<=state->n_attachments; i++){
snprintf(s, sizeof(s)-1, "%s/%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, sdata->ttmpfile[RND_STR_LEN-6], sdata->ttmpfile[RND_STR_LEN-5], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile, i); snprintf(s, sizeof(s)-1, "%s/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, sdata->ttmpfile[8], sdata->ttmpfile[9], sdata->ttmpfile[10], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile, i);
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s); if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s);
@ -188,7 +188,7 @@ int remove_stored_message_files(struct session_data *sdata, struct _state *state
} }
} }
snprintf(s, sizeof(s)-1, "%s/%c%c/%c%c/%c%c/%s.m", cfg->queuedir, sdata->ttmpfile[RND_STR_LEN-6], sdata->ttmpfile[RND_STR_LEN-5], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile); snprintf(s, sizeof(s)-1, "%s/%c%c%c/%c%c/%c%c/%s.m", cfg->queuedir, sdata->ttmpfile[8], sdata->ttmpfile[9], sdata->ttmpfile[10], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile);
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s); if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s);