Lines 32-37
Link Here
|
32 |
#include <assert.h> |
32 |
#include <assert.h> |
33 |
#include <dirent.h> |
33 |
#include <dirent.h> |
34 |
#include <errno.h> |
34 |
#include <errno.h> |
|
|
35 |
#include <glob.h> |
35 |
|
36 |
|
36 |
/* Lame fix for systems where NAME_MAX isn't defined after including the above |
37 |
/* Lame fix for systems where NAME_MAX isn't defined after including the above |
37 |
* set of .h files (Solaris, FreeBSD so far). Probably grossly oversized but |
38 |
* set of .h files (Solaris, FreeBSD so far). Probably grossly oversized but |
Lines 654-659
Link Here
|
654 |
} |
655 |
} |
655 |
} |
656 |
} |
656 |
/*}}}*/ |
657 |
/*}}}*/ |
|
|
658 |
char *find_new_link_target(char *link_target)/*{{{*/ |
659 |
{ |
660 |
int ret, colon_pos; |
661 |
char *target_glob,*pos,*new_target=NULL; |
662 |
glob_t pglob; |
663 |
|
664 |
/* create search pattern */ |
665 |
pos = strrchr( link_target, ':'); |
666 |
if( pos ) colon_pos = pos - link_target; |
667 |
else colon_pos = strlen(link_target); |
668 |
target_glob = Malloc( colon_pos + 2); |
669 |
strncpy( target_glob, link_target, colon_pos); |
670 |
target_glob[colon_pos] = '*'; |
671 |
target_glob[colon_pos+1] = '\0'; |
672 |
|
673 |
ret = glob( target_glob, GLOB_NOSORT, NULL, &pglob ); |
674 |
|
675 |
/* if we found nothing yet, possibly replace /new/ with /cur/ |
676 |
and search again */ |
677 |
if( (ret == GLOB_NOMATCH) && change_new_to_cur(target_glob) ) |
678 |
ret = glob( target_glob, GLOB_NOSORT, NULL, &pglob ); |
679 |
|
680 |
switch(ret) { |
681 |
case 0: |
682 |
if( pglob.gl_pathc > 1) |
683 |
fprintf(stderr, "Matched more than one file for %s.\n", target_glob); |
684 |
else { |
685 |
if(verbose) fprintf(stderr, "Using completion %s.\n", target_glob); |
686 |
new_target=new_string(pglob.gl_pathv[0]); |
687 |
} |
688 |
break; |
689 |
case GLOB_NOMATCH: |
690 |
if (verbose) fprintf(stderr, "Found no completions for %s\n", target_glob); |
691 |
break; |
692 |
default: |
693 |
fprintf(stderr, "Error while running glob on %s\n", target_glob); |
694 |
} |
695 |
|
696 |
free(target_glob); |
697 |
globfree(&pglob); |
698 |
|
699 |
return new_target; |
700 |
} |
701 |
/*}}}*/ |
657 |
static void create_symlink(char *link_target, char *new_link)/*{{{*/ |
702 |
static void create_symlink(char *link_target, char *new_link)/*{{{*/ |
658 |
{ |
703 |
{ |
659 |
if (symlink(link_target, new_link) < 0) { |
704 |
if (symlink(link_target, new_link) < 0) { |
Lines 776-782
Link Here
|
776 |
*is_flagged = (db->msg_type_and_flags[idx] & FLAG_FLAGGED) ? 1 : 0; |
821 |
*is_flagged = (db->msg_type_and_flags[idx] & FLAG_FLAGGED) ? 1 : 0; |
777 |
} |
822 |
} |
778 |
|
823 |
|
779 |
static int do_search(struct read_db *db, char **args, char *output_path, int show_threads, enum folder_type ft, int verbose)/*{{{*/ |
824 |
static int do_search(struct read_db *db, char **args, char *output_path, int show_threads, enum folder_type ft, |
|
|
825 |
int verbose, int do_md_completion)/*{{{*/ |
780 |
{ |
826 |
{ |
781 |
char *colon, *start_words; |
827 |
char *colon, *start_words; |
782 |
int do_body, do_subject, do_from, do_to, do_cc, do_date, do_size; |
828 |
int do_body, do_subject, do_from, do_to, do_cc, do_date, do_size; |
Lines 1037-1049
Link Here
|
1037 |
switch (rd_msg_type(db, i)) { |
1083 |
switch (rd_msg_type(db, i)) { |
1038 |
case DB_MSG_FILE: |
1084 |
case DB_MSG_FILE: |
1039 |
{ |
1085 |
{ |
1040 |
char *target_path; |
1086 |
char *target_path, *new_target=NULL; |
1041 |
char *message_path; |
1087 |
char *message_path; |
1042 |
int is_in_new; |
1088 |
int is_in_new; |
|
|
1089 |
struct msgpath mgp; |
1043 |
message_path = db->data + db->path_offsets[i]; |
1090 |
message_path = db->data + db->path_offsets[i]; |
|
|
1091 |
if (do_md_completion && access(message_path, F_OK)) |
1092 |
/* if target does not exist anymore, try file completion */ |
1093 |
new_target = find_new_link_target(message_path); |
1094 |
if(new_target) { |
1095 |
mgp.src.mpf.path = new_target; |
1096 |
scan_maildir_flags(&mgp); |
1097 |
target_path = mk_maildir_path(i, output_path, 0, mgp.seen, mgp.replied, mgp.flagged); |
1098 |
create_symlink(new_target, target_path); |
1099 |
free(new_target); |
1100 |
} else { |
1044 |
is_in_new = looks_like_maildir_new_p(message_path); |
1101 |
is_in_new = looks_like_maildir_new_p(message_path); |
1045 |
target_path = mk_maildir_path(i, output_path, is_in_new, is_seen, is_replied, is_flagged); |
1102 |
target_path = mk_maildir_path(i, output_path, is_in_new, is_seen, is_replied, is_flagged); |
1046 |
create_symlink(message_path, target_path); |
1103 |
create_symlink(message_path, target_path); |
|
|
1104 |
} |
1047 |
free(target_path); |
1105 |
free(target_path); |
1048 |
++n_hits; |
1106 |
++n_hits; |
1049 |
} |
1107 |
} |
Lines 1069-1076
Link Here
|
1069 |
switch (rd_msg_type(db, i)) { |
1127 |
switch (rd_msg_type(db, i)) { |
1070 |
case DB_MSG_FILE: |
1128 |
case DB_MSG_FILE: |
1071 |
{ |
1129 |
{ |
|
|
1130 |
char *message_path, *new_target=NULL; |
1072 |
char *target_path = mk_mh_path(i, output_path); |
1131 |
char *target_path = mk_mh_path(i, output_path); |
1073 |
create_symlink(db->data + db->path_offsets[i], target_path); |
1132 |
message_path = db->data + db->path_offsets[i]; |
|
|
1133 |
if (do_md_completion && access(message_path, F_OK)) |
1134 |
/* if target does not exist anymore, try file completion */ |
1135 |
new_target = find_new_link_target(message_path); |
1136 |
if(new_target) { |
1137 |
create_symlink(new_target, target_path); |
1138 |
free(new_target); |
1139 |
} else |
1140 |
create_symlink(message_path, target_path); |
1074 |
free(target_path); |
1141 |
free(target_path); |
1075 |
++n_hits; |
1142 |
++n_hits; |
1076 |
} |
1143 |
} |
Lines 1382-1388
Link Here
|
1382 |
} |
1449 |
} |
1383 |
/*}}}*/ |
1450 |
/*}}}*/ |
1384 |
|
1451 |
|
1385 |
int search_top(int do_threads, int do_augment, char *database_path, char *complete_mfolder, char **argv, enum folder_type ft, int verbose)/*{{{*/ |
1452 |
int search_top(int do_threads, int do_augment, char *database_path, char *complete_mfolder, |
|
|
1453 |
char **argv, enum folder_type ft, int verbose, int do_md_completion)/*{{{*/ |
1386 |
{ |
1454 |
{ |
1387 |
struct read_db *db; |
1455 |
struct read_db *db; |
1388 |
int result; |
1456 |
int result; |
Lines 1428-1434
Link Here
|
1428 |
} |
1496 |
} |
1429 |
} |
1497 |
} |
1430 |
|
1498 |
|
1431 |
result = do_search(db, argv, complete_mfolder, do_threads, ft, verbose); |
1499 |
result = do_search(db, argv, complete_mfolder, do_threads, ft, verbose, do_md_completion); |
1432 |
free(complete_mfolder); |
1500 |
free(complete_mfolder); |
1433 |
close_db(db); |
1501 |
close_db(db); |
1434 |
return result; |
1502 |
return result; |