diff --git a/src/internfile/mh_mbox.cpp b/src/internfile/mh_mbox.cpp index 035b0eeb..0ce15711 100644 --- a/src/internfile/mh_mbox.cpp +++ b/src/internfile/mh_mbox.cpp @@ -520,7 +520,9 @@ using namespace std; static char *thisprog; -static char usage [] = +static char usage [] = +"Test driver for mbox walking function\n" +"mh_mbox [-m num] mboxfile\n" " \n\n" ; static void @@ -534,57 +536,87 @@ RclConfig *RclConfig::getMainConfig() { return config; } +static int op_flags; +#define OPT_MOINS 0x1 +#define OPT_m 0x2 +//#define OPT_t 0x4 int main(int argc, char **argv) { - thisprog = argv[0]; - argc--; argv++; - - while (argc > 0 && **argv == '-') { - (*argv)++; - if (!(**argv)) - /* Cas du "adb - core" */ - Usage(); - while (**argv) - switch (*(*argv)++) { - default: Usage(); break; - } + string msgnum; + thisprog = argv[0]; argc--; argv++; - } - if (argc != 1) - Usage(); - string filename = *argv++;argc--; - string reason; - config = recollinit(RclInitFlags(0), 0, 0, reason, 0); - if (config == 0) { - cerr << "init failed " << reason << endl; - exit(1); - } - MimeHandlerMbox mh("text/x-mail"); - if (!mh.set_document_file(filename)) { - cerr << "set_document_file failed" << endl; - exit(1); - } - int docnt = 0; - while (mh.has_documents()) { - if (!mh.next_document()) { - cerr << "next_document failed" << endl; - exit(1); - } - map::const_iterator it = - mh.get_meta_data().find("content"); - int size; - if (it == mh.get_meta_data().end()) { - size = -1; - } else { - size = it->second.length(); - } - cout << "Doc " << docnt << " size " << size << endl; - docnt++; - } - cout << docnt << " documents found in " << filename << endl; - exit(0); + while (argc > 0 && **argv == '-') { + (*argv)++; + if (!(**argv)) + /* Cas du "adb - core" */ + Usage(); + while (**argv) + switch (*(*argv)++) { + case 'm': op_flags |= OPT_m; if (argc < 2) Usage(); + msgnum = *(++argv); + argc--; + goto b1; +// case 't': op_flags |= OPT_t;break; + default: Usage(); break; + } + b1: argc--; argv++; + } + + if (argc != 1) + Usage(); + string filename = *argv++;argc--; + string reason; + config = recollinit(RclInitFlags(0), 0, 0, reason, 0); + if (config == 0) { + cerr << "init failed " << reason << endl; + exit(1); + } + config->setKeyDir(path_getfather(filename)); + MimeHandlerMbox mh("text/x-mail"); + if (!mh.set_document_file(filename)) { + cerr << "set_document_file failed" << endl; + exit(1); + } + if (!msgnum.empty()) { + mh.skip_to_document(msgnum); + if (!mh.next_document()) { + cerr << "next_document failed after skipping to " << msgnum << endl; + exit(1); + } + map::const_iterator it = + mh.get_meta_data().find("content"); + int size; + if (it == mh.get_meta_data().end()) { + size = -1; + cerr << "No content!!" << endl; + exit(1); + } + cout << "Doc " << msgnum << ":" << endl; + cout << it->second << endl; + exit(0); + } + + int docnt = 0; + while (mh.has_documents()) { + if (!mh.next_document()) { + cerr << "next_document failed" << endl; + exit(1); + } + docnt++; + map::const_iterator it = + mh.get_meta_data().find("content"); + int size; + if (it == mh.get_meta_data().end()) { + size = -1; + } else { + size = it->second.length(); + } + cout << "Doc " << docnt << " size " << size << endl; + } + cout << docnt << " documents found in " << filename << endl; + exit(0); }