forked from tat/mimetic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmm.cxx
86 lines (74 loc) · 2.26 KB
/
mm.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/***************************************************************************
copyright : (C) 2002-2008 by Stefano Barbato
email : [email protected]
$Id: mm.cxx,v 1.3 2008-10-07 11:06:25 tat Exp $
***************************************************************************/
#include <fstream>
#include <streambuf>
#include <cassert>
#include <getopt.h>
#include <mimetic/mimetic.h>
#include "mm.h"
#include "cmdline.h"
#include "engine.h"
using namespace std;
using namespace mimetic;
void print_cmd_info()
{
static const char *cmd_info =
"mm " MM_VERSION ", a multipurpose mail tool\n"
"Copyright (c) 2003 by Stefano Barbato - All rights reserved.\n";
cerr << cmd_info << endl;
}
void do_usage_if(int b, const string& file, int line)
{
const static char *usage =
"WARNING: mm is still under development. It's NOT ready for production!\n"
"Usage: mm [MATCH] [ACTION] [INFILE] [OUTFILE]\n" ;
if(!b)
return;
cerr << usage << endl << "[" << file << ":" << line << "]" << endl;
exit(1);
}
void do_die_if(int b, const std::string& msg, const string& file, int line)
{
if(!b)
return;
cerr << "Error [" << file << ":" << line << "]: " << msg << endl;
exit(1);
}
int main(int argc, char** argv)
{
std::ios_base::sync_with_stdio(false);
command_line cl;
die_if(!cl.parse_cmd_line(argc, argv), "command line error");
string fqn;
filebuf fin;
filebuf fout;
if(cl.is_set("out"))
{
fqn = cl["out"];
fout.open(fqn.c_str(), ios::out);
die_if(!fout.is_open(),
string("unable to open output file ")+fqn);
}
if(cl.is_set("in"))
{
fqn = cl["in"];
fin.open(fqn.c_str(), ios::in);
die_if(!fin.is_open(),
string("unable to open input file ")+fqn);
}
print_cmd_info();
engine e(cl);
istream is( fin.is_open() ? &fin : cin.rdbuf());
ostream os( fout.is_open() ? &fout : cout.rdbuf());
istreambuf_iterator<char> ibeg(is), iend;
ostreambuf_iterator<char> out(os);
int iMask = (cl.is_set("ignore-child-parts") ? imChildParts: imNone);
MimeEntity me(ibeg, iend, iMask);
if(!e.match(me))
cerr << "not ";
cerr << "matched" << endl;
return 0;
}