Commit b4b7a4a6 b4b7a4a68868d9943b9a4c946c1e0b21b2c3d49f by Wojciech Polak

Add Envelope class to libmu_cpp. Add new methods.

* include/mailutils/cpp/envelope.h, libmu_cpp/envelope.cc: New files.
1 parent 29b072f7
...@@ -33,7 +33,7 @@ parse (const char *str) ...@@ -33,7 +33,7 @@ parse (const char *str)
33 try { 33 try {
34 Address address (str); 34 Address address (str);
35 size_t count = address.get_count (); 35 size_t count = address.get_count ();
36 cout << str << "=> count " << count << endl; 36 cout << address << " => count " << count << endl;
37 37
38 for (size_t no = 1; no <= count; no++) 38 for (size_t no = 1; no <= count; no++)
39 { 39 {
...@@ -41,17 +41,17 @@ parse (const char *str) ...@@ -41,17 +41,17 @@ parse (const char *str)
41 cout << no << " "; 41 cout << no << " ";
42 42
43 if (isgroup) 43 if (isgroup)
44 cout << "group " << address.get_personal (no) << endl; 44 cout << "group <" << address.get_personal (no) << ">" << endl;
45 else 45 else
46 cout << "email " << address.get_email (no) << endl; 46 cout << "email <" << address.get_email (no) << ">" << endl;
47 47
48 if (!isgroup) 48 if (!isgroup)
49 cout << " personal " << address.get_personal (no) << endl; 49 cout << " personal <" << address.get_personal (no) << ">" << endl;
50 50
51 cout << " comments " << address.get_comments (no) << endl; 51 cout << " comments <" << address.get_comments (no) << ">" << endl;
52 cout << " local-part " << address.get_local_part (no) 52 cout << " local-part <" << address.get_local_part (no) << ">"
53 << " domain " << address.get_domain (no) << endl; 53 << " domain <" << address.get_domain (no) << ">" << endl;
54 cout << " route " << address.get_route (no) << endl; 54 cout << " route <" << address.get_route (no) << ">" << endl;
55 } 55 }
56 } 56 }
57 catch (Exception& e) { 57 catch (Exception& e) {
......
...@@ -127,8 +127,6 @@ print_message_part_sizes (Message& part, int indent) ...@@ -127,8 +127,6 @@ print_message_part_sizes (Message& part, int indent)
127 void 127 void
128 message_display_parts (Message& msg, int indent) 128 message_display_parts (Message& msg, int indent)
129 { 129 {
130 size_t nbytes;
131
132 /* How many parts does the message has? */ 130 /* How many parts does the message has? */
133 size_t nparts = msg.get_num_parts (); 131 size_t nparts = msg.get_num_parts ();
134 132
...@@ -140,8 +138,8 @@ message_display_parts (Message& msg, int indent) ...@@ -140,8 +138,8 @@ message_display_parts (Message& msg, int indent)
140 Message part = msg.get_part (j); 138 Message part = msg.get_part (j);
141 Header hdr = part.get_header (); 139 Header hdr = part.get_header ();
142 140
143 string type; 141 string type ("text/plain");
144 string encoding (""); 142 string encoding ("7bit");
145 try { 143 try {
146 type = hdr[MU_HEADER_CONTENT_TYPE]; 144 type = hdr[MU_HEADER_CONTENT_TYPE];
147 encoding = hdr[MU_HEADER_CONTENT_TRANSFER_ENCODING]; 145 encoding = hdr[MU_HEADER_CONTENT_TRANSFER_ENCODING];
......
...@@ -26,13 +26,10 @@ using namespace mailutils; ...@@ -26,13 +26,10 @@ using namespace mailutils;
26 26
27 int main (int argc, char* argv[]) 27 int main (int argc, char* argv[])
28 { 28 {
29 if (argc == 1)
30 exit (0);
31
32 register_local_mbox_formats (); 29 register_local_mbox_formats ();
33 30
34 try { 31 try {
35 MailboxDefault mbox (argv[1]); 32 MailboxDefault mbox ((argc > 1) ? argv[1] : "");
36 mbox.open (); 33 mbox.open ();
37 34
38 size_t total = mbox.messages_count (); 35 size_t total = mbox.messages_count ();
...@@ -43,7 +40,7 @@ int main (int argc, char* argv[]) ...@@ -43,7 +40,7 @@ int main (int argc, char* argv[])
43 Message msg = mbox[msgno]; 40 Message msg = mbox[msgno];
44 Header hdr = msg.get_header (); 41 Header hdr = msg.get_header ();
45 cout << hdr[MU_HEADER_FROM] << " " 42 cout << hdr[MU_HEADER_FROM] << " "
46 << hdr.get_value (MU_HEADER_SUBJECT, "[none]") << endl; 43 << hdr.get_value (MU_HEADER_SUBJECT, "(NO SUBJECT)") << endl;
47 } 44 }
48 45
49 mbox.close (); 46 mbox.close ();
......
...@@ -21,6 +21,7 @@ MU_CXX_INCLUDES = \ ...@@ -21,6 +21,7 @@ MU_CXX_INCLUDES = \
21 attribute.h\ 21 attribute.h\
22 body.h\ 22 body.h\
23 debug.h\ 23 debug.h\
24 envelope.h\
24 error.h\ 25 error.h\
25 filter.h\ 26 filter.h\
26 folder.h\ 27 folder.h\
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
21 #ifndef _ADDRESS_H 21 #ifndef _ADDRESS_H
22 #define _ADDRESS_H 22 #define _ADDRESS_H
23 23
24 #include <ostream>
25 #include <errno.h>
24 #include <mailutils/address.h> 26 #include <mailutils/address.h>
25 #include <mailutils/cpp/error.h> 27 #include <mailutils/cpp/error.h>
26 28
...@@ -29,9 +31,6 @@ namespace mailutils ...@@ -29,9 +31,6 @@ namespace mailutils
29 31
30 class Address 32 class Address
31 { 33 {
32 private:
33 char buf[256];
34
35 protected: 34 protected:
36 mu_address_t addr; 35 mu_address_t addr;
37 36
...@@ -56,6 +55,9 @@ class Address ...@@ -56,6 +55,9 @@ class Address
56 std::string get_comments (size_t n); 55 std::string get_comments (size_t n);
57 std::string get_route (size_t n); 56 std::string get_route (size_t n);
58 57
58 std::string to_string ();
59 friend std::ostream& operator << (std::ostream&, Address&);
60
59 // Address Exceptions 61 // Address Exceptions
60 class EInval : public Exception { 62 class EInval : public Exception {
61 public: 63 public:
......
...@@ -21,7 +21,10 @@ ...@@ -21,7 +21,10 @@
21 #ifndef _MUCPP_ATTRIBUTE_H 21 #ifndef _MUCPP_ATTRIBUTE_H
22 #define _MUCPP_ATTRIBUTE_H 22 #define _MUCPP_ATTRIBUTE_H
23 23
24 #include <ostream>
25 #include <errno.h>
24 #include <mailutils/attribute.h> 26 #include <mailutils/attribute.h>
27 #include <mailutils/cpp/error.h>
25 28
26 namespace mailutils 29 namespace mailutils
27 { 30 {
...@@ -65,6 +68,9 @@ class Attribute ...@@ -65,6 +68,9 @@ class Attribute
65 void unset_draft (); 68 void unset_draft ();
66 void unset_recent (); 69 void unset_recent ();
67 void unset_read (); 70 void unset_read ();
71
72 std::string to_string ();
73 friend std::ostream& operator << (std::ostream&, Attribute&);
68 }; 74 };
69 75
70 } 76 }
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
22 #define _MUCPP_BODY_H 22 #define _MUCPP_BODY_H
23 23
24 #include <string> 24 #include <string>
25 #include <errno.h>
25 #include <mailutils/body.h> 26 #include <mailutils/body.h>
27 #include <mailutils/cpp/error.h>
26 #include <mailutils/cpp/stream.h> 28 #include <mailutils/cpp/stream.h>
27 29
28 namespace mailutils 30 namespace mailutils
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
22 #define _MUCPP_DEBUG_H 22 #define _MUCPP_DEBUG_H
23 23
24 #include <string> 24 #include <string>
25 #include <errno.h>
25 #include <mailutils/debug.h> 26 #include <mailutils/debug.h>
27 #include <mailutils/cpp/error.h>
26 28
27 namespace mailutils 29 namespace mailutils
28 { 30 {
......
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _MUCPP_ENVELOPE_H
22 #define _MUCPP_ENVELOPE_H
23
24 #include <string>
25 #include <errno.h>
26 #include <mailutils/envelope.h>
27 #include <mailutils/cpp/error.h>
28
29 namespace mailutils
30 {
31
32 class Envelope
33 {
34 protected:
35 mu_envelope_t env;
36
37 public:
38 Envelope ();
39 Envelope (const mu_envelope_t);
40
41 std::string get_sender ();
42 std::string get_date ();
43 };
44
45 }
46
47 #endif // not _MUCPP_ENVELOPE_H
48
...@@ -21,9 +21,12 @@ ...@@ -21,9 +21,12 @@
21 #ifndef _MUCPP_FOLDER_H 21 #ifndef _MUCPP_FOLDER_H
22 #define _MUCPP_FOLDER_H 22 #define _MUCPP_FOLDER_H
23 23
24 #include <errno.h>
24 #include <mailutils/folder.h> 25 #include <mailutils/folder.h>
26 #include <mailutils/cpp/error.h>
25 #include <mailutils/cpp/list.h> 27 #include <mailutils/cpp/list.h>
26 #include <mailutils/cpp/stream.h> 28 #include <mailutils/cpp/stream.h>
29 #include <mailutils/cpp/url.h>
27 30
28 namespace mailutils 31 namespace mailutils
29 { 32 {
...@@ -50,6 +53,8 @@ class Folder ...@@ -50,6 +53,8 @@ class Folder
50 53
51 Stream& get_stream (); 54 Stream& get_stream ();
52 void set_stream (const Stream& stream); 55 void set_stream (const Stream& stream);
56
57 Url& get_url ();
53 }; 58 };
54 59
55 } 60 }
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
22 #define _MUCPP_HEADER_H 22 #define _MUCPP_HEADER_H
23 23
24 #include <string> 24 #include <string>
25 #include <errno.h>
25 #include <mailutils/header.h> 26 #include <mailutils/header.h>
27 #include <mailutils/cpp/error.h>
26 28
27 namespace mailutils 29 namespace mailutils
28 { 30 {
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
21 #ifndef _MUCPP_ITERATOR_H 21 #ifndef _MUCPP_ITERATOR_H
22 #define _MUCPP_ITERATOR_H 22 #define _MUCPP_ITERATOR_H
23 23
24 #include <errno.h>
24 #include <mailutils/iterator.h> 25 #include <mailutils/iterator.h>
26 #include <mailutils/cpp/error.h>
25 #include <mailutils/cpp/list.h> 27 #include <mailutils/cpp/list.h>
26 28
27 namespace mailutils 29 namespace mailutils
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
21 #ifndef _MUCPP_LIST_H 21 #ifndef _MUCPP_LIST_H
22 #define _MUCPP_LIST_H 22 #define _MUCPP_LIST_H
23 23
24 #include <errno.h>
24 #include <mailutils/list.h> 25 #include <mailutils/list.h>
26 #include <mailutils/cpp/error.h>
25 #include <mailutils/cpp/iterator.h> 27 #include <mailutils/cpp/iterator.h>
26 28
27 typedef int mu_list_action_t (void*, void*); 29 typedef int mu_list_action_t (void*, void*);
......
...@@ -21,9 +21,13 @@ ...@@ -21,9 +21,13 @@
21 #ifndef _MUCPP_MAILBOX_H 21 #ifndef _MUCPP_MAILBOX_H
22 #define _MUCPP_MAILBOX_H 22 #define _MUCPP_MAILBOX_H
23 23
24 #include <errno.h>
24 #include <mailutils/mailbox.h> 25 #include <mailutils/mailbox.h>
26 #include <mailutils/cpp/error.h>
25 #include <mailutils/cpp/debug.h> 27 #include <mailutils/cpp/debug.h>
28 #include <mailutils/cpp/folder.h>
26 #include <mailutils/cpp/message.h> 29 #include <mailutils/cpp/message.h>
30 #include <mailutils/cpp/url.h>
27 31
28 namespace mailutils 32 namespace mailutils
29 { 33 {
...@@ -37,15 +41,21 @@ class MailboxBase ...@@ -37,15 +41,21 @@ class MailboxBase
37 void open (); 41 void open ();
38 void open (int flag); 42 void open (int flag);
39 void close (); 43 void close ();
40 44 void flush (bool expunge);
41 Debug& get_debug ();
42
43 size_t messages_count (); 45 size_t messages_count ();
44 size_t messages_recent (); 46 size_t messages_recent ();
45 size_t message_unseen (); 47 size_t message_unseen ();
46 Message& get_message (size_t num); 48 Message& get_message (size_t num);
47 void append_message (const Message& msg); 49 void append_message (const Message& msg);
48 void expunge (); 50 void expunge ();
51 void sync ();
52 void lock ();
53 void unlock ();
54 mu_off_t get_size ();
55
56 Debug& get_debug ();
57 Folder& get_folder ();
58 Url& get_url ();
49 59
50 inline Message& operator [] (size_t num) { 60 inline Message& operator [] (size_t num) {
51 return this->get_message (num); 61 return this->get_message (num);
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
21 #ifndef _MUCPP_MAILCAP_H 21 #ifndef _MUCPP_MAILCAP_H
22 #define _MUCPP_MAILCAP_H 22 #define _MUCPP_MAILCAP_H
23 23
24 #include <errno.h>
24 #include <mailutils/mailcap.h> 25 #include <mailutils/mailcap.h>
26 #include <mailutils/cpp/error.h>
25 #include <mailutils/cpp/stream.h> 27 #include <mailutils/cpp/stream.h>
26 28
27 namespace mailutils 29 namespace mailutils
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
22 #define _MUCPP_MAILER_H 22 #define _MUCPP_MAILER_H
23 23
24 #include <string> 24 #include <string>
25 #include <errno.h>
25 #include <mailutils/mailer.h> 26 #include <mailutils/mailer.h>
26 #include <mailutils/cpp/debug.h> 27 #include <mailutils/cpp/debug.h>
27 #include <mailutils/cpp/message.h> 28 #include <mailutils/cpp/message.h>
......
...@@ -21,9 +21,13 @@ ...@@ -21,9 +21,13 @@
21 #ifndef _MUCPP_MESSAGE_H 21 #ifndef _MUCPP_MESSAGE_H
22 #define _MUCPP_MESSAGE_H 22 #define _MUCPP_MESSAGE_H
23 23
24 #include <errno.h>
24 #include <mailutils/message.h> 25 #include <mailutils/message.h>
25 #include <mailutils/cpp/header.h> 26 #include <mailutils/cpp/error.h>
27 #include <mailutils/cpp/attribute.h>
26 #include <mailutils/cpp/body.h> 28 #include <mailutils/cpp/body.h>
29 #include <mailutils/cpp/envelope.h>
30 #include <mailutils/cpp/header.h>
27 #include <mailutils/cpp/stream.h> 31 #include <mailutils/cpp/stream.h>
28 32
29 namespace mailutils 33 namespace mailutils
...@@ -45,8 +49,10 @@ class Message ...@@ -45,8 +49,10 @@ class Message
45 Message& operator = (const Message&); 49 Message& operator = (const Message&);
46 ~Message (); 50 ~Message ();
47 51
48 Header& get_header (); 52 Attribute& get_attribute ();
49 Body& get_body (); 53 Body& get_body ();
54 Envelope& get_envelope ();
55 Header& get_header ();
50 Stream& get_stream (); 56 Stream& get_stream ();
51 void set_stream (const Stream& stream); 57 void set_stream (const Stream& stream);
52 58
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
22 #define _MUCPP_MIME_H 22 #define _MUCPP_MIME_H
23 23
24 #include <string> 24 #include <string>
25 #include <errno.h>
25 #include <mailutils/mime.h> 26 #include <mailutils/mime.h>
27 #include <mailutils/cpp/error.h>
26 #include <mailutils/cpp/message.h> 28 #include <mailutils/cpp/message.h>
27 29
28 namespace mailutils 30 namespace mailutils
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
21 #ifndef _MUCPP_POP3_H 21 #ifndef _MUCPP_POP3_H
22 #define _MUCPP_POP3_H 22 #define _MUCPP_POP3_H
23 23
24 #include <errno.h>
24 #include <mailutils/pop3.h> 25 #include <mailutils/pop3.h>
25 #include <mailutils/cpp/list.h> 26 #include <mailutils/cpp/list.h>
26 #include <mailutils/cpp/iterator.h> 27 #include <mailutils/cpp/iterator.h>
......
...@@ -21,7 +21,10 @@ ...@@ -21,7 +21,10 @@
21 #ifndef _MUCPP_REGISTRAR_H 21 #ifndef _MUCPP_REGISTRAR_H
22 #define _MUCPP_REGISTRAR_H 22 #define _MUCPP_REGISTRAR_H
23 23
24 #include <string>
25 #include <errno.h>
24 #include <mailutils/registrar.h> 26 #include <mailutils/registrar.h>
27 #include <mailutils/cpp/error.h>
25 #include <mailutils/cpp/url.h> 28 #include <mailutils/cpp/url.h>
26 29
27 namespace mailutils 30 namespace mailutils
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
22 #define _MUCPP_STREAM_H 22 #define _MUCPP_STREAM_H
23 23
24 #include <string> 24 #include <string>
25 #include <errno.h>
25 #include <mailutils/stream.h> 26 #include <mailutils/stream.h>
26 #include <mailutils/cpp/error.h> 27 #include <mailutils/cpp/error.h>
27 28
......
...@@ -23,16 +23,16 @@ ...@@ -23,16 +23,16 @@
23 23
24 #include <string> 24 #include <string>
25 #include <vector> 25 #include <vector>
26 #include <ostream>
27 #include <errno.h>
26 #include <mailutils/url.h> 28 #include <mailutils/url.h>
29 #include <mailutils/cpp/error.h>
27 30
28 namespace mailutils 31 namespace mailutils
29 { 32 {
30 33
31 class Url 34 class Url
32 { 35 {
33 private:
34 char buf[1024];
35
36 protected: 36 protected:
37 mu_url_t url; 37 mu_url_t url;
38 38
...@@ -51,6 +51,9 @@ class Url ...@@ -51,6 +51,9 @@ class Url
51 std::string get_host (); 51 std::string get_host ();
52 std::string get_path (); 52 std::string get_path ();
53 std::vector<std::string> get_query (); 53 std::vector<std::string> get_query ();
54
55 std::string to_string ();
56 friend std::ostream& operator << (std::ostream&, Url&);
54 }; 57 };
55 58
56 } 59 }
......
...@@ -28,6 +28,7 @@ libmu_cpp_la_SOURCES = \ ...@@ -28,6 +28,7 @@ libmu_cpp_la_SOURCES = \
28 attribute.cc\ 28 attribute.cc\
29 body.cc\ 29 body.cc\
30 debug.cc\ 30 debug.cc\
31 envelope.cc\
31 filter.cc\ 32 filter.cc\
32 folder.cc\ 33 folder.cc\
33 header.cc\ 34 header.cc\
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/address.h> 21 #include <mailutils/cpp/address.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
...@@ -97,72 +95,97 @@ Address :: get_count () ...@@ -97,72 +95,97 @@ Address :: get_count ()
97 std::string 95 std::string
98 Address :: get_email (size_t n) 96 Address :: get_email (size_t n)
99 { 97 {
100 int status = mu_address_get_email (addr, n, buf, sizeof (buf), 0); 98 char *buf = NULL;
99 int status = mu_address_aget_email (addr, n, &buf);
101 if (status == EINVAL) 100 if (status == EINVAL)
102 throw Address::EInval ("Address::get_email", status); 101 throw Address::EInval ("Address::get_email", status);
103 else if (status == ENOENT) 102 else if (status == ENOENT)
104 throw Address::ENoent ("Address::get_email", status); 103 throw Address::ENoent ("Address::get_email", status);
105 104
106 return std::string (buf); 105 return std::string (buf ? buf : "");
107 } 106 }
108 107
109 std::string 108 std::string
110 Address :: get_local_part (size_t n) 109 Address :: get_local_part (size_t n)
111 { 110 {
112 int status = mu_address_get_local_part (addr, n, buf, sizeof (buf), 0); 111 char *buf = NULL;
112 int status = mu_address_aget_local_part (addr, n, &buf);
113 if (status == EINVAL) 113 if (status == EINVAL)
114 throw Address::EInval ("Address::get_local_part", status); 114 throw Address::EInval ("Address::get_local_part", status);
115 else if (status == ENOENT) 115 else if (status == ENOENT)
116 throw Address::ENoent ("Address::get_local_part", status); 116 throw Address::ENoent ("Address::get_local_part", status);
117 117
118 return std::string (buf); 118 return std::string (buf ? buf : "");
119 } 119 }
120 120
121 std::string 121 std::string
122 Address :: get_domain (size_t n) 122 Address :: get_domain (size_t n)
123 { 123 {
124 int status = mu_address_get_domain (addr, n, buf, sizeof (buf), 0); 124 char *buf = NULL;
125 int status = mu_address_aget_domain (addr, n, &buf);
125 if (status == EINVAL) 126 if (status == EINVAL)
126 throw Address::EInval ("Address::get_domain", status); 127 throw Address::EInval ("Address::get_domain", status);
127 else if (status == ENOENT) 128 else if (status == ENOENT)
128 throw Address::ENoent ("Address::get_domain", status); 129 throw Address::ENoent ("Address::get_domain", status);
129 130
130 return std::string (buf); 131 return std::string (buf ? buf : "");
131 } 132 }
132 133
133 std::string 134 std::string
134 Address :: get_personal (size_t n) 135 Address :: get_personal (size_t n)
135 { 136 {
136 int status = mu_address_get_personal (addr, n, buf, sizeof (buf), 0); 137 char *buf = NULL;
138 int status = mu_address_aget_personal (addr, n, &buf);
137 if (status == EINVAL) 139 if (status == EINVAL)
138 throw Address::EInval ("Address::get_personal", status); 140 throw Address::EInval ("Address::get_personal", status);
139 else if (status == ENOENT) 141 else if (status == ENOENT)
140 throw Address::ENoent ("Address::get_personal", status); 142 throw Address::ENoent ("Address::get_personal", status);
141 143
142 return std::string (buf); 144 return std::string (buf ? buf : "");
143 } 145 }
144 146
145 std::string 147 std::string
146 Address :: get_comments (size_t n) 148 Address :: get_comments (size_t n)
147 { 149 {
148 int status = mu_address_get_comments (addr, n, buf, sizeof (buf), 0); 150 char *buf = NULL;
151 int status = mu_address_aget_comments (addr, n, &buf);
149 if (status == EINVAL) 152 if (status == EINVAL)
150 throw Address::EInval ("Address::get_comments", status); 153 throw Address::EInval ("Address::get_comments", status);
151 else if (status == ENOENT) 154 else if (status == ENOENT)
152 throw Address::ENoent ("Address::get_comments", status); 155 throw Address::ENoent ("Address::get_comments", status);
153 156
154 return std::string (buf); 157 return std::string (buf ? buf : "");
155 } 158 }
156 159
157 std::string 160 std::string
158 Address :: get_route (size_t n) 161 Address :: get_route (size_t n)
159 { 162 {
160 int status = mu_address_get_route (addr, n, buf, sizeof (buf), 0); 163 char *buf = NULL;
164 int status = mu_address_aget_route (addr, n, &buf);
161 if (status == EINVAL) 165 if (status == EINVAL)
162 throw Address::EInval ("Address::get_route", status); 166 throw Address::EInval ("Address::get_route", status);
163 else if (status == ENOENT) 167 else if (status == ENOENT)
164 throw Address::ENoent ("Address::get_route", status); 168 throw Address::ENoent ("Address::get_route", status);
165 169
170 return std::string (buf ? buf : "");
171 }
172
173 std::string
174 Address :: to_string ()
175 {
176 size_t n;
177 char buf[1024];
178 int status = mu_address_to_string (addr, buf, sizeof (buf), &n);
179 if (status)
180 throw Exception ("Address::to_string", status);
181
166 return std::string (buf); 182 return std::string (buf);
167 } 183 }
168 184
185 namespace mailutils
186 {
187 std::ostream& operator << (std::ostream& os, Address& addr) {
188 return os << addr.to_string ();
189 };
190 }
191
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/attribute.h> 21 #include <mailutils/cpp/attribute.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
...@@ -213,3 +211,19 @@ Attribute :: unset_read () ...@@ -213,3 +211,19 @@ Attribute :: unset_read ()
213 mu_attribute_unset_read (attr); 211 mu_attribute_unset_read (attr);
214 } 212 }
215 213
214 std::string
215 Attribute :: to_string ()
216 {
217 char buf[MU_STATUS_BUF_SIZE];
218 size_t na = 0;
219 mu_attribute_to_string (attr, buf, sizeof (buf), &na);
220 return std::string (buf);
221 }
222
223 namespace mailutils
224 {
225 std::ostream& operator << (std::ostream& os, Attribute& attr) {
226 return os << attr.to_string ();
227 };
228 }
229
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/body.h> 21 #include <mailutils/cpp/body.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/debug.h> 21 #include <mailutils/cpp/debug.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
......
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2009 Free Software Foundation, Inc.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General
16 Public License along with this library; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA
19 */
20
21 #include <mailutils/cpp/envelope.h>
22
23 using namespace mailutils;
24
25 //
26 // Envelope
27 //
28
29 Envelope :: Envelope ()
30 {
31 this->env = NULL;
32 }
33
34 Envelope :: Envelope (const mu_envelope_t env)
35 {
36 if (env == 0)
37 throw Exception ("Envelope::Envelope", EINVAL);
38
39 this->env = env;
40 }
41
42 std::string
43 Envelope :: get_sender ()
44 {
45 char* c_val = NULL;
46
47 int status = mu_envelope_aget_sender (env, &c_val);
48 if (status)
49 throw Exception ("Envelope::get_sender", status);
50
51 std::string val (c_val);
52 free (c_val);
53 return val;
54 }
55
56 std::string
57 Envelope :: get_date ()
58 {
59 char* c_val;
60
61 int status = mu_envelope_aget_date (env, &c_val);
62 if (status)
63 throw Exception ("Envelope::get_date", status);
64
65 std::string val (c_val);
66 free (c_val);
67 return val;
68 }
69
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/folder.h> 21 #include <mailutils/cpp/folder.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
...@@ -86,7 +84,8 @@ Folder :: close () ...@@ -86,7 +84,8 @@ Folder :: close ()
86 } 84 }
87 85
88 List& 86 List&
89 Folder :: list (const std::string& dirname, void* pattern, size_t max_level) 87 Folder :: list (const std::string& dirname, void* pattern,
88 size_t max_level = 0)
90 { 89 {
91 mu_list_t c_list; 90 mu_list_t c_list;
92 91
...@@ -134,3 +133,15 @@ Folder :: set_stream (const Stream& stream) ...@@ -134,3 +133,15 @@ Folder :: set_stream (const Stream& stream)
134 throw Exception ("Folder::set_stream", status); 133 throw Exception ("Folder::set_stream", status);
135 } 134 }
136 135
136 Url&
137 Folder :: get_url ()
138 {
139 mu_url_t c_url;
140
141 int status = mu_folder_get_url (folder, &c_url);
142 if (status)
143 throw Exception ("Folder::get_url", status);
144
145 return *new Url (c_url);
146 }
147
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/header.h> 21 #include <mailutils/cpp/header.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/iterator.h> 21 #include <mailutils/cpp/iterator.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/list.h> 21 #include <mailutils/cpp/list.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/mailbox.h> 21 #include <mailutils/cpp/mailbox.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
...@@ -52,23 +50,21 @@ MailboxBase :: close () ...@@ -52,23 +50,21 @@ MailboxBase :: close ()
52 throw Exception ("MailboxBase::close", status); 50 throw Exception ("MailboxBase::close", status);
53 } 51 }
54 52
55 Debug& 53 void
56 MailboxBase :: get_debug () 54 MailboxBase :: flush (bool expunge = false)
57 { 55 {
58 mu_debug_t c_dbg; 56 int status = mu_mailbox_flush (mbox, expunge);
59
60 int status = mu_mailbox_get_debug (mbox, &c_dbg);
61 if (status) 57 if (status)
62 throw Exception ("MailboxBase::get_debug", status); 58 throw Exception ("MailboxBase::flush", status);
63
64 return *new Debug (c_dbg);
65 } 59 }
66 60
67 size_t 61 size_t
68 MailboxBase :: messages_count () 62 MailboxBase :: messages_count ()
69 { 63 {
70 size_t total; 64 size_t total;
71 mu_mailbox_messages_count (mbox, &total); 65 int status = mu_mailbox_messages_count (mbox, &total);
66 if (status)
67 throw Exception ("MailboxBase::messages_count", status);
72 return total; 68 return total;
73 } 69 }
74 70
...@@ -76,7 +72,9 @@ size_t ...@@ -76,7 +72,9 @@ size_t
76 MailboxBase :: messages_recent () 72 MailboxBase :: messages_recent ()
77 { 73 {
78 size_t recent; 74 size_t recent;
79 mu_mailbox_messages_recent (mbox, &recent); 75 int status = mu_mailbox_messages_recent (mbox, &recent);
76 if (status)
77 throw Exception ("MailboxBase::messages_recent", status);
80 return recent; 78 return recent;
81 } 79 }
82 80
...@@ -84,7 +82,9 @@ size_t ...@@ -84,7 +82,9 @@ size_t
84 MailboxBase :: message_unseen () 82 MailboxBase :: message_unseen ()
85 { 83 {
86 size_t unseen; 84 size_t unseen;
87 mu_mailbox_message_unseen (mbox, &unseen); 85 int status = mu_mailbox_message_unseen (mbox, &unseen);
86 if (status)
87 throw Exception ("MailboxBase::message_unseen", status);
88 return unseen; 88 return unseen;
89 } 89 }
90 90
...@@ -116,6 +116,76 @@ MailboxBase :: expunge () ...@@ -116,6 +116,76 @@ MailboxBase :: expunge ()
116 throw Exception ("MailboxBase::expunge", status); 116 throw Exception ("MailboxBase::expunge", status);
117 } 117 }
118 118
119 void
120 MailboxBase :: sync ()
121 {
122 int status = mu_mailbox_sync (mbox);
123 if (status)
124 throw Exception ("MailboxBase::sync", status);
125 }
126
127 void
128 MailboxBase :: lock ()
129 {
130 int status = mu_mailbox_lock (mbox);
131 if (status)
132 throw Exception ("MailboxBase::lock", status);
133 }
134
135 void
136 MailboxBase :: unlock ()
137 {
138 int status = mu_mailbox_unlock (mbox);
139 if (status)
140 throw Exception ("MailboxBase::unlock", status);
141 }
142
143 mu_off_t
144 MailboxBase :: get_size ()
145 {
146 mu_off_t size;
147 int status = mu_mailbox_get_size (mbox, &size);
148 if (status)
149 throw Exception ("MailboxBase::get_size", status);
150 return size;
151 }
152
153 Debug&
154 MailboxBase :: get_debug ()
155 {
156 mu_debug_t c_dbg;
157
158 int status = mu_mailbox_get_debug (mbox, &c_dbg);
159 if (status)
160 throw Exception ("MailboxBase::get_debug", status);
161
162 return *new Debug (c_dbg);
163 }
164
165 Folder&
166 MailboxBase :: get_folder ()
167 {
168 mu_folder_t c_folder;
169
170 int status = mu_mailbox_get_folder (mbox, &c_folder);
171 if (status)
172 throw Exception ("MailboxBase::get_folder", status);
173
174 return *new Folder (c_folder);
175 }
176
177 Url&
178 MailboxBase :: get_url ()
179 {
180 mu_url_t c_url;
181
182 int status = mu_mailbox_get_url (mbox, &c_url);
183 if (status)
184 throw Exception ("MailboxBase::get_url", status);
185
186 return *new Url (c_url);
187 }
188
119 // 189 //
120 // Mailbox 190 // Mailbox
121 // 191 //
......
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/mailcap.h> 21 #include <mailutils/cpp/mailcap.h>
22 #include <mailutils/cpp/stream.h>
23 #include <mailutils/cpp/error.h>
24 #include <errno.h>
25 22
26 using namespace mailutils; 23 using namespace mailutils;
27 24
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/mailer.h> 21 #include <mailutils/cpp/mailer.h>
22 #include <errno.h>
23 22
24 using namespace mailutils; 23 using namespace mailutils;
25 24
......
...@@ -19,11 +19,6 @@ ...@@ -19,11 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/message.h> 21 #include <mailutils/cpp/message.h>
22 #include <mailutils/cpp/header.h>
23 #include <mailutils/cpp/body.h>
24 #include <mailutils/cpp/stream.h>
25 #include <mailutils/cpp/error.h>
26 #include <errno.h>
27 22
28 using namespace mailutils; 23 using namespace mailutils;
29 24
...@@ -72,16 +67,16 @@ Message :: ~Message () ...@@ -72,16 +67,16 @@ Message :: ~Message ()
72 mu_message_destroy (&msg, this); 67 mu_message_destroy (&msg, this);
73 } 68 }
74 69
75 Header& 70 Attribute&
76 Message :: get_header () 71 Message :: get_attribute ()
77 { 72 {
78 mu_header_t c_hdr; 73 mu_attribute_t c_attr;
79 74
80 int status = mu_message_get_header (msg, &c_hdr); 75 int status = mu_message_get_attribute (msg, &c_attr);
81 if (status) 76 if (status)
82 throw Exception ("Message::get_header", status); 77 throw Exception ("Message::get_attribute", status);
83 78
84 return *new Header (c_hdr); 79 return *new Attribute (c_attr);
85 } 80 }
86 81
87 Body& 82 Body&
...@@ -96,6 +91,30 @@ Message :: get_body () ...@@ -96,6 +91,30 @@ Message :: get_body ()
96 return *new Body (c_body); 91 return *new Body (c_body);
97 } 92 }
98 93
94 Envelope&
95 Message :: get_envelope ()
96 {
97 mu_envelope_t c_env;
98
99 int status = mu_message_get_envelope (msg, &c_env);
100 if (status)
101 throw Exception ("Message::get_envelope", status);
102
103 return *new Envelope (c_env);
104 }
105
106 Header&
107 Message :: get_header ()
108 {
109 mu_header_t c_hdr;
110
111 int status = mu_message_get_header (msg, &c_hdr);
112 if (status)
113 throw Exception ("Message::get_header", status);
114
115 return *new Header (c_hdr);
116 }
117
99 Stream& 118 Stream&
100 Message :: get_stream () 119 Message :: get_stream ()
101 { 120 {
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/mime.h> 21 #include <mailutils/cpp/mime.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
18 Boston, MA 02110-1301 USA 18 Boston, MA 02110-1301 USA
19 */ 19 */
20 20
21 #include <string>
22 #include <mailutils/cpp/mutil.h> 21 #include <mailutils/cpp/mutil.h>
23 22
24 using namespace mailutils; 23 using namespace mailutils;
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/pop3.h> 21 #include <mailutils/cpp/pop3.h>
22 #include <mailutils/cpp/iterator.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
......
...@@ -18,10 +18,7 @@ ...@@ -18,10 +18,7 @@
18 Boston, MA 02110-1301 USA 18 Boston, MA 02110-1301 USA
19 */ 19 */
20 20
21 #include <string>
22 #include <mailutils/cpp/registrar.h> 21 #include <mailutils/cpp/registrar.h>
23 #include <mailutils/cpp/error.h>
24 #include <errno.h>
25 22
26 using namespace mailutils; 23 using namespace mailutils;
27 24
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/stream.h> 21 #include <mailutils/cpp/stream.h>
22 #include <errno.h>
23 22
24 using namespace mailutils; 23 using namespace mailutils;
25 24
......
...@@ -19,8 +19,6 @@ ...@@ -19,8 +19,6 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/url.h> 21 #include <mailutils/cpp/url.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24 22
25 using namespace mailutils; 23 using namespace mailutils;
26 24
...@@ -76,67 +74,73 @@ Url :: get_port () ...@@ -76,67 +74,73 @@ Url :: get_port ()
76 std::string 74 std::string
77 Url :: get_scheme () 75 Url :: get_scheme ()
78 { 76 {
79 int status = mu_url_get_scheme (url, buf, sizeof (buf), NULL); 77 char *buf = NULL;
78 int status = mu_url_aget_scheme (url, &buf);
80 if (status == MU_ERR_NOENT) 79 if (status == MU_ERR_NOENT)
81 return ""; 80 return "";
82 else if (status) 81 else if (status)
83 throw Exception ("Url::get_scheme", status); 82 throw Exception ("Url::get_scheme", status);
84 return std::string (buf); 83 return std::string (buf ? buf : "");
85 } 84 }
86 85
87 std::string 86 std::string
88 Url :: get_user () 87 Url :: get_user ()
89 { 88 {
90 int status = mu_url_get_user (url, buf, sizeof (buf), NULL); 89 char *buf = NULL;
90 int status = mu_url_aget_user (url, &buf);
91 if (status == MU_ERR_NOENT) 91 if (status == MU_ERR_NOENT)
92 return ""; 92 return "";
93 else if (status) 93 else if (status)
94 throw Exception ("Url::get_user", status); 94 throw Exception ("Url::get_user", status);
95 return std::string (buf); 95 return std::string (buf ? buf : "");
96 } 96 }
97 97
98 std::string 98 std::string
99 Url :: get_passwd () 99 Url :: get_passwd ()
100 { 100 {
101 int status = mu_url_get_passwd (url, buf, sizeof (buf), NULL); 101 char *buf = NULL;
102 int status = mu_url_aget_passwd (url, &buf);
102 if (status == MU_ERR_NOENT) 103 if (status == MU_ERR_NOENT)
103 return ""; 104 return "";
104 else if (status) 105 else if (status)
105 throw Exception ("Url::get_passwd", status); 106 throw Exception ("Url::get_passwd", status);
106 return std::string (buf); 107 return std::string (buf ? buf : "");
107 } 108 }
108 109
109 std::string 110 std::string
110 Url :: get_auth () 111 Url :: get_auth ()
111 { 112 {
112 int status = mu_url_get_auth (url, buf, sizeof (buf), NULL); 113 char *buf = NULL;
114 int status = mu_url_aget_auth (url, &buf);
113 if (status == MU_ERR_NOENT) 115 if (status == MU_ERR_NOENT)
114 return ""; 116 return "";
115 else if (status) 117 else if (status)
116 throw Exception ("Url::get_auth", status); 118 throw Exception ("Url::get_auth", status);
117 return std::string (buf); 119 return std::string (buf ? buf : "");
118 } 120 }
119 121
120 std::string 122 std::string
121 Url :: get_host () 123 Url :: get_host ()
122 { 124 {
123 int status = mu_url_get_host (url, buf, sizeof (buf), NULL); 125 char *buf = NULL;
126 int status = mu_url_aget_host (url, &buf);
124 if (status == MU_ERR_NOENT) 127 if (status == MU_ERR_NOENT)
125 return ""; 128 return "";
126 else if (status) 129 else if (status)
127 throw Exception ("Url::get_host", status); 130 throw Exception ("Url::get_host", status);
128 return std::string (buf); 131 return std::string (buf ? buf : "");
129 } 132 }
130 133
131 std::string 134 std::string
132 Url :: get_path () 135 Url :: get_path ()
133 { 136 {
134 int status = mu_url_get_path (url, buf, sizeof (buf), NULL); 137 char *buf = NULL;
138 int status = mu_url_aget_path (url, &buf);
135 if (status == MU_ERR_NOENT) 139 if (status == MU_ERR_NOENT)
136 return ""; 140 return "";
137 else if (status) 141 else if (status)
138 throw Exception ("Url::get_path", status); 142 throw Exception ("Url::get_path", status);
139 return std::string (buf); 143 return std::string (buf ? buf : "");
140 } 144 }
141 145
142 std::vector<std::string> 146 std::vector<std::string>
...@@ -157,3 +161,17 @@ Url :: get_query () ...@@ -157,3 +161,17 @@ Url :: get_query ()
157 return params; 161 return params;
158 } 162 }
159 163
164 std::string
165 Url :: to_string ()
166 {
167 const char *str = mu_url_to_string (url);
168 return std::string (str ? str : "");
169 }
170
171 namespace mailutils
172 {
173 std::ostream& operator << (std::ostream& os, Url& url) {
174 return os << url.to_string ();
175 };
176 }
177
......