1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
5 $Id: mm.cxx,v 1.2 2005/02/23 10:26:14 tat Exp $
6 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 ***************************************************************************/
20 #include <mimetic/mimetic.h>
26 using namespace mimetic;
31 static const char *cmd_info =
32 "mm " MM_VERSION ", a multipurpose mail tool\n"
33 "Copyright (c) 2003 by Stefano Barbato - All rights reserved.\n";
34 cerr << cmd_info << endl;
37 void do_usage_if(int b, const string& file, int line)
39 const static char *usage =
40 "WARNING: mm is still under development. It's NOT ready for production!\n"
41 "Usage: mm [MATCH] [ACTION] [INFILE] [OUTFILE]\n" ;
44 cerr << usage << endl << "[" << file << ":" << line << "]" << endl;
48 void do_die_if(int b, const std::string& msg, const string& file, int line)
52 cerr << "Error [" << file << ":" << line << "]: " << msg << endl;
57 int main(int argc, char** argv)
59 std::ios_base::sync_with_stdio(false);
62 die_if(!cl.parse_cmd_line(argc, argv), "command line error");
70 fout.open(fqn.c_str(), ios::out);
71 die_if(!fout.is_open(),
72 string("unable to open output file ")+fqn);
77 fin.open(fqn.c_str(), ios::in);
78 die_if(!fin.is_open(),
79 string("unable to open input file ")+fqn);
83 istream is( fin.is_open() ? &fin : cin.rdbuf());
84 ostream os( fout.is_open() ? &fout : cout.rdbuf());
85 istreambuf_iterator<char> ibeg(is), iend;
86 ostreambuf_iterator<char> out(os);
87 int iMask = (cl.is_set("ignore-child-parts") ? imChildParts: imNone);
88 MimeEntity me(ibeg, iend, iMask);
91 cerr << "matched" << endl;