Update libmu_cpp.
* libmu_cpp/filter.cc, include/mailutils/cpp/filter.h, include/mailutils/cpp/stream.h: Split FilterStream. * libmu_cpp/mailbox.cc, include/mailutils/cpp/mailbox.h: Add new methods. * examples/cpp/iconv.cc: Reflect changes in filter.h. * examples/cpp/mimetest.cc: Likewise. * examples/cpp/http.cc: Bugfix.
Showing
9 changed files
with
81 additions
and
30 deletions
... | @@ -28,16 +28,19 @@ | ... | @@ -28,16 +28,19 @@ |
28 | using namespace std; | 28 | using namespace std; |
29 | using namespace mailutils; | 29 | using namespace mailutils; |
30 | 30 | ||
31 | string wbuf = "GET / HTTP/1.0\r\n\r\n"; | ||
32 | string rbuf; | ||
33 | |||
34 | int | 31 | int |
35 | main () | 32 | main (int argc, char **argv) |
36 | { | 33 | { |
37 | int off = 0; | 34 | int off = 0; |
38 | 35 | string host; | |
36 | |||
37 | if (argc == 1) | ||
38 | host = "www.gnu.org"; | ||
39 | else | ||
40 | host = argv[1]; | ||
41 | |||
39 | try { | 42 | try { |
40 | TcpStream stream ("www.gnu.org", 80, MU_STREAM_NONBLOCK); | 43 | TcpStream stream (host, 80, MU_STREAM_NONBLOCK); |
41 | 44 | ||
42 | connect_again: | 45 | connect_again: |
43 | try { | 46 | try { |
... | @@ -47,11 +50,13 @@ main () | ... | @@ -47,11 +50,13 @@ main () |
47 | stream.wait (MU_STREAM_READY_WR); | 50 | stream.wait (MU_STREAM_READY_WR); |
48 | goto connect_again; | 51 | goto connect_again; |
49 | } | 52 | } |
50 | 53 | ||
54 | string path = argc == 3 ? argv[2] : "/"; | ||
55 | string wbuf = "GET " + path + " HTTP/1.0\r\n\r\n"; | ||
56 | |||
51 | write_again: | 57 | write_again: |
52 | try { | 58 | try { |
53 | string wbuf (wbuf, off, wbuf.length ()); | 59 | stream << wbuf.substr (off); |
54 | stream << wbuf; | ||
55 | } | 60 | } |
56 | catch (Stream::EAgain) { | 61 | catch (Stream::EAgain) { |
57 | stream.wait (MU_STREAM_READY_WR); | 62 | stream.wait (MU_STREAM_READY_WR); |
... | @@ -65,6 +70,7 @@ main () | ... | @@ -65,6 +70,7 @@ main () |
65 | exit (1); | 70 | exit (1); |
66 | } | 71 | } |
67 | 72 | ||
73 | string rbuf; | ||
68 | read_again: | 74 | read_again: |
69 | do | 75 | do |
70 | { | 76 | { | ... | ... |
... | @@ -40,9 +40,8 @@ main (int argc, char **argv) | ... | @@ -40,9 +40,8 @@ main (int argc, char **argv) |
40 | StdioStream *in = new StdioStream (stdin, 0); | 40 | StdioStream *in = new StdioStream (stdin, 0); |
41 | in->open (); | 41 | in->open (); |
42 | 42 | ||
43 | FilterStream cvt; | 43 | FilterIconvStream cvt (*in, (string)argv[1], (string)argv[2], 0, |
44 | cvt.iconv_create (*in, (string)argv[1], (string)argv[2], 0, | 44 | mu_fallback_none); |
45 | mu_fallback_none); | ||
46 | cvt.open (); | 45 | cvt.open (); |
47 | delete in; | 46 | delete in; |
48 | 47 | ... | ... |
... | @@ -188,8 +188,7 @@ message_display_parts (Message& msg, int indent) | ... | @@ -188,8 +188,7 @@ message_display_parts (Message& msg, int indent) |
188 | Body body = part.get_body (); | 188 | Body body = part.get_body (); |
189 | Stream stream = body.get_stream (); | 189 | Stream stream = body.get_stream (); |
190 | 190 | ||
191 | FilterStream filter; | 191 | FilterStream filter (stream, encoding, 0, 0); |
192 | filter.create (stream, encoding, 0, 0); | ||
193 | int offset = 0; | 192 | int offset = 0; |
194 | char buf[2048]; | 193 | char buf[2048]; |
195 | 194 | ... | ... |
... | @@ -33,10 +33,17 @@ class FilterStream : public Stream | ... | @@ -33,10 +33,17 @@ class FilterStream : public Stream |
33 | Stream *input; | 33 | Stream *input; |
34 | 34 | ||
35 | public: | 35 | public: |
36 | void create (Stream& transport, const std::string& code, int mode, | 36 | FilterStream (Stream& transport, const std::string& code, |
37 | int flag); | 37 | int mode, int flag); |
38 | }; | ||
39 | |||
40 | class FilterIconvStream : public Stream | ||
41 | { | ||
42 | private: | ||
43 | Stream *input; | ||
38 | 44 | ||
39 | void iconv_create (Stream& transport, | 45 | public: |
46 | FilterIconvStream (Stream& transport, | ||
40 | const std::string& fromcode, | 47 | const std::string& fromcode, |
41 | const std::string& tocode, | 48 | const std::string& tocode, |
42 | int flags, | 49 | int flags, | ... | ... |
... | @@ -41,7 +41,11 @@ class MailboxBase | ... | @@ -41,7 +41,11 @@ class MailboxBase |
41 | Debug& get_debug (); | 41 | Debug& get_debug (); |
42 | 42 | ||
43 | size_t messages_count (); | 43 | size_t messages_count (); |
44 | size_t messages_recent (); | ||
45 | size_t message_unseen (); | ||
44 | Message& get_message (size_t num); | 46 | Message& get_message (size_t num); |
47 | void append_message (const Message& msg); | ||
48 | void expunge (); | ||
45 | 49 | ||
46 | inline Message& operator [] (size_t num) { | 50 | inline Message& operator [] (size_t num) { |
47 | return this->get_message (num); | 51 | return this->get_message (num); | ... | ... |
... | @@ -49,6 +49,7 @@ class Stream | ... | @@ -49,6 +49,7 @@ class Stream |
49 | // Friends | 49 | // Friends |
50 | friend class FilterStream; | 50 | friend class FilterStream; |
51 | friend class FilterProgStream; | 51 | friend class FilterProgStream; |
52 | friend class FilterIconvStream; | ||
52 | friend class Folder; | 53 | friend class Folder; |
53 | friend class Mailcap; | 54 | friend class Mailcap; |
54 | friend class Message; | 55 | friend class Message; | ... | ... |
... | @@ -26,33 +26,35 @@ using namespace mailutils; | ... | @@ -26,33 +26,35 @@ using namespace mailutils; |
26 | // FilterStream | 26 | // FilterStream |
27 | // | 27 | // |
28 | 28 | ||
29 | void | 29 | FilterStream :: FilterStream (Stream& transport, |
30 | FilterStream :: create (Stream& transport, | 30 | const std::string& code, |
31 | const std::string& code, | 31 | int mode, int flag) |
32 | int mode, int flag) | ||
33 | { | 32 | { |
34 | int status = mu_filter_create (&this->stm, | 33 | int status = mu_filter_create (&this->stm, |
35 | transport.stm, | 34 | transport.stm, |
36 | code.c_str (), | 35 | code.c_str (), |
37 | mode, flag); | 36 | mode, flag); |
38 | if (status) | 37 | if (status) |
39 | throw Exception ("FilterStream::create", status); | 38 | throw Exception ("FilterStream::FilterStream", status); |
40 | this->input = new Stream (transport); | 39 | this->input = new Stream (transport); |
41 | } | 40 | } |
42 | 41 | ||
43 | void | 42 | // |
44 | FilterStream :: iconv_create (Stream& transport, | 43 | // FilterIconvStream |
45 | const std::string& fromcode, | 44 | // |
46 | const std::string& tocode, | 45 | |
47 | int flags, | 46 | FilterIconvStream :: FilterIconvStream (Stream& transport, |
48 | enum mu_iconv_fallback_mode fallback_mode) | 47 | const std::string& fromcode, |
48 | const std::string& tocode, | ||
49 | int flags, | ||
50 | enum mu_iconv_fallback_mode fm) | ||
49 | { | 51 | { |
50 | int status = mu_filter_iconv_create (&this->stm, transport.stm, | 52 | int status = mu_filter_iconv_create (&this->stm, transport.stm, |
51 | fromcode.c_str (), | 53 | fromcode.c_str (), |
52 | tocode.c_str (), | 54 | tocode.c_str (), |
53 | flags, fallback_mode); | 55 | flags, fm); |
54 | if (status) | 56 | if (status) |
55 | throw Exception ("FilterStream::iconv_create", status); | 57 | throw Exception ("FilterIconvStream::FilterIconvStream", status); |
56 | this->input = new Stream (transport); | 58 | this->input = new Stream (transport); |
57 | } | 59 | } |
58 | 60 | ... | ... |
... | @@ -72,6 +72,22 @@ MailboxBase :: messages_count () | ... | @@ -72,6 +72,22 @@ MailboxBase :: messages_count () |
72 | return total; | 72 | return total; |
73 | } | 73 | } |
74 | 74 | ||
75 | size_t | ||
76 | MailboxBase :: messages_recent () | ||
77 | { | ||
78 | size_t recent; | ||
79 | mu_mailbox_messages_recent (mbox, &recent); | ||
80 | return recent; | ||
81 | } | ||
82 | |||
83 | size_t | ||
84 | MailboxBase :: message_unseen () | ||
85 | { | ||
86 | size_t unseen; | ||
87 | mu_mailbox_message_unseen (mbox, &unseen); | ||
88 | return unseen; | ||
89 | } | ||
90 | |||
75 | Message& | 91 | Message& |
76 | MailboxBase :: get_message (size_t num) | 92 | MailboxBase :: get_message (size_t num) |
77 | { | 93 | { |
... | @@ -84,6 +100,22 @@ MailboxBase :: get_message (size_t num) | ... | @@ -84,6 +100,22 @@ MailboxBase :: get_message (size_t num) |
84 | return *new Message (c_msg); | 100 | return *new Message (c_msg); |
85 | } | 101 | } |
86 | 102 | ||
103 | void | ||
104 | MailboxBase :: append_message (const Message& msg) | ||
105 | { | ||
106 | int status = mu_mailbox_append_message (mbox, msg.msg); | ||
107 | if (status) | ||
108 | throw Exception ("MailboxBase::append_message", status); | ||
109 | } | ||
110 | |||
111 | void | ||
112 | MailboxBase :: expunge () | ||
113 | { | ||
114 | int status = mu_mailbox_expunge (mbox); | ||
115 | if (status) | ||
116 | throw Exception ("MailboxBase::expunge", status); | ||
117 | } | ||
118 | |||
87 | // | 119 | // |
88 | // Mailbox | 120 | // Mailbox |
89 | // | 121 | // | ... | ... |
-
Please register or sign in to post a comment