mbox: test driver improved
This commit is contained in:
parent
6f431e2455
commit
629e62e2b8
@ -520,7 +520,9 @@ using namespace std;
|
|||||||
|
|
||||||
static char *thisprog;
|
static char *thisprog;
|
||||||
|
|
||||||
static char usage [] =
|
static char usage [] =
|
||||||
|
"Test driver for mbox walking function\n"
|
||||||
|
"mh_mbox [-m num] mboxfile\n"
|
||||||
" \n\n"
|
" \n\n"
|
||||||
;
|
;
|
||||||
static void
|
static void
|
||||||
@ -534,57 +536,87 @@ RclConfig *RclConfig::getMainConfig()
|
|||||||
{
|
{
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
static int op_flags;
|
||||||
|
#define OPT_MOINS 0x1
|
||||||
|
#define OPT_m 0x2
|
||||||
|
//#define OPT_t 0x4
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
thisprog = argv[0];
|
string msgnum;
|
||||||
argc--; argv++;
|
thisprog = argv[0];
|
||||||
|
|
||||||
while (argc > 0 && **argv == '-') {
|
|
||||||
(*argv)++;
|
|
||||||
if (!(**argv))
|
|
||||||
/* Cas du "adb - core" */
|
|
||||||
Usage();
|
|
||||||
while (**argv)
|
|
||||||
switch (*(*argv)++) {
|
|
||||||
default: Usage(); break;
|
|
||||||
}
|
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
}
|
|
||||||
|
|
||||||
if (argc != 1)
|
while (argc > 0 && **argv == '-') {
|
||||||
Usage();
|
(*argv)++;
|
||||||
string filename = *argv++;argc--;
|
if (!(**argv))
|
||||||
string reason;
|
/* Cas du "adb - core" */
|
||||||
config = recollinit(RclInitFlags(0), 0, 0, reason, 0);
|
Usage();
|
||||||
if (config == 0) {
|
while (**argv)
|
||||||
cerr << "init failed " << reason << endl;
|
switch (*(*argv)++) {
|
||||||
exit(1);
|
case 'm': op_flags |= OPT_m; if (argc < 2) Usage();
|
||||||
}
|
msgnum = *(++argv);
|
||||||
MimeHandlerMbox mh("text/x-mail");
|
argc--;
|
||||||
if (!mh.set_document_file(filename)) {
|
goto b1;
|
||||||
cerr << "set_document_file failed" << endl;
|
// case 't': op_flags |= OPT_t;break;
|
||||||
exit(1);
|
default: Usage(); break;
|
||||||
}
|
}
|
||||||
int docnt = 0;
|
b1: argc--; argv++;
|
||||||
while (mh.has_documents()) {
|
}
|
||||||
if (!mh.next_document()) {
|
|
||||||
cerr << "next_document failed" << endl;
|
if (argc != 1)
|
||||||
exit(1);
|
Usage();
|
||||||
}
|
string filename = *argv++;argc--;
|
||||||
map<string, string>::const_iterator it =
|
string reason;
|
||||||
mh.get_meta_data().find("content");
|
config = recollinit(RclInitFlags(0), 0, 0, reason, 0);
|
||||||
int size;
|
if (config == 0) {
|
||||||
if (it == mh.get_meta_data().end()) {
|
cerr << "init failed " << reason << endl;
|
||||||
size = -1;
|
exit(1);
|
||||||
} else {
|
}
|
||||||
size = it->second.length();
|
config->setKeyDir(path_getfather(filename));
|
||||||
}
|
MimeHandlerMbox mh("text/x-mail");
|
||||||
cout << "Doc " << docnt << " size " << size << endl;
|
if (!mh.set_document_file(filename)) {
|
||||||
docnt++;
|
cerr << "set_document_file failed" << endl;
|
||||||
}
|
exit(1);
|
||||||
cout << docnt << " documents found in " << filename << endl;
|
}
|
||||||
exit(0);
|
if (!msgnum.empty()) {
|
||||||
|
mh.skip_to_document(msgnum);
|
||||||
|
if (!mh.next_document()) {
|
||||||
|
cerr << "next_document failed after skipping to " << msgnum << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
map<string, string>::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<string, string>::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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user