Commit 234b002d 234b002dc8b0842ee750577faa0dec82b8857228 by Wojciech Polak

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.
1 parent 5b3ac30a
......@@ -28,16 +28,19 @@
using namespace std;
using namespace mailutils;
string wbuf = "GET / HTTP/1.0\r\n\r\n";
string rbuf;
int
main ()
main (int argc, char **argv)
{
int off = 0;
string host;
if (argc == 1)
host = "www.gnu.org";
else
host = argv[1];
try {
TcpStream stream ("www.gnu.org", 80, MU_STREAM_NONBLOCK);
TcpStream stream (host, 80, MU_STREAM_NONBLOCK);
connect_again:
try {
......@@ -47,11 +50,13 @@ main ()
stream.wait (MU_STREAM_READY_WR);
goto connect_again;
}
string path = argc == 3 ? argv[2] : "/";
string wbuf = "GET " + path + " HTTP/1.0\r\n\r\n";
write_again:
try {
string wbuf (wbuf, off, wbuf.length ());
stream << wbuf;
stream << wbuf.substr (off);
}
catch (Stream::EAgain) {
stream.wait (MU_STREAM_READY_WR);
......@@ -65,6 +70,7 @@ main ()
exit (1);
}
string rbuf;
read_again:
do
{
......
......@@ -40,9 +40,8 @@ main (int argc, char **argv)
StdioStream *in = new StdioStream (stdin, 0);
in->open ();
FilterStream cvt;
cvt.iconv_create (*in, (string)argv[1], (string)argv[2], 0,
mu_fallback_none);
FilterIconvStream cvt (*in, (string)argv[1], (string)argv[2], 0,
mu_fallback_none);
cvt.open ();
delete in;
......
......@@ -188,8 +188,7 @@ message_display_parts (Message& msg, int indent)
Body body = part.get_body ();
Stream stream = body.get_stream ();
FilterStream filter;
filter.create (stream, encoding, 0, 0);
FilterStream filter (stream, encoding, 0, 0);
int offset = 0;
char buf[2048];
......
......@@ -33,10 +33,17 @@ class FilterStream : public Stream
Stream *input;
public:
void create (Stream& transport, const std::string& code, int mode,
int flag);
FilterStream (Stream& transport, const std::string& code,
int mode, int flag);
};
class FilterIconvStream : public Stream
{
private:
Stream *input;
void iconv_create (Stream& transport,
public:
FilterIconvStream (Stream& transport,
const std::string& fromcode,
const std::string& tocode,
int flags,
......
......@@ -41,7 +41,11 @@ class MailboxBase
Debug& get_debug ();
size_t messages_count ();
size_t messages_recent ();
size_t message_unseen ();
Message& get_message (size_t num);
void append_message (const Message& msg);
void expunge ();
inline Message& operator [] (size_t num) {
return this->get_message (num);
......
......@@ -35,6 +35,7 @@ class Message
mu_message_t msg;
bool owner;
friend class MailboxBase;
friend class Mailer;
friend class Mime;
......
......@@ -49,6 +49,7 @@ class Stream
// Friends
friend class FilterStream;
friend class FilterProgStream;
friend class FilterIconvStream;
friend class Folder;
friend class Mailcap;
friend class Message;
......
......@@ -26,33 +26,35 @@ using namespace mailutils;
// FilterStream
//
void
FilterStream :: create (Stream& transport,
const std::string& code,
int mode, int flag)
FilterStream :: FilterStream (Stream& transport,
const std::string& code,
int mode, int flag)
{
int status = mu_filter_create (&this->stm,
transport.stm,
code.c_str (),
mode, flag);
if (status)
throw Exception ("FilterStream::create", status);
throw Exception ("FilterStream::FilterStream", status);
this->input = new Stream (transport);
}
void
FilterStream :: iconv_create (Stream& transport,
const std::string& fromcode,
const std::string& tocode,
int flags,
enum mu_iconv_fallback_mode fallback_mode)
//
// FilterIconvStream
//
FilterIconvStream :: FilterIconvStream (Stream& transport,
const std::string& fromcode,
const std::string& tocode,
int flags,
enum mu_iconv_fallback_mode fm)
{
int status = mu_filter_iconv_create (&this->stm, transport.stm,
fromcode.c_str (),
tocode.c_str (),
flags, fallback_mode);
flags, fm);
if (status)
throw Exception ("FilterStream::iconv_create", status);
throw Exception ("FilterIconvStream::FilterIconvStream", status);
this->input = new Stream (transport);
}
......
......@@ -72,6 +72,22 @@ MailboxBase :: messages_count ()
return total;
}
size_t
MailboxBase :: messages_recent ()
{
size_t recent;
mu_mailbox_messages_recent (mbox, &recent);
return recent;
}
size_t
MailboxBase :: message_unseen ()
{
size_t unseen;
mu_mailbox_message_unseen (mbox, &unseen);
return unseen;
}
Message&
MailboxBase :: get_message (size_t num)
{
......@@ -84,6 +100,22 @@ MailboxBase :: get_message (size_t num)
return *new Message (c_msg);
}
void
MailboxBase :: append_message (const Message& msg)
{
int status = mu_mailbox_append_message (mbox, msg.msg);
if (status)
throw Exception ("MailboxBase::append_message", status);
}
void
MailboxBase :: expunge ()
{
int status = mu_mailbox_expunge (mbox);
if (status)
throw Exception ("MailboxBase::expunge", status);
}
//
// Mailbox
//
......