00001
00002 #include <mime/decode.h>
00003
00004 #include <iostream>
00005
00006 #include <stdexcept>
00007
00008 using namespace std;
00009
00010 class my_decoder : public mime::decoder {
00011 public:
00012 my_decoder() {}
00013 virtual void object_created(mime::object* object);
00014 virtual void data_start(mime::object* obj);
00015 virtual void data(mime::object* obj, unsigned char *data,
00016 int len);
00017 virtual void data_end(mime::object* obj);
00018 };
00019
00020 void my_decoder::object_created(mime::object* object)
00021 {
00022
00023 cerr << "*** New object type "
00024 << object->type << "/" << object->subtype
00025 << endl;
00026
00027 map<string,mime::field>::iterator i;
00028 for(i = object->fields.begin();
00029 i != object->fields.end();
00030 i++) {
00031 cerr << " " << i->first << ":" << i->second.value << endl;
00032 map<string,string>::iterator j;
00033 for(j = i->second.attributes.begin();
00034 j != i->second.attributes.end();
00035 j++) {
00036 cerr << " " << j->first << ":" << j->second << endl;
00037 }
00038 }
00039
00040 }
00041
00042 void my_decoder::data_start(mime::object* object)
00043 {
00044 cerr << "*** Data start "
00045 << object->type << "/" << object->subtype
00046 << endl;
00047 }
00048
00049 void my_decoder::data(mime::object* object, unsigned char *data, int len)
00050 {
00051
00052 for(int i = 0; i < len; i++)
00053 cerr << data[i];
00054 }
00055
00056 void my_decoder::data_end(mime::object* object)
00057 {
00058 cerr << "*** Data end "
00059 << object->type << "/" << object->subtype
00060 << endl;
00061 }
00062
00063 int main(int argc, char **argv)
00064 {
00065
00066 try {
00067
00068 my_decoder d;
00069
00070 while (cin.good()) {
00071 unsigned char c = cin.get();
00072 if (cin.good())
00073 d.decode(c);
00074 }
00075
00076 d.close();
00077
00078 } catch (exception& e) {
00079 cerr << "Exception: " << e.what() << endl;
00080 }
00081
00082 }
00083