Commit f5191b73 f5191b732ac0e4dcc782cb3cc8dfc700a7e4c72a by Wojciech Polak

libmu_cpp refactoring and improvements.

* examples/cpp/mimetest.cc, include/mailutils/cpp/attribute.h,
include/mailutils/cpp/body.h, include/mailutils/cpp/mime.h,
include/mailutils/cpp/mutil.h, include/mailutils/cpp/registrar.h,
libmu_cpp/attribute.cc, libmu_cpp/body.cc, libmu_cpp/mime.cc,
libmu_cpp/mutil.cc, libmu_cpp/registrar.cc: New files.
1 parent 74f736ce
1 ## Process this file with GNU Automake to create Makefile.in 1 ## Process this file with GNU Automake to create Makefile.in
2 ## 2 ##
3 ## Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 ## Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 ## 4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or 5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as 6 ## modify it under the terms of the GNU General Public License as
...@@ -23,6 +23,7 @@ CXX_EXAMPLES = \ ...@@ -23,6 +23,7 @@ CXX_EXAMPLES = \
23 iconv\ 23 iconv\
24 listop\ 24 listop\
25 mailcap\ 25 mailcap\
26 mimetest\
26 murun\ 27 murun\
27 sfrom\ 28 sfrom\
28 url-parse 29 url-parse
...@@ -43,6 +44,7 @@ http_SOURCES = http.cc ...@@ -43,6 +44,7 @@ http_SOURCES = http.cc
43 iconv_SOURCES = iconv.cc 44 iconv_SOURCES = iconv.cc
44 listop_SOURCES = listop.cc 45 listop_SOURCES = listop.cc
45 mailcap_SOURCES = mailcap.cc 46 mailcap_SOURCES = mailcap.cc
47 mimetest_SOURCES = mimetest.cc
46 murun_SOURCES = murun.cc 48 murun_SOURCES = murun.cc
47 sfrom_SOURCES = sfrom.cc 49 sfrom_SOURCES = sfrom.cc
48 url_parse_SOURCES = url-parse.cc 50 url_parse_SOURCES = url-parse.cc
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -22,47 +22,40 @@ ...@@ -22,47 +22,40 @@
22 #include <cstring> 22 #include <cstring>
23 #include <mailutils/cpp/mailutils.h> 23 #include <mailutils/cpp/mailutils.h>
24 24
25 #include <mailutils/filter.h>
26 #include <mailutils/mutil.h>
27
28 using namespace std; 25 using namespace std;
29 using namespace mailutils; 26 using namespace mailutils;
30 27
31 static int 28 static int
32 parse (const char *str) 29 parse (const char *str)
33 { 30 {
34 size_t no = 0; 31 set_user_email_domain ("localhost");
35 size_t count = 0;
36 std::string buf;
37
38 mu_set_user_email_domain ("localhost");
39 32
40 try { 33 try {
41 Address address (str); 34 Address address (str);
42 count = address.getCount (); 35 size_t count = address.get_count ();
43 cout << str << "=> count " << count << endl; 36 cout << str << "=> count " << count << endl;
44 37
45 for (no = 1; no <= count; no++) 38 for (size_t no = 1; no <= count; no++)
46 { 39 {
47 bool isgroup = address.isGroup (no); 40 bool isgroup = address.is_group (no);
48 cout << no << " "; 41 cout << no << " ";
49 42
50 if (isgroup) 43 if (isgroup)
51 cout << "group " << address.getPersonal (no) << endl; 44 cout << "group " << address.get_personal (no) << endl;
52 else 45 else
53 cout << "email " << address.getEmail (no) << endl; 46 cout << "email " << address.get_email (no) << endl;
54 47
55 if (!isgroup) 48 if (!isgroup)
56 cout << " personal " << address.getPersonal (no) << endl; 49 cout << " personal " << address.get_personal (no) << endl;
57 50
58 cout << " comments " << address.getComments (no) << endl; 51 cout << " comments " << address.get_comments (no) << endl;
59 cout << " local-part " << address.getLocalPart (no) 52 cout << " local-part " << address.get_local_part (no)
60 << " domain " << address.getDomain (no) << endl; 53 << " domain " << address.get_domain (no) << endl;
61 cout << " route " << address.getRoute (no) << endl; 54 cout << " route " << address.get_route (no) << endl;
62 } 55 }
63 } 56 }
64 catch (Exception& e) { 57 catch (Exception& e) {
65 cerr << e.method () << ": " << e.msgError () << endl; 58 cerr << e.method () << ": " << e.what () << endl;
66 } 59 }
67 60
68 cout << endl; 61 cout << endl;
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
28 using namespace std; 28 using namespace std;
29 using namespace mailutils; 29 using namespace mailutils;
30 30
31 std::string wbuf = "GET / HTTP/1.0\r\n\r\n"; 31 string wbuf = "GET / HTTP/1.0\r\n\r\n";
32 std::string rbuf; 32 string rbuf;
33 33
34 int 34 int
35 main () 35 main ()
...@@ -55,13 +55,13 @@ main () ...@@ -55,13 +55,13 @@ main ()
55 } 55 }
56 catch (Stream::EAgain) { 56 catch (Stream::EAgain) {
57 stream.wait (MU_STREAM_READY_WR); 57 stream.wait (MU_STREAM_READY_WR);
58 off += stream.getWriten (); 58 off += stream.get_write_count ();
59 goto write_again; 59 goto write_again;
60 } 60 }
61 61
62 if (stream.getWriten () != wbuf.length ()) 62 if (stream.get_write_count () != wbuf.length ())
63 { 63 {
64 cerr << "stream.getWriten() != wbuf length" << endl; 64 cerr << "stream.get_write_count() != wbuf length" << endl;
65 exit (1); 65 exit (1);
66 } 66 }
67 67
...@@ -75,12 +75,12 @@ main () ...@@ -75,12 +75,12 @@ main ()
75 stream.wait (MU_STREAM_READY_RD); 75 stream.wait (MU_STREAM_READY_RD);
76 goto read_again; 76 goto read_again;
77 } 77 }
78 cout << rbuf.substr (0, stream.getReadn ()); 78 cout << rbuf.substr (0, stream.get_read_count ());
79 } 79 }
80 while (stream.getReadn ()); 80 while (stream.get_read_count ());
81 } 81 }
82 catch (Exception& e) { 82 catch (Exception& e) {
83 cerr << e.method () << ": " << e.msgError () << endl; 83 cerr << e.method () << ": " << e.what () << endl;
84 exit (1); 84 exit (1);
85 } 85 }
86 86
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -41,7 +41,8 @@ main (int argc, char **argv) ...@@ -41,7 +41,8 @@ main (int argc, char **argv)
41 in->open (); 41 in->open ();
42 42
43 FilterStream cvt; 43 FilterStream cvt;
44 cvt.iconvCreate (*in, (string)argv[1], (string)argv[2], 0, mu_fallback_none); 44 cvt.iconv_create (*in, (string)argv[1], (string)argv[2], 0,
45 mu_fallback_none);
45 cvt.open (); 46 cvt.open ();
46 delete in; 47 delete in;
47 48
...@@ -50,15 +51,15 @@ main (int argc, char **argv) ...@@ -50,15 +51,15 @@ main (int argc, char **argv)
50 51
51 do { 52 do {
52 cvt.read (buffer, sizeof (buffer), total); 53 cvt.read (buffer, sizeof (buffer), total);
53 out.sequentialWrite (buffer, cvt.getReadn ()); 54 out.sequential_write (buffer, cvt.get_read_count ());
54 total += cvt.getReadn (); 55 total += cvt.get_read_count ();
55 } while (cvt.getReadn ()); 56 } while (cvt.get_read_count ());
56 57
57 out.flush (); 58 out.flush ();
58 delete in; 59 delete in;
59 } 60 }
60 catch (Exception& e) { 61 catch (Exception& e) {
61 cerr << e.method () << ": " << e.msgError () << endl; 62 cerr << e.method () << ": " << e.what () << endl;
62 exit (1); 63 exit (1);
63 } 64 }
64 65
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -36,11 +36,9 @@ usage (int code) ...@@ -36,11 +36,9 @@ usage (int code)
36 void 36 void
37 print (List& lst) 37 print (List& lst)
38 { 38 {
39 Iterator itr (lst); 39 for (Iterator itr = lst.begin (); !itr.is_done (); itr++)
40
41 for (itr.first (); !itr.isDone (); itr++)
42 { 40 {
43 char* text = (char *) itr.current (); 41 char* text = (char *) *itr;
44 cout << text << endl; 42 cout << text << endl;
45 } 43 }
46 } 44 }
...@@ -72,7 +70,7 @@ del (List& lst, int argc, char **argv) ...@@ -72,7 +70,7 @@ del (List& lst, int argc, char **argv)
72 lst.remove (strdup (*++argv)); 70 lst.remove (strdup (*++argv));
73 } 71 }
74 catch (Exception& e) { 72 catch (Exception& e) {
75 cerr << e.method () << ": " << e.msgError () << endl; 73 cerr << e.method () << ": " << e.what () << endl;
76 } 74 }
77 } 75 }
78 } 76 }
...@@ -94,7 +92,7 @@ add (List& lst, int argc, char **argv) ...@@ -94,7 +92,7 @@ add (List& lst, int argc, char **argv)
94 lst.append (strdup (*++argv)); 92 lst.append (strdup (*++argv));
95 } 93 }
96 catch (Exception& e) { 94 catch (Exception& e) {
97 cerr << e.method () << ": " << e.msgError () << endl; 95 cerr << e.method () << ": " << e.what () << endl;
98 } 96 }
99 } 97 }
100 } 98 }
...@@ -115,7 +113,7 @@ prep (List& lst, int argc, char **argv) ...@@ -115,7 +113,7 @@ prep (List& lst, int argc, char **argv)
115 lst.prepend (strdup (*++argv)); 113 lst.prepend (strdup (*++argv));
116 } 114 }
117 catch (Exception& e) { 115 catch (Exception& e) {
118 cerr << e.method () << ": " << e.msgError () << endl; 116 cerr << e.method () << ": " << e.what () << endl;
119 } 117 }
120 } 118 }
121 } 119 }
...@@ -134,7 +132,7 @@ repl (List& lst, int argc, char **argv) ...@@ -134,7 +132,7 @@ repl (List& lst, int argc, char **argv)
134 lst.replace (argv[1], strdup (argv[2])); 132 lst.replace (argv[1], strdup (argv[2]));
135 } 133 }
136 catch (Exception& e) { 134 catch (Exception& e) {
137 cerr << e.method () << ": " << e.msgError () << endl; 135 cerr << e.method () << ": " << e.what () << endl;
138 } 136 }
139 } 137 }
140 138
...@@ -170,7 +168,7 @@ find (Iterator* itr, char* arg) ...@@ -170,7 +168,7 @@ find (Iterator* itr, char* arg)
170 } 168 }
171 169
172 itr->current ((void**) &text); 170 itr->current ((void**) &text);
173 for (itr->first (); !itr->isDone (); itr->next ()) 171 for (itr->first (); !itr->is_done (); itr->next ())
174 { 172 {
175 char *item; 173 char *item;
176 174
...@@ -181,7 +179,7 @@ find (Iterator* itr, char* arg) ...@@ -181,7 +179,7 @@ find (Iterator* itr, char* arg)
181 179
182 cerr << arg << " not in list" << endl; 180 cerr << arg << " not in list" << endl;
183 181
184 for (itr->first (); !itr->isDone (); itr->next ()) 182 for (itr->first (); !itr->is_done (); itr->next ())
185 { 183 {
186 char *item; 184 char *item;
187 185
...@@ -233,7 +231,7 @@ shell (List& lst) ...@@ -233,7 +231,7 @@ shell (List& lst)
233 itr[num]->current ((void**) &text); 231 itr[num]->current ((void**) &text);
234 } 232 }
235 catch (Exception& e) { 233 catch (Exception& e) {
236 cerr << e.method () << ": " << e.msgError () << endl; 234 cerr << e.method () << ": " << e.what () << endl;
237 } 235 }
238 236
239 cout << num << ":(" << (text ? text : "NULL") << ")> "; 237 cout << num << ":(" << (text ? text : "NULL") << ")> ";
...@@ -246,27 +244,29 @@ shell (List& lst) ...@@ -246,27 +244,29 @@ shell (List& lst)
246 244
247 if (argc > 0) 245 if (argc > 0)
248 { 246 {
249 if (!strcmp (argv[0], "next")) 247 string cmd (argv[0]);
248
249 if (cmd == "next")
250 next (itr[num], argv[1]); 250 next (itr[num], argv[1]);
251 else if (!strcmp (argv[0], "first")) 251 else if (cmd == "first")
252 itr[num]->first (); 252 itr[num]->first ();
253 else if (!strcmp (argv[0], "del")) 253 else if (cmd == "del")
254 del (lst, argc, argv); 254 del (lst, argc, argv);
255 else if (!strcmp (argv[0], "add")) 255 else if (cmd == "add")
256 add (lst, argc, argv); 256 add (lst, argc, argv);
257 else if (!strcmp (argv[0], "prep")) 257 else if (cmd == "prep")
258 prep (lst, argc, argv); 258 prep (lst, argc, argv);
259 else if (!strcmp (argv[0], "repl")) 259 else if (cmd == "repl")
260 repl (lst, argc, argv); 260 repl (lst, argc, argv);
261 else if (!strcmp (argv[0], "print")) 261 else if (cmd == "print")
262 print (lst); 262 print (lst);
263 else if (!strcmp (argv[0], "quit")) 263 else if (cmd == "quit")
264 return; 264 return;
265 else if (!strcmp (argv[0], "iter")) 265 else if (cmd == "iter")
266 iter (&num, argc, argv); 266 iter (&num, argc, argv);
267 else if (!strcmp (argv[0], "find")) 267 else if (cmd == "find")
268 find (itr[num], argv[1]); 268 find (itr[num], argv[1]);
269 else if (!strcmp (argv[0], "help")) 269 else if (cmd == "help")
270 help (); 270 help ();
271 else if (argc == 1) 271 else if (argc == 1)
272 { 272 {
...@@ -280,7 +280,7 @@ shell (List& lst) ...@@ -280,7 +280,7 @@ shell (List& lst)
280 text = (char*) lst[n]; 280 text = (char*) lst[n];
281 } 281 }
282 catch (Exception& e) { 282 catch (Exception& e) {
283 cerr << e.method () << ": " << e.msgError () << endl; 283 cerr << e.method () << ": " << e.what () << endl;
284 } 284 }
285 285
286 // else 286 // else
...@@ -320,7 +320,7 @@ main (int argc, char **argv) ...@@ -320,7 +320,7 @@ main (int argc, char **argv)
320 320
321 try { 321 try {
322 List lst; 322 List lst;
323 lst.setComparator (string_comp); 323 lst.set_comparator (string_comp);
324 324
325 while (argc--) 325 while (argc--)
326 { 326 {
...@@ -330,7 +330,7 @@ main (int argc, char **argv) ...@@ -330,7 +330,7 @@ main (int argc, char **argv)
330 shell (lst); 330 shell (lst);
331 } 331 }
332 catch (Exception& e) { 332 catch (Exception& e) {
333 cerr << e.method () << ": " << e.msgError () << endl; 333 cerr << e.method () << ": " << e.what () << endl;
334 } 334 }
335 335
336 return 0; 336 return 0;
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -27,58 +27,48 @@ using namespace mailutils; ...@@ -27,58 +27,48 @@ using namespace mailutils;
27 int 27 int
28 main (int argc, char **argv) 28 main (int argc, char **argv)
29 { 29 {
30 int status = 0; 30 string file ("/etc/mailcap");
31 char* file = "/etc/mailcap";
32 31
33 try { 32 try {
34 FileStream stream ((std::string) file, MU_STREAM_READ); 33 FileStream stream (file, MU_STREAM_READ);
35 stream.open (); 34 stream.open ();
36 35
37 Mailcap mailcap (stream); 36 Mailcap mailcap (stream);
38 37
39 int i; 38 int count = mailcap.entries_count ();
40 size_t count = 0;
41 string buffer;
42 39
43 count = mailcap.getCount (); 40 for (int i = 1; i <= count; i++)
44 for (i = 1; i <= count; i++)
45 { 41 {
46 size_t j;
47 size_t fields_count = 0;
48
49 cout << "entry[" << i << "]\n"; 42 cout << "entry[" << i << "]\n";
50 43
51 MailcapEntry entry = mailcap.getEntry (i); 44 MailcapEntry entry = mailcap[i];
52 45
53 /* typefield. */ 46 /* typefield. */
54 buffer = entry.getTypeField (); 47 cout << "\ttypefield: " << entry.get_typefield () << endl;
55 cout << "\ttypefield: " << buffer << endl;
56 48
57 /* view-command. */ 49 /* view-command. */
58 buffer = entry.getViewCommand (); 50 cout << "\tview-command: " << entry.get_viewcommand () << endl;
59 cout << "\tview-command: " << buffer << endl;
60 51
61 /* fields. */ 52 /* fields. */
62 fields_count = entry.fieldsCount (); 53 size_t fields_count = entry.fields_count ();
63 for (j = 1; j <= fields_count; j++) 54 for (size_t j = 1; j <= fields_count; j++)
64 { 55 {
65 try { 56 try {
66 buffer = entry.getField (j); 57 cout << "\tfields[" << j << "]: " << entry[j] << endl;
67 } 58 }
68 catch (Exception& e) { 59 catch (Exception& e) {
69 cerr << e.method () << ": cannot retrieve field " 60 cerr << e.method () << ": cannot retrieve field "
70 << j << ": " << e.msgError () << endl; 61 << j << ": " << e.what () << endl;
71 } 62 }
72 cout << "\tfields[" << j << "]: " << buffer << endl;
73 } 63 }
74
75 cout << endl; 64 cout << endl;
76 } 65 }
77 } 66 }
78 catch (Exception& e) { 67 catch (Exception& e) {
79 cerr << e.method () << ": " << e.msgError () << endl; 68 cerr << e.method () << ": " << e.what () << endl;
80 exit (1); 69 exit (1);
81 } 70 }
82 71
83 return 0; 72 return 0;
84 } 73 }
74
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2009 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 MA 02110-1301 USA */
18
19 #include <iostream>
20 #include <cstdlib>
21 #include <cstring>
22 #include <iomanip>
23 #include <mailutils/cpp/mailutils.h>
24
25 using namespace std;
26 using namespace mailutils;
27
28 void message_display_parts (Message& msg, int indent);
29
30 bool print_attachments = false;
31 int indent_level = 4;
32
33 void
34 print_file (const std::string& fname, int indent)
35 {
36 char buf[128];
37 FILE *fp = fopen (fname.c_str (), "r");
38
39 if (!fp)
40 {
41 cerr << "can't open file " << fname << ": " << strerror (errno) << endl;
42 return;
43 }
44
45 while (fgets (buf, sizeof buf, fp))
46 cout << setw (indent) << setfill (' ') << buf;
47 fclose (fp);
48 unlink (fname.c_str ());
49 }
50
51 int
52 main (int argc, char **argv)
53 {
54 int i = 0;
55 bool debug = false;
56
57 for (i = 1; i < argc; i++)
58 {
59 if (strcmp (argv[i], "-d") == 0)
60 debug = true;
61 else if (strcmp (argv[i], "-p") == 0)
62 print_attachments = true;
63 else if (strcmp (argv[i], "-i") == 0)
64 indent_level = strtoul (argv[++i], NULL, 0);
65 else
66 break;
67 }
68
69 /* Registration. */
70 registrar_record (mu_imap_record);
71 registrar_record (mu_pop_record);
72 registrar_record (mu_mbox_record);
73 registrar_set_default_record (mu_mbox_record);
74
75 MailboxDefault mbox (argv[i]);
76
77 /* Debugging trace. FIXME: ADD MISSING */
78
79 /* Open the mailbox for reading only. */
80 mbox.open ();
81
82 /* Iterate through the entire message set. */
83 size_t count = mbox.messages_count ();
84
85 for (size_t i = 1; i <= count; ++i)
86 {
87 Message msg = mbox.get_message (i);
88 Header hdr = msg.get_header ();
89
90 cout << "Message: " << i << endl;
91 cout << "From: " << hdr[MU_HEADER_FROM] << endl;
92 cout << "Subject: " << hdr[MU_HEADER_SUBJECT] << endl;
93 cout << "Number of parts in message - " << msg.get_num_parts () << endl;
94 cout << "Total message size - "
95 << msg.size () << "/" << msg.lines () << endl;
96
97 try {
98 message_display_parts (msg, 0);
99 }
100 catch (Exception& e)
101 {
102 cerr << e.method () << ": " << e.what () << endl;
103 }
104 }
105
106 mbox.close ();
107 return 0;
108 }
109
110 static void
111 print_message_part_sizes (Message& part, int indent)
112 {
113 Header hdr = part.get_header ();
114 Body body = part.get_body ();
115
116 cout << setw (indent) << setfill (' ') << "Message part size - ";
117 cout << part.size () << "/" << part.lines () << ": "
118 << hdr.size () << "/" << hdr.lines () << ", "
119 << body.size () << "/" << body.lines () << endl;
120 }
121
122 void
123 message_display_parts (Message& msg, int indent)
124 {
125 size_t nbytes;
126
127 /* How many parts does the message has? */
128 size_t nparts = msg.get_num_parts ();
129
130 /* Iterate through all the parts. Treat type "message/rfc822"
131 differently, since it is a message of its own that can have other
132 subparts(recursive). */
133 for (int j = 1; j <= nparts; j++)
134 {
135 Message part = msg.get_part (j);
136 Header hdr = part.get_header ();
137
138 string type;
139 string encoding ("");
140 try {
141 type = hdr[MU_HEADER_CONTENT_TYPE];
142 encoding = hdr[MU_HEADER_CONTENT_TRANSFER_ENCODING];
143 }
144 catch (Exception& e)
145 {
146 if (e.status () != MU_ERR_NOENT) {
147 cerr << e.method () << ": " << e.what () << endl;
148 exit (1);
149 }
150 }
151
152 cout << setw (indent) << setfill (' ')
153 << "Type of part " << j << " = " << type << endl;
154
155 print_message_part_sizes (part, indent);
156
157 bool ismulti = part.is_multipart ();
158 if (type == "message/rfc822" || ismulti)
159 {
160 if (!ismulti)
161 part = part.unencapsulate ();
162
163 Header hdr = part.get_header ();
164 string from = hdr[MU_HEADER_FROM];
165 string subject = hdr[MU_HEADER_SUBJECT];
166
167 cout << setw (indent) << setfill (' ')
168 << "Encapsulated message : " << from << "\t" << subject << endl;
169 cout << setw (indent) << setfill (' ') << "Begin" << endl;
170
171 size_t nsubparts = part.get_num_parts ();
172 message_display_parts (part, indent + indent_level);
173 }
174 else if (strncasecmp (type.c_str (), "text/plain",
175 strlen ("text/plain")) == 0 ||
176 strncasecmp (type.c_str (), "text/html",
177 strlen ("text/html")) == 0 ||
178 type.empty ())
179 {
180 cout << setw (indent) << setfill (' ') << "Text Message" << endl;
181 cout << setw (indent) << setfill (' ') << "Begin" << endl;
182
183 Body body = part.get_body ();
184 Stream stream = body.get_stream ();
185
186 FilterStream filter;
187 filter.create (stream, encoding, 0, 0);
188 int offset = 0;
189 char buf[2048];
190
191 while (filter.readline (buf, sizeof (buf), offset) == 0 &&
192 filter.get_read_count ())
193 {
194 cout << setw (indent) << setfill (' ') << buf;
195 offset += filter.get_read_count ();
196 }
197 }
198 else
199 {
200 /* Save the attachements. */
201 string fname;
202 try {
203 fname = part.get_attachment_name ();
204 }
205 catch (Exception& e) {
206 fname = mailutils::tempname ();
207 }
208 cout << setw (indent) << setfill (' ')
209 << "Attachment - saving " << "[" << fname << "]" << endl;
210 cout << setw (indent) << setfill (' ') << "Begin" << endl;
211
212 part.save_attachment ();
213 if (print_attachments)
214 print_file (fname, indent);
215 }
216 cout << endl << setw (indent) << setfill (' ') << "End" << endl;
217 }
218 }
219
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -32,16 +32,16 @@ read_and_print (Stream *in, Stream& out) ...@@ -32,16 +32,16 @@ read_and_print (Stream *in, Stream& out)
32 { 32 {
33 char buffer[128]; 33 char buffer[128];
34 34
35 in->sequentialReadLine (buffer, sizeof (buffer)); 35 in->sequential_readline (buffer, sizeof (buffer));
36 while (in->getReadn ()) 36 while (in->get_read_count ())
37 { 37 {
38 out.sequentialWrite (buffer, in->getReadn ()); 38 out.sequential_write (buffer, in->get_read_count ());
39 in->sequentialReadLine (buffer, sizeof (buffer)); 39 in->sequential_readline (buffer, sizeof (buffer));
40 } 40 }
41 } 41 }
42 42
43 Stream * 43 Stream *
44 createFilter (bool read_stdin, char *cmdline, int flags) 44 create_filter (bool read_stdin, char *cmdline, int flags)
45 { 45 {
46 try { 46 try {
47 if (read_stdin) 47 if (read_stdin)
...@@ -61,7 +61,7 @@ createFilter (bool read_stdin, char *cmdline, int flags) ...@@ -61,7 +61,7 @@ createFilter (bool read_stdin, char *cmdline, int flags)
61 } 61 }
62 catch (Exception& e) { 62 catch (Exception& e) {
63 cerr << progname << ": cannot create program filter stream: " 63 cerr << progname << ": cannot create program filter stream: "
64 << e.method () << ": " << e.msgError () << endl; 64 << e.method () << ": " << e.what () << endl;
65 exit (1); 65 exit (1);
66 } 66 }
67 } 67 }
...@@ -92,7 +92,7 @@ main (int argc, char *argv[]) ...@@ -92,7 +92,7 @@ main (int argc, char *argv[])
92 92
93 mu_argcv_string (argc - i, &argv[i], &cmdline); 93 mu_argcv_string (argc - i, &argv[i], &cmdline);
94 94
95 stream = createFilter (read_stdin, cmdline, flags); 95 stream = create_filter (read_stdin, cmdline, flags);
96 96
97 try { 97 try {
98 StdioStream out (stdout, 0); 98 StdioStream out (stdout, 0);
...@@ -103,7 +103,7 @@ main (int argc, char *argv[]) ...@@ -103,7 +103,7 @@ main (int argc, char *argv[])
103 delete stream; 103 delete stream;
104 } 104 }
105 catch (Exception& e) { 105 catch (Exception& e) {
106 cerr << e.method () << ": " << e.msgError () << endl; 106 cerr << e.method () << ": " << e.what () << endl;
107 exit (1); 107 exit (1);
108 } 108 }
109 109
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -21,36 +21,27 @@ ...@@ -21,36 +21,27 @@
21 #include <iostream> 21 #include <iostream>
22 #include <mailutils/cpp/mailutils.h> 22 #include <mailutils/cpp/mailutils.h>
23 23
24 #include <mailutils/registrar.h> // tmp
25 #include <mailutils/list.h> // tmp
26
27 using namespace std; 24 using namespace std;
28 using namespace mailutils; 25 using namespace mailutils;
29 26
30 int main (int argc, char* argv[]) 27 int main (int argc, char* argv[])
31 { 28 {
32 size_t total = 0;
33
34 if (argc == 1) 29 if (argc == 1)
35 exit (0); 30 exit (0);
36 31
37 mu_register_local_mbox_formats (); 32 register_local_mbox_formats ();
38
39 Message msg;
40 Header hdr;
41 33
42 try { 34 try {
43
44 MailboxDefault mbox (argv[1]); 35 MailboxDefault mbox (argv[1]);
36 mbox.open ();
45 37
46 mbox.open (MU_STREAM_READ); 38 size_t total = mbox.messages_count ();
47 total = mbox.messagesCount ();
48 cout << "Total: " << total << endl; 39 cout << "Total: " << total << endl;
49 40
50 for (int msgno = 1; msgno <= total; msgno++) 41 for (int msgno = 1; msgno <= total; msgno++)
51 { 42 {
52 msg = mbox[msgno]; 43 Message msg = mbox[msgno];
53 hdr = msg.getHeader (); 44 Header hdr = msg.get_header ();
54 cout << hdr[MU_HEADER_FROM] << " " 45 cout << hdr[MU_HEADER_FROM] << " "
55 << hdr[MU_HEADER_SUBJECT] << endl; 46 << hdr[MU_HEADER_SUBJECT] << endl;
56 } 47 }
...@@ -58,7 +49,7 @@ int main (int argc, char* argv[]) ...@@ -58,7 +49,7 @@ int main (int argc, char* argv[])
58 mbox.close (); 49 mbox.close ();
59 } 50 }
60 catch (Exception& e) { 51 catch (Exception& e) {
61 cerr << e.method () << ": " << e.msgError () << endl; 52 cerr << e.method () << ": " << e.what () << endl;
62 exit (1); 53 exit (1);
63 } 54 }
64 55
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or modify 5 GNU Mailutils is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
...@@ -43,21 +43,21 @@ main () ...@@ -43,21 +43,21 @@ main ()
43 Url url (str); 43 Url url (str);
44 url.parse (); 44 url.parse ();
45 45
46 cout << "\tscheme <" << url.getScheme () << ">" << endl; 46 cout << "\tscheme <" << url.get_scheme () << ">" << endl;
47 cout << "\tuser <" << url.getUser () << ">" << endl; 47 cout << "\tuser <" << url.get_user () << ">" << endl;
48 cout << "\tpasswd <" << url.getPasswd () << ">" << endl; 48 cout << "\tpasswd <" << url.get_passwd () << ">" << endl;
49 cout << "\tauth <" << url.getAuth () << ">" << endl; 49 cout << "\tauth <" << url.get_auth () << ">" << endl;
50 cout << "\thost <" << url.getHost () << ">" << endl; 50 cout << "\thost <" << url.get_host () << ">" << endl;
51 cout << "\tport " << url.getPort () << endl; 51 cout << "\tport " << url.get_port () << endl;
52 cout << "\tpath <" << url.getPath () << ">" << endl; 52 cout << "\tpath <" << url.get_path () << ">" << endl;
53 53
54 vector<string> params = url.getQuery (); 54 vector<string> params = url.get_query ();
55 for (vector<string>::size_type i = 0; i != params.size (); i++) { 55 for (vector<string>::size_type i = 0; i != params.size (); i++) {
56 cout << "\tquery[" << i << "] <" << params[i] << ">" << endl; 56 cout << "\tquery[" << i << "] <" << params[i] << ">" << endl;
57 } 57 }
58 } 58 }
59 catch (Exception& e) { 59 catch (Exception& e) {
60 cerr << e.method () << ": " << e.msgError () << endl; 60 cerr << e.method () << ": " << e.what () << endl;
61 goto again; 61 goto again;
62 } 62 }
63 } 63 }
......
1 ## Process this file with GNU Automake to create Makefile.in 1 ## Process this file with GNU Automake to create Makefile.in
2 ## 2 ##
3 ## Copyright (C) 2004, 2007 Free Software Foundation, Inc. 3 ## Copyright (C) 2004, 2007, 2009 Free Software Foundation, Inc.
4 ## 4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or 5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as 6 ## modify it under the terms of the GNU General Public License as
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
18 18
19 MU_CXX_INCLUDES = \ 19 MU_CXX_INCLUDES = \
20 address.h\ 20 address.h\
21 attribute.h\
22 body.h\
21 error.h\ 23 error.h\
22 filter.h\ 24 filter.h\
23 header.h\ 25 header.h\
...@@ -28,7 +30,10 @@ MU_CXX_INCLUDES = \ ...@@ -28,7 +30,10 @@ MU_CXX_INCLUDES = \
28 mailer.h\ 30 mailer.h\
29 mailutils.h\ 31 mailutils.h\
30 message.h\ 32 message.h\
33 mime.h\
34 mutil.h\
31 pop3.h\ 35 pop3.h\
36 registrar.h\
32 stream.h\ 37 stream.h\
33 url.h 38 url.h
34 39
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _ADDRESS_H 21 #ifndef _ADDRESS_H
22 #define _ADDRESS_H 22 #define _ADDRESS_H
23 23
24 #include <iostream>
25 #include <mailutils/address.h> 24 #include <mailutils/address.h>
26 #include <mailutils/cpp/error.h> 25 #include <mailutils/cpp/error.h>
27 26
...@@ -43,25 +42,25 @@ class Address ...@@ -43,25 +42,25 @@ class Address
43 Address (const mu_address_t); 42 Address (const mu_address_t);
44 ~Address (); 43 ~Address ();
45 44
46 size_t getCount (); 45 size_t get_count ();
47 bool isGroup (size_t); 46 bool is_group (size_t n);
48 47
49 std::string getEmail (size_t); 48 std::string get_email (size_t n);
50 std::string getLocalPart (size_t); 49 std::string get_local_part (size_t n);
51 std::string getDomain (size_t); 50 std::string get_domain (size_t n);
52 std::string getPersonal (size_t); 51 std::string get_personal (size_t n);
53 std::string getComments (size_t); 52 std::string get_comments (size_t n);
54 std::string getRoute (size_t); 53 std::string get_route (size_t n);
55 54
56 // Address Exceptions 55 // Address Exceptions
57 class EInval : public Exception { 56 class EInval : public Exception {
58 public: 57 public:
59 EInval (const std::string& m, int s) : Exception (m, s) {} 58 EInval (const char* m, int s) : Exception (m, s) {}
60 }; 59 };
61 60
62 class ENoent : public Exception { 61 class ENoent : public Exception {
63 public: 62 public:
64 ENoent (const std::string& m, int s) : Exception (m, s) {} 63 ENoent (const char* m, int s) : Exception (m, s) {}
65 }; 64 };
66 }; 65 };
67 66
......
1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007, 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_ATTRIBUTE_H
22 #define _MUCPP_ATTRIBUTE_H
23
24 #include <mailutils/attribute.h>
25
26 namespace mailutils
27 {
28
29 class Attribute
30 {
31 protected:
32 mu_attribute_t attr;
33
34 public:
35 Attribute ();
36 Attribute (const mu_attribute_t);
37
38 bool is_modified ();
39 void clear_modified ();
40 void set_modified ();
41
42 bool is_userflag (int flag);
43 bool is_seen ();
44 bool is_answered ();
45 bool is_flagged ();
46 bool is_deleted ();
47 bool is_draft ();
48 bool is_recent ();
49 bool is_read ();
50
51 void set_userflag (int flag);
52 void set_seen ();
53 void set_answered ();
54 void set_flagged ();
55 void set_deleted ();
56 void set_draft ();
57 void set_recent ();
58 void set_read ();
59
60 void unset_userflag (int flag);
61 void unset_seen ();
62 void unset_answered ();
63 void unset_flagged ();
64 void unset_deleted ();
65 void unset_draft ();
66 void unset_recent ();
67 void unset_read ();
68 };
69
70 }
71
72 #endif // not _MUCPP_ATTRIBUTE_H
73
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_BODY_H
22 #define _MUCPP_BODY_H
23
24 #include <string>
25 #include <mailutils/body.h>
26 #include <mailutils/cpp/stream.h>
27
28 namespace mailutils
29 {
30
31 class Body
32 {
33 protected:
34 mu_body_t body;
35 bool owner;
36
37 public:
38 Body ();
39 Body (const mu_body_t);
40 ~Body ();
41
42 bool is_modified ();
43 void clear_modified ();
44
45 Stream& get_stream ();
46
47 size_t size ();
48 size_t lines ();
49 };
50
51 }
52
53 #endif // not _MUCPP_BODY_H
54
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _MUCPP_ERROR_H 21 #ifndef _MUCPP_ERROR_H
22 #define _MUCPP_ERROR_H 22 #define _MUCPP_ERROR_H
23 23
24 #include <iostream>
25 #include <string> 24 #include <string>
26 #include <mailutils/errno.h> 25 #include <mailutils/errno.h>
27 26
...@@ -31,20 +30,36 @@ namespace mailutils ...@@ -31,20 +30,36 @@ namespace mailutils
31 class Exception 30 class Exception
32 { 31 {
33 protected: 32 protected:
34 std::string pmethod; 33 int pstatus;
35 std::string pmsgerr; 34 const char* pmethod;
35 const char* pmsgerr;
36 36
37 public: 37 public:
38 Exception (const std::string m, int s) { 38 Exception (const char* method_name, int status) {
39 pmethod = m; 39 pstatus = status;
40 pmsgerr = mu_strerror (s); 40 pmethod = method_name;
41 pmsgerr = mu_strerror (status);
41 } 42 }
42 43
43 std::string method () const { 44 Exception (const std::string method_name, int status) {
45 pstatus = status;
46 pmethod = method_name.c_str ();
47 pmsgerr = mu_strerror (status);
48 }
49
50 int status () const {
51 return pstatus;
52 }
53
54 const char* method () const {
44 return pmethod; 55 return pmethod;
45 } 56 }
46 57
47 std::string msgError () const { 58 const char* msg_error () const {
59 return pmsgerr;
60 }
61
62 const char* what () const {
48 return pmsgerr; 63 return pmsgerr;
49 } 64 }
50 }; 65 };
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _MUCPP_FILTER_H 21 #ifndef _MUCPP_FILTER_H
22 #define _MUCPP_FILTER_H 22 #define _MUCPP_FILTER_H
23 23
24 #include <iostream>
25 #include <mailutils/filter.h> 24 #include <mailutils/filter.h>
26 #include <mailutils/cpp/stream.h> 25 #include <mailutils/cpp/stream.h>
27 26
...@@ -34,10 +33,14 @@ class FilterStream : public Stream ...@@ -34,10 +33,14 @@ class FilterStream : public Stream
34 Stream *input; 33 Stream *input;
35 34
36 public: 35 public:
37 void create (Stream&, const std::string&, int, int); 36 void create (Stream& transport, const std::string& code, int mode,
38 void iconvCreate (Stream&, const std::string&, 37 int flag);
39 const std::string&, int, 38
40 enum mu_iconv_fallback_mode); 39 void iconv_create (Stream& transport,
40 const std::string& fromcode,
41 const std::string& tocode,
42 int flags,
43 enum mu_iconv_fallback_mode fallback_mode);
41 }; 44 };
42 45
43 } 46 }
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _MUCPP_HEADER_H 21 #ifndef _MUCPP_HEADER_H
22 #define _MUCPP_HEADER_H 22 #define _MUCPP_HEADER_H
23 23
24 #include <iostream>
25 #include <string> 24 #include <string>
26 #include <mailutils/header.h> 25 #include <mailutils/header.h>
27 26
...@@ -37,8 +36,13 @@ class Header ...@@ -37,8 +36,13 @@ class Header
37 Header (); 36 Header ();
38 Header (const mu_header_t); 37 Header (const mu_header_t);
39 38
40 std::string getValue (const std::string&); 39 std::string get_value (const std::string& name);
41 std::string operator [] (const std::string&); 40 size_t size ();
41 size_t lines ();
42
43 inline std::string operator [] (const std::string& name) {
44 return this->get_value (name);
45 }
42 }; 46 };
43 47
44 } 48 }
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,32 +21,42 @@ ...@@ -21,32 +21,42 @@
21 #ifndef _MUCPP_ITERATOR_H 21 #ifndef _MUCPP_ITERATOR_H
22 #define _MUCPP_ITERATOR_H 22 #define _MUCPP_ITERATOR_H
23 23
24 #include <iostream>
25 #include <mailutils/iterator.h> 24 #include <mailutils/iterator.h>
26 #include <mailutils/cpp/list.h> 25 #include <mailutils/cpp/list.h>
27 26
28 namespace mailutils 27 namespace mailutils
29 { 28 {
30 29
30 class List;
31
31 class Iterator 32 class Iterator
32 { 33 {
33 protected: 34 protected:
34 mu_iterator_t mu_iter; 35 mu_iterator_t mu_iter;
35 List* pList; 36 List* pList;
36 37
38 friend class List;
39
37 public: 40 public:
38 Iterator (const List&); 41 Iterator (const List&);
39 Iterator (const mu_iterator_t); 42 Iterator (const mu_iterator_t);
40 ~Iterator (); 43 ~Iterator ();
41 44
45 bool operator == (const Iterator&);
46 bool operator != (const Iterator&);
47
42 void dup (Iterator*&, const Iterator&); 48 void dup (Iterator*&, const Iterator&);
43 void first (); 49 void first ();
44 void next (); 50 void next ();
45 Iterator& operator ++ (int); 51 Iterator& operator ++ (int);
46 void current (void**); 52 void current (void** pitem);
47 void* current (); 53 void* current ();
48 bool isDone (); 54 bool is_done ();
49 List& getList (); 55 List& get_list ();
56
57 inline void* operator * () {
58 return this->current ();
59 }
50 }; 60 };
51 61
52 } 62 }
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
21 #ifndef _MUCPP_LIST_H 21 #ifndef _MUCPP_LIST_H
22 #define _MUCPP_LIST_H 22 #define _MUCPP_LIST_H
23 23
24 #include <iostream>
25 #include <mailutils/list.h> 24 #include <mailutils/list.h>
25 #include <mailutils/cpp/iterator.h>
26 26
27 typedef int mu_list_action_t (void*, void*); 27 typedef int mu_list_action_t (void*, void*);
28 typedef int (*mu_list_comparator_t) (const void*, const void*); 28 typedef int (*mu_list_comparator_t) (const void*, const void*);
...@@ -30,10 +30,13 @@ typedef int (*mu_list_comparator_t) (const void*, const void*); ...@@ -30,10 +30,13 @@ typedef int (*mu_list_comparator_t) (const void*, const void*);
30 namespace mailutils 30 namespace mailutils
31 { 31 {
32 32
33 class Iterator;
34
33 class List 35 class List
34 { 36 {
35 protected: 37 protected:
36 mu_list_t mu_list; 38 mu_list_t mu_list;
39 Iterator* iter;
37 40
38 friend class Iterator; 41 friend class Iterator;
39 42
...@@ -42,25 +45,33 @@ class List ...@@ -42,25 +45,33 @@ class List
42 List (const mu_list_t); 45 List (const mu_list_t);
43 ~List (); 46 ~List ();
44 47
45 void append (void*); 48 void append (void* item);
46 void prepend (void*); 49 void prepend (void* item);
47 void insert (void*, void*, int); 50 void insert (void* item, void* new_item, int insert_before);
48 void remove (void*); 51 void remove (void* item);
49 void replace (void*, void*); 52 void replace (void* old_item, void* new_item);
53
54 void get (size_t index, void** pitem);
55 void* get (size_t index);
56 void* front ();
57 void* back ();
50 58
51 void get (size_t, void**); 59 Iterator begin ();
52 void* get (size_t);
53 void* operator [] (size_t);
54 60
55 void toArray (void**, size_t, size_t*); 61 void to_array (void** array, size_t count, size_t* pcount);
56 void locate (void*, void**); 62 void locate (void* item, void** ret_item);
57 63
58 void apply (mu_list_action_t*, void*); 64 void apply (mu_list_action_t* action, void* cbdata);
59 mu_list_comparator_t setComparator (mu_list_comparator_t); 65 mu_list_comparator_t set_comparator (mu_list_comparator_t comp);
60 void setDestroyItem (void (*mu_destoy_item) (void *)); 66 void set_destroy_item (void (*mu_destoy_item) (void *item));
61 67
62 bool isEmpty (); 68 bool is_empty ();
63 size_t count (); 69 size_t count ();
70 size_t size ();
71
72 inline void* operator [] (size_t index) {
73 return this->get (index);
74 }
64 }; 75 };
65 76
66 } 77 }
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _MUCPP_MAILBOX_H 21 #ifndef _MUCPP_MAILBOX_H
22 #define _MUCPP_MAILBOX_H 22 #define _MUCPP_MAILBOX_H
23 23
24 #include <iostream>
25 #include <mailutils/mailbox.h> 24 #include <mailutils/mailbox.h>
26 #include <mailutils/cpp/message.h> 25 #include <mailutils/cpp/message.h>
27 26
...@@ -34,12 +33,16 @@ class MailboxBase ...@@ -34,12 +33,16 @@ class MailboxBase
34 mu_mailbox_t mbox; 33 mu_mailbox_t mbox;
35 34
36 public: 35 public:
37 void open (int); 36 void open ();
37 void open (int flag);
38 void close (); 38 void close ();
39 39
40 size_t messagesCount (); 40 size_t messages_count ();
41 Message& getMessage (size_t); 41 Message& get_message (size_t num);
42 Message& operator [] (size_t); 42
43 inline Message& operator [] (size_t num) {
44 return this->get_message (num);
45 }
43 }; 46 };
44 47
45 class Mailbox : public MailboxBase 48 class Mailbox : public MailboxBase
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _MUCPP_MAILCAP_H 21 #ifndef _MUCPP_MAILCAP_H
22 #define _MUCPP_MAILCAP_H 22 #define _MUCPP_MAILCAP_H
23 23
24 #include <iostream>
25 #include <mailutils/mailcap.h> 24 #include <mailutils/mailcap.h>
26 #include <mailutils/cpp/stream.h> 25 #include <mailutils/cpp/stream.h>
27 26
...@@ -39,10 +38,14 @@ class MailcapEntry ...@@ -39,10 +38,14 @@ class MailcapEntry
39 public: 38 public:
40 MailcapEntry (mu_mailcap_entry_t); 39 MailcapEntry (mu_mailcap_entry_t);
41 40
42 size_t fieldsCount (); 41 size_t fields_count ();
43 std::string getTypeField (); 42 std::string get_typefield ();
44 std::string getViewCommand (); 43 std::string get_viewcommand ();
45 std::string getField (size_t); 44 std::string get_field (size_t i);
45
46 inline std::string operator [] (size_t i) {
47 return this->get_field (i);
48 }
46 }; 49 };
47 50
48 class Mailcap 51 class Mailcap
...@@ -55,8 +58,12 @@ class Mailcap ...@@ -55,8 +58,12 @@ class Mailcap
55 Mailcap (const mu_mailcap_t); 58 Mailcap (const mu_mailcap_t);
56 ~Mailcap (); 59 ~Mailcap ();
57 60
58 size_t getCount (); 61 size_t entries_count ();
59 MailcapEntry& getEntry (size_t); 62 MailcapEntry& get_entry (size_t i);
63
64 inline MailcapEntry& operator [] (size_t i) {
65 return this->get_entry (i);
66 }
60 }; 67 };
61 68
62 } 69 }
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _MUCPP_MAILER_H 21 #ifndef _MUCPP_MAILER_H
22 #define _MUCPP_MAILER_H 22 #define _MUCPP_MAILER_H
23 23
24 #include <iostream>
25 #include <string> 24 #include <string>
26 #include <mailutils/mailer.h> 25 #include <mailutils/mailer.h>
27 #include <mailutils/cpp/message.h> 26 #include <mailutils/cpp/message.h>
...@@ -40,9 +39,10 @@ class Mailer ...@@ -40,9 +39,10 @@ class Mailer
40 Mailer (const mu_mailer_t); 39 Mailer (const mu_mailer_t);
41 ~Mailer (); 40 ~Mailer ();
42 41
43 void open (int); 42 void open (int flags);
44 void close (); 43 void close ();
45 void sendMessage (const Message&, const Address&, const Address&); 44 void send_message (const Message& msg, const Address& from,
45 const Address& to);
46 }; 46 };
47 47
48 } 48 }
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
19 */ 19 */
20 20
21 #include <mailutils/cpp/address.h> 21 #include <mailutils/cpp/address.h>
22 #include <mailutils/cpp/attribute.h>
23 #include <mailutils/cpp/body.h>
22 #include <mailutils/cpp/error.h> 24 #include <mailutils/cpp/error.h>
23 #include <mailutils/cpp/filter.h> 25 #include <mailutils/cpp/filter.h>
24 #include <mailutils/cpp/header.h> 26 #include <mailutils/cpp/header.h>
...@@ -28,7 +30,10 @@ ...@@ -28,7 +30,10 @@
28 #include <mailutils/cpp/mailcap.h> 30 #include <mailutils/cpp/mailcap.h>
29 #include <mailutils/cpp/mailer.h> 31 #include <mailutils/cpp/mailer.h>
30 #include <mailutils/cpp/message.h> 32 #include <mailutils/cpp/message.h>
33 #include <mailutils/cpp/mime.h>
34 #include <mailutils/cpp/mutil.h>
31 #include <mailutils/cpp/pop3.h> 35 #include <mailutils/cpp/pop3.h>
36 #include <mailutils/cpp/registrar.h>
32 #include <mailutils/cpp/stream.h> 37 #include <mailutils/cpp/stream.h>
33 #include <mailutils/cpp/url.h> 38 #include <mailutils/cpp/url.h>
34 39
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
23 23
24 #include <mailutils/message.h> 24 #include <mailutils/message.h>
25 #include <mailutils/cpp/header.h> 25 #include <mailutils/cpp/header.h>
26 #include <mailutils/cpp/body.h>
27 #include <mailutils/cpp/stream.h>
26 28
27 namespace mailutils 29 namespace mailutils
28 { 30 {
...@@ -31,14 +33,31 @@ class Message ...@@ -31,14 +33,31 @@ class Message
31 { 33 {
32 protected: 34 protected:
33 mu_message_t msg; 35 mu_message_t msg;
36 bool owner;
34 37
35 friend class Mailer; 38 friend class Mailer;
39 friend class Mime;
36 40
37 public: 41 public:
38 Message (); 42 Message ();
39 Message (const mu_message_t); 43 Message (const mu_message_t);
44 Message& operator = (const Message&);
45 ~Message ();
40 46
41 Header& getHeader (); 47 Header& get_header ();
48 Body& get_body ();
49 Stream& get_stream ();
50
51 bool is_multipart ();
52 size_t size ();
53 size_t lines ();
54 size_t get_num_parts ();
55 Message& get_part (const size_t npart);
56
57 void save_attachment ();
58 void save_attachment (const std::string& filename);
59 Message& unencapsulate ();
60 std::string get_attachment_name ();
42 }; 61 };
43 62
44 } 63 }
......
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_MIME_H
22 #define _MUCPP_MIME_H
23
24 #include <string>
25 #include <mailutils/mime.h>
26 #include <mailutils/cpp/message.h>
27
28 namespace mailutils
29 {
30
31 class Mime
32 {
33 protected:
34 mu_mime_t mime;
35
36 public:
37 Mime (const Message&, int);
38 Mime (const mu_mime_t);
39 ~Mime ();
40
41 bool is_multipart ();
42 size_t get_num_parts ();
43
44 Message& get_part (size_t part);
45 void add_part (const Message& msg);
46 Message& get_message ();
47 };
48
49 extern int rfc2047_decode (const char* tocode, const char* fromstr,
50 char** ptostr);
51 extern int rfc2047_encode (const char* charset, const char* encoding,
52 const char* text, char** result);
53
54 }
55
56 #endif // not _MUCPP_MIME_H
57
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_MUTIL_H
22 #define _MUCPP_MUTIL_H
23
24 #include <string>
25 #include <mailutils/filter.h>
26 #include <mailutils/mutil.h>
27
28 namespace mailutils
29 {
30
31 int set_user_email (const std::string& email);
32 int set_user_email_domain (const std::string& domain);
33 std::string tempname ();
34 std::string tempname (const std::string& tmpdir);
35
36 }
37
38 #endif // not _MUCPP_MUTIL_H
39
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _MUCPP_POP3_H 21 #ifndef _MUCPP_POP3_H
22 #define _MUCPP_POP3_H 22 #define _MUCPP_POP3_H
23 23
24 #include <iostream>
25 #include <mailutils/pop3.h> 24 #include <mailutils/pop3.h>
26 #include <mailutils/cpp/list.h> 25 #include <mailutils/cpp/list.h>
27 #include <mailutils/cpp/iterator.h> 26 #include <mailutils/cpp/iterator.h>
...@@ -41,30 +40,33 @@ class Pop3 ...@@ -41,30 +40,33 @@ class Pop3
41 Pop3 (const mu_pop3_t); 40 Pop3 (const mu_pop3_t);
42 ~Pop3 (); 41 ~Pop3 ();
43 42
44 void setCarrier (const Stream&); 43 void set_carrier (const Stream& carrier);
45 Stream& getCarrier (); 44 Stream& get_carrier ();
46 void connect (); 45 void connect ();
47 void disconnect (); 46 void disconnect ();
48 void setTimeout (int); 47 void set_timeout (int timeout);
49 int getTimeout (); 48 int get_timeout ();
50 49
50 void apop (const char* name, const char* digest);
51 void stls (); 51 void stls ();
52 Iterator& capa (); 52 Iterator& capa ();
53 void dele (unsigned int); 53 void dele (unsigned int msgno);
54 size_t list (unsigned int); 54 size_t list (unsigned int msgno);
55 Iterator& listAll (); 55 Iterator& list_all ();
56 void noop (); 56 void noop ();
57 void pass (const char*); 57 void pass (const char* pass);
58 void quit (); 58 void quit ();
59 Stream& retr (unsigned int); 59 Stream& retr (unsigned int msgno);
60 void rset (); 60 void rset ();
61 void stat (unsigned int*, size_t*); 61 void stat (unsigned int* count, size_t* octets);
62 Stream& top (unsigned int, unsigned int); 62 Stream& top (unsigned int msgno, unsigned int lines);
63 void user (const char*); 63 std::string uidl (unsigned int msgno);
64 Iterator& uidl_all ();
65 void user (const char* user);
64 66
65 size_t readLine (char*, size_t); 67 size_t readline (char* buf, size_t buflen);
66 size_t response (char*, size_t); 68 size_t response (char* buf, size_t buflen);
67 void sendLine (const char*); 69 void sendline (const char* line);
68 void send (); 70 void send ();
69 }; 71 };
70 72
......
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_REGISTRAR_H
22 #define _MUCPP_REGISTRAR_H
23
24 #include <mailutils/registrar.h>
25 #include <mailutils/cpp/url.h>
26
27 namespace mailutils
28 {
29
30 class Record
31 {
32 protected:
33 mu_record_t record;
34
35 public:
36 Record (const mu_record_t);
37 ~Record ();
38
39 // Defaults
40 int set_default_scheme (const std::string&);
41 std::string get_default_scheme ();
42 int get_default_record (mu_record_t* prec);
43 void set_default_record ();
44
45 // Registration
46 int registrar ();
47 int unregistrar ();
48 };
49
50 // Defaults
51 inline void
52 registrar_set_default_record (const mu_record_t record)
53 {
54 mu_registrar_set_default_record (record);
55 }
56
57 // Registration
58 inline int
59 registrar_record (const mu_record_t record)
60 {
61 return mu_registrar_record (record);
62 }
63
64 inline int
65 unregistrar_record (const mu_record_t record)
66 {
67 return mu_unregistrar_record (record);
68 }
69
70
71 inline void register_all_mbox_formats ()
72 {
73 mu_register_all_mbox_formats ();
74 }
75
76 inline void
77 register_local_mbox_formats ()
78 {
79 mu_register_local_mbox_formats ();
80 }
81
82 inline void
83 register_remote_mbox_formats ()
84 {
85 mu_register_remote_mbox_formats ();
86 }
87
88 inline void
89 register_all_mailer_formats ()
90 {
91 mu_register_all_mailer_formats ();
92 }
93
94 inline void
95 register_extra_formats ()
96 {
97 mu_register_extra_formats ();
98 }
99
100 inline void
101 register_all_formats ()
102 {
103 mu_register_all_formats ();
104 }
105
106 }
107
108 #endif // not _MUCPP_REGISTRAR_H
109
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,9 +21,7 @@ ...@@ -21,9 +21,7 @@
21 #ifndef _MUCPP_STREAM_H 21 #ifndef _MUCPP_STREAM_H
22 #define _MUCPP_STREAM_H 22 #define _MUCPP_STREAM_H
23 23
24 #include <iostream>
25 #include <string> 24 #include <string>
26 #include <cstdio>
27 #include <mailutils/stream.h> 25 #include <mailutils/stream.h>
28 #include <mailutils/cpp/error.h> 26 #include <mailutils/cpp/error.h>
29 27
...@@ -34,8 +32,8 @@ class Stream ...@@ -34,8 +32,8 @@ class Stream
34 { 32 {
35 protected: 33 protected:
36 mu_stream_t stm; 34 mu_stream_t stm;
37 size_t readn; 35 size_t read_count;
38 size_t writen; 36 size_t write_count;
39 int wflags; 37 int wflags;
40 bool opened; 38 bool opened;
41 size_t reference_count; 39 size_t reference_count;
...@@ -62,22 +60,22 @@ class Stream ...@@ -62,22 +60,22 @@ class Stream
62 60
63 void open (); 61 void open ();
64 void close (); 62 void close ();
65 void setWaitFlags (int); 63 void set_waitflags (int flags);
66 void wait (); // timeval is missing 64 void wait (); // timeval is missing
67 void wait (int); // timeval is missing 65 void wait (int flags); // timeval is missing
68 void read (char*, size_t, off_t); 66 int read (char* rbuf, size_t size, off_t offset);
69 void write (const std::string&, size_t, off_t); 67 int write (const std::string& wbuf, size_t size, off_t offset);
70 void readLine (char*, size_t, off_t); 68 int readline (char* rbuf, size_t size, off_t offset);
71 void sequentialReadLine (char*, size_t); 69 void sequential_readline (char* rbuf, size_t size);
72 void sequentialWrite (const std::string&, size_t); 70 void sequential_write (const std::string& wbuf, size_t size);
73 void flush (); 71 void flush ();
74 72
75 // Inlines 73 // Inlines
76 size_t getReadn () const { 74 size_t get_read_count () const {
77 return readn; 75 return read_count;
78 }; 76 };
79 size_t getWriten () const { 77 size_t get_write_count () const {
80 return writen; 78 return write_count;
81 }; 79 };
82 80
83 friend Stream& operator << (Stream&, const std::string&); 81 friend Stream& operator << (Stream&, const std::string&);
...@@ -86,7 +84,7 @@ class Stream ...@@ -86,7 +84,7 @@ class Stream
86 // Stream Exceptions 84 // Stream Exceptions
87 class EAgain : public Exception { 85 class EAgain : public Exception {
88 public: 86 public:
89 EAgain (const std::string& m, int s) : Exception (m, s) {} 87 EAgain (const char* m, int s) : Exception (m, s) {}
90 }; 88 };
91 }; 89 };
92 90
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
21 #ifndef _MUCPP_URL_H 21 #ifndef _MUCPP_URL_H
22 #define _MUCPP_URL_H 22 #define _MUCPP_URL_H
23 23
24 #include <iostream>
25 #include <string> 24 #include <string>
26 #include <vector> 25 #include <vector>
27 #include <mailutils/url.h> 26 #include <mailutils/url.h>
...@@ -44,14 +43,14 @@ class Url ...@@ -44,14 +43,14 @@ class Url
44 ~Url (); 43 ~Url ();
45 44
46 void parse (); 45 void parse ();
47 long getPort (); 46 long get_port ();
48 std::string getScheme (); 47 std::string get_scheme ();
49 std::string getUser (); 48 std::string get_user ();
50 std::string getPasswd (); 49 std::string get_passwd ();
51 std::string getAuth (); 50 std::string get_auth ();
52 std::string getHost (); 51 std::string get_host ();
53 std::string getPath (); 52 std::string get_path ();
54 std::vector<std::string> getQuery (); 53 std::vector<std::string> get_query ();
55 }; 54 };
56 55
57 } 56 }
......
1 ## Process this file with GNU Automake to create Makefile.in 1 ## Process this file with GNU Automake to create Makefile.in
2 ## 2 ##
3 ## Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 ## Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 ## 4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or 5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as 6 ## modify it under the terms of the GNU General Public License as
...@@ -25,6 +25,8 @@ EXTRA_LTLIBRARIES = $(MU_CXX_LIBS) ...@@ -25,6 +25,8 @@ EXTRA_LTLIBRARIES = $(MU_CXX_LIBS)
25 25
26 libmu_cpp_la_SOURCES = \ 26 libmu_cpp_la_SOURCES = \
27 address.cc\ 27 address.cc\
28 attribute.cc\
29 body.cc\
28 filter.cc\ 30 filter.cc\
29 header.cc\ 31 header.cc\
30 iterator.cc\ 32 iterator.cc\
...@@ -33,7 +35,10 @@ libmu_cpp_la_SOURCES = \ ...@@ -33,7 +35,10 @@ libmu_cpp_la_SOURCES = \
33 mailcap.cc\ 35 mailcap.cc\
34 mailer.cc\ 36 mailer.cc\
35 message.cc\ 37 message.cc\
38 mime.cc\
39 mutil.cc\
36 pop3.cc\ 40 pop3.cc\
41 registrar.cc\
37 stream.cc\ 42 stream.cc\
38 url.cc 43 url.cc
39 44
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -49,20 +49,20 @@ Address :: ~Address () ...@@ -49,20 +49,20 @@ Address :: ~Address ()
49 } 49 }
50 50
51 bool 51 bool
52 Address :: isGroup (size_t n) 52 Address :: is_group (size_t n)
53 { 53 {
54 int isgroup; 54 int isgroup;
55 int status = mu_address_is_group (addr, n, &isgroup); 55 int status = mu_address_is_group (addr, n, &isgroup);
56 if (status == EINVAL) 56 if (status == EINVAL)
57 throw Address::EInval ("Address::isGroup", status); 57 throw Address::EInval ("Address::is_group", status);
58 else if (status == ENOENT) 58 else if (status == ENOENT)
59 throw Address::ENoent ("Address::isGroup", status); 59 throw Address::ENoent ("Address::is_group", status);
60 60
61 return (bool) isgroup; 61 return (bool) isgroup;
62 } 62 }
63 63
64 size_t 64 size_t
65 Address :: getCount () 65 Address :: get_count ()
66 { 66 {
67 size_t count; 67 size_t count;
68 mu_address_get_count (addr, &count); 68 mu_address_get_count (addr, &count);
...@@ -70,73 +70,73 @@ Address :: getCount () ...@@ -70,73 +70,73 @@ Address :: getCount ()
70 } 70 }
71 71
72 std::string 72 std::string
73 Address :: getEmail (size_t n) 73 Address :: get_email (size_t n)
74 { 74 {
75 int status = mu_address_get_email (addr, n, buf, sizeof (buf), 0); 75 int status = mu_address_get_email (addr, n, buf, sizeof (buf), 0);
76 if (status == EINVAL) 76 if (status == EINVAL)
77 throw Address::EInval ("Address::getEmail", status); 77 throw Address::EInval ("Address::get_email", status);
78 else if (status == ENOENT) 78 else if (status == ENOENT)
79 throw Address::ENoent ("Address::getEmail", status); 79 throw Address::ENoent ("Address::get_email", status);
80 80
81 return std::string (buf); 81 return std::string (buf);
82 } 82 }
83 83
84 std::string 84 std::string
85 Address :: getLocalPart (size_t n) 85 Address :: get_local_part (size_t n)
86 { 86 {
87 int status = mu_address_get_local_part (addr, n, buf, sizeof (buf), 0); 87 int status = mu_address_get_local_part (addr, n, buf, sizeof (buf), 0);
88 if (status == EINVAL) 88 if (status == EINVAL)
89 throw Address::EInval ("Address::getLocalPart", status); 89 throw Address::EInval ("Address::get_local_part", status);
90 else if (status == ENOENT) 90 else if (status == ENOENT)
91 throw Address::ENoent ("Address::getLocalPart", status); 91 throw Address::ENoent ("Address::get_local_part", status);
92 92
93 return std::string (buf); 93 return std::string (buf);
94 } 94 }
95 95
96 std::string 96 std::string
97 Address :: getDomain (size_t n) 97 Address :: get_domain (size_t n)
98 { 98 {
99 int status = mu_address_get_domain (addr, n, buf, sizeof (buf), 0); 99 int status = mu_address_get_domain (addr, n, buf, sizeof (buf), 0);
100 if (status == EINVAL) 100 if (status == EINVAL)
101 throw Address::EInval ("Address::getDomain", status); 101 throw Address::EInval ("Address::get_domain", status);
102 else if (status == ENOENT) 102 else if (status == ENOENT)
103 throw Address::ENoent ("Address::getDomain", status); 103 throw Address::ENoent ("Address::get_domain", status);
104 104
105 return std::string (buf); 105 return std::string (buf);
106 } 106 }
107 107
108 std::string 108 std::string
109 Address :: getPersonal (size_t n) 109 Address :: get_personal (size_t n)
110 { 110 {
111 int status = mu_address_get_personal (addr, n, buf, sizeof (buf), 0); 111 int status = mu_address_get_personal (addr, n, buf, sizeof (buf), 0);
112 if (status == EINVAL) 112 if (status == EINVAL)
113 throw Address::EInval ("Address::getPersonal", status); 113 throw Address::EInval ("Address::get_personal", status);
114 else if (status == ENOENT) 114 else if (status == ENOENT)
115 throw Address::ENoent ("Address::getPersonal", status); 115 throw Address::ENoent ("Address::get_personal", status);
116 116
117 return std::string (buf); 117 return std::string (buf);
118 } 118 }
119 119
120 std::string 120 std::string
121 Address :: getComments (size_t n) 121 Address :: get_comments (size_t n)
122 { 122 {
123 int status = mu_address_get_comments (addr, n, buf, sizeof (buf), 0); 123 int status = mu_address_get_comments (addr, n, buf, sizeof (buf), 0);
124 if (status == EINVAL) 124 if (status == EINVAL)
125 throw Address::EInval ("Address::getComments", status); 125 throw Address::EInval ("Address::get_comments", status);
126 else if (status == ENOENT) 126 else if (status == ENOENT)
127 throw Address::ENoent ("Address::getComments", status); 127 throw Address::ENoent ("Address::get_comments", status);
128 128
129 return std::string (buf); 129 return std::string (buf);
130 } 130 }
131 131
132 std::string 132 std::string
133 Address :: getRoute (size_t n) 133 Address :: get_route (size_t n)
134 { 134 {
135 int status = mu_address_get_route (addr, n, buf, sizeof (buf), 0); 135 int status = mu_address_get_route (addr, n, buf, sizeof (buf), 0);
136 if (status == EINVAL) 136 if (status == EINVAL)
137 throw Address::EInval ("Address::getRoute", status); 137 throw Address::EInval ("Address::get_route", status);
138 else if (status == ENOENT) 138 else if (status == ENOENT)
139 throw Address::ENoent ("Address::getRoute", status); 139 throw Address::ENoent ("Address::get_route", status);
140 140
141 return std::string (buf); 141 return std::string (buf);
142 } 142 }
......
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/attribute.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24
25 using namespace mailutils;
26
27 //
28 // Attribute
29 //
30
31 Attribute :: Attribute ()
32 {
33 }
34
35 Attribute :: Attribute (const mu_attribute_t attr)
36 {
37 if (attr == 0)
38 throw Exception ("Attribute::Attribute", EINVAL);
39
40 this->attr = attr;
41 }
42
43 inline bool
44 Attribute :: is_modified ()
45 {
46 return (bool) mu_attribute_is_modified (attr);
47 }
48
49 inline void
50 Attribute :: clear_modified ()
51 {
52 mu_attribute_clear_modified (attr);
53 }
54
55 inline void
56 Attribute :: set_modified ()
57 {
58 mu_attribute_set_modified (attr);
59 }
60
61 //
62 // is_*
63 //
64
65 inline bool
66 Attribute :: is_userflag (int flag)
67 {
68 return (bool) mu_attribute_is_userflag (attr, flag);
69 }
70
71 inline bool
72 Attribute :: is_seen ()
73 {
74 return (bool) mu_attribute_is_seen (attr);
75 }
76
77 inline bool
78 Attribute :: is_answered () {
79 return (bool) mu_attribute_is_answered (attr);
80 }
81
82 inline bool
83 Attribute :: is_flagged ()
84 {
85 return (bool) mu_attribute_is_flagged (attr);
86 }
87
88 inline bool
89 Attribute :: is_deleted ()
90 {
91 return (bool) mu_attribute_is_deleted (attr);
92 }
93
94 inline bool
95 Attribute :: is_draft ()
96 {
97 return (bool) mu_attribute_is_draft (attr);
98 }
99
100 inline bool
101 Attribute :: is_recent ()
102 {
103 return (bool) mu_attribute_is_recent (attr);
104 }
105
106 inline bool
107 Attribute :: is_read ()
108 {
109 return (bool) mu_attribute_is_read (attr);
110 }
111
112 //
113 // set_*
114 //
115
116 inline void
117 Attribute :: set_userflag (int flag)
118 {
119 mu_attribute_set_userflag (attr, flag);
120 }
121
122 inline void
123 Attribute :: set_seen ()
124 {
125 mu_attribute_set_seen (attr);
126 }
127
128 inline void
129 Attribute :: set_answered ()
130 {
131 mu_attribute_set_answered (attr);
132 }
133
134 inline void
135 Attribute :: set_flagged ()
136 {
137 mu_attribute_set_flagged (attr);
138 }
139
140 inline void
141 Attribute :: set_deleted ()
142 {
143 mu_attribute_set_deleted (attr);
144 }
145
146 inline void
147 Attribute :: set_draft ()
148 {
149 mu_attribute_set_draft (attr);
150 }
151
152 inline void
153 Attribute :: set_recent ()
154 {
155 mu_attribute_set_recent (attr);
156 }
157
158 inline void
159 Attribute :: set_read ()
160 {
161 mu_attribute_set_read (attr);
162 }
163
164 //
165 // unset_*
166 //
167
168 inline void
169 Attribute :: unset_userflag (int flag)
170 {
171 mu_attribute_unset_userflag (attr, flag);
172 }
173
174 inline void
175 Attribute :: unset_seen ()
176 {
177 mu_attribute_unset_seen (attr);
178 }
179
180 inline void
181 Attribute :: unset_answered ()
182 {
183 mu_attribute_unset_answered (attr);
184 }
185
186 inline void
187 Attribute :: unset_flagged ()
188 {
189 mu_attribute_unset_flagged (attr);
190 }
191
192 inline void
193 Attribute :: unset_deleted ()
194 {
195 mu_attribute_unset_deleted (attr);
196 }
197
198 inline void
199 Attribute :: unset_draft ()
200 {
201 mu_attribute_unset_draft (attr);
202 }
203
204 inline void
205 Attribute :: unset_recent ()
206 {
207 mu_attribute_unset_recent (attr);
208 }
209
210 inline void
211 Attribute :: unset_read ()
212 {
213 mu_attribute_unset_read (attr);
214 }
215
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/body.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24
25 using namespace mailutils;
26
27 //
28 // Body
29 //
30
31 Body :: Body ()
32 {
33 int status = mu_body_create (&body, this);
34 if (status)
35 throw Exception ("Body::Body", status);
36
37 this->owner = true;
38 }
39
40 Body :: Body (const mu_body_t body)
41 {
42 if (body == 0)
43 throw Exception ("Body::Body", EINVAL);
44
45 this->body = body;
46 this->owner = false;
47 }
48
49 Body :: ~Body ()
50 {
51 if (this->owner)
52 mu_body_destroy (&body, this);
53 }
54
55 bool
56 Body :: is_modified ()
57 {
58 return (bool) mu_body_is_modified (body);
59 }
60
61 void
62 Body :: clear_modified ()
63 {
64 int status = mu_body_clear_modified (body);
65 if (status)
66 throw Exception ("Body::clear_modified", status);
67 }
68
69 Stream&
70 Body :: get_stream ()
71 {
72 mu_stream_t c_stream;
73
74 int status = mu_body_get_stream (body, &c_stream);
75 if (status)
76 throw Exception ("Body::get_stream", status);
77
78 return *new Stream (c_stream);
79 }
80
81 size_t
82 Body :: size ()
83 {
84 size_t c_size;
85 int status = mu_body_size (body, &c_size);
86 if (status)
87 throw Exception ("Body::size", status);
88 return c_size;
89 }
90
91 size_t
92 Body :: lines ()
93 {
94 size_t c_lines;
95 int status = mu_body_lines (body, &c_lines);
96 if (status)
97 throw Exception ("Body::lines", status);
98 return c_lines;
99 }
100
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -41,18 +41,18 @@ FilterStream :: create (Stream& transport, ...@@ -41,18 +41,18 @@ FilterStream :: create (Stream& transport,
41 } 41 }
42 42
43 void 43 void
44 FilterStream :: iconvCreate (Stream& transport, 44 FilterStream :: iconv_create (Stream& transport,
45 const std::string& fromcode, 45 const std::string& fromcode,
46 const std::string& tocode, 46 const std::string& tocode,
47 int flags, 47 int flags,
48 enum mu_iconv_fallback_mode fallback_mode) 48 enum mu_iconv_fallback_mode fallback_mode)
49 { 49 {
50 int status = mu_filter_iconv_create (&this->stm, transport.stm, 50 int status = mu_filter_iconv_create (&this->stm, transport.stm,
51 fromcode.c_str (), 51 fromcode.c_str (),
52 tocode.c_str (), 52 tocode.c_str (),
53 flags, fallback_mode); 53 flags, fallback_mode);
54 if (status) 54 if (status)
55 throw Exception ("FilterStream::iconvCreate", status); 55 throw Exception ("FilterStream::iconv_create", status);
56 this->input = new Stream (transport); 56 this->input = new Stream (transport);
57 } 57 }
58 58
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -41,22 +41,36 @@ Header :: Header (const mu_header_t hdr) ...@@ -41,22 +41,36 @@ Header :: Header (const mu_header_t hdr)
41 } 41 }
42 42
43 std::string 43 std::string
44 Header :: getValue (const std::string& name) 44 Header :: get_value (const std::string& name)
45 { 45 {
46 char* c_val; 46 char* c_val;
47 47
48 int status = mu_header_aget_value (hdr, name.c_str (), &c_val); 48 int status = mu_header_aget_value (hdr, name.c_str (), &c_val);
49 if (status) 49 if (status)
50 throw Exception ("Header::getValue", status); 50 throw Exception ("Header::get_value", status);
51 51
52 std::string val (c_val); 52 std::string val (c_val);
53 free (c_val); 53 free (c_val);
54 return val; 54 return val;
55 } 55 }
56 56
57 std::string 57 size_t
58 Header :: operator [] (const std::string& name) 58 Header :: size ()
59 {
60 size_t c_size;
61 int status = mu_header_size (hdr, &c_size);
62 if (status)
63 throw Exception ("Header::size", status);
64 return c_size;
65 }
66
67 size_t
68 Header :: lines ()
59 { 69 {
60 return this->getValue (name); 70 size_t c_lines;
71 int status = mu_header_lines (hdr, &c_lines);
72 if (status)
73 throw Exception ("Header::lines", status);
74 return c_lines;
61 } 75 }
62 76
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -51,6 +51,18 @@ Iterator :: ~Iterator () ...@@ -51,6 +51,18 @@ Iterator :: ~Iterator ()
51 mu_iterator_destroy (&mu_iter); 51 mu_iterator_destroy (&mu_iter);
52 } 52 }
53 53
54 bool
55 Iterator :: operator == (const Iterator& iter)
56 {
57 return mu_iter == iter.mu_iter;
58 }
59
60 bool
61 Iterator :: operator != (const Iterator& iter)
62 {
63 return mu_iter != iter.mu_iter;
64 }
65
54 void 66 void
55 Iterator :: first () 67 Iterator :: first ()
56 { 68 {
...@@ -91,16 +103,16 @@ Iterator :: current () ...@@ -91,16 +103,16 @@ Iterator :: current ()
91 } 103 }
92 104
93 bool 105 bool
94 Iterator :: isDone () 106 Iterator :: is_done ()
95 { 107 {
96 return (bool) mu_iterator_is_done (mu_iter); 108 return (bool) mu_iterator_is_done (mu_iter);
97 } 109 }
98 110
99 List& 111 List&
100 Iterator :: getList () 112 Iterator :: get_list ()
101 { 113 {
102 if (!pList) 114 if (!pList)
103 throw Exception ("Iterator::getList", ENOTSUP); 115 throw Exception ("Iterator::get_list", ENOTSUP);
104 return *pList; 116 return *pList;
105 } 117 }
106 118
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -108,18 +108,43 @@ List :: get (size_t index) ...@@ -108,18 +108,43 @@ List :: get (size_t index)
108 return pitem; 108 return pitem;
109 } 109 }
110 110
111 inline void*
112 List :: front ()
113 {
114 return this->get (0);
115 }
116
111 void* 117 void*
112 List :: operator [] (size_t index) 118 List :: back ()
119 {
120 size_t count = this->count ();
121 if (count)
122 return this->get (count - 1);
123 else
124 return NULL;
125 }
126
127 Iterator
128 List :: begin ()
113 { 129 {
114 return this->get (index); 130 mu_iterator_t mu_iter;
131 int status = mu_list_get_iterator (this->mu_list, &mu_iter);
132 if (status)
133 throw Exception ("Iterator::begin", status);
134
135 Iterator itr = Iterator (mu_iter);
136
137 this->iter = &itr;
138 this->iter->first ();
139 return itr;
115 } 140 }
116 141
117 void 142 void
118 List :: toArray (void** array, size_t count, size_t* pcount) 143 List :: to_array (void** array, size_t count, size_t* pcount)
119 { 144 {
120 int status = mu_list_to_array (mu_list, array, count, pcount); 145 int status = mu_list_to_array (mu_list, array, count, pcount);
121 if (status) 146 if (status)
122 throw Exception ("List::toArray", status); 147 throw Exception ("List::to_array", status);
123 } 148 }
124 149
125 void 150 void
...@@ -131,7 +156,7 @@ List :: locate (void* item, void** ret_item) ...@@ -131,7 +156,7 @@ List :: locate (void* item, void** ret_item)
131 } 156 }
132 157
133 bool 158 bool
134 List :: isEmpty () 159 List :: is_empty ()
135 { 160 {
136 return (bool) mu_list_is_empty (mu_list); 161 return (bool) mu_list_is_empty (mu_list);
137 } 162 }
...@@ -148,6 +173,12 @@ List :: count () ...@@ -148,6 +173,12 @@ List :: count ()
148 return count; 173 return count;
149 } 174 }
150 175
176 inline size_t
177 List :: size ()
178 {
179 return this->count ();
180 }
181
151 void 182 void
152 List :: apply (mu_list_action_t* action, void* cbdata) 183 List :: apply (mu_list_action_t* action, void* cbdata)
153 { 184 {
...@@ -157,16 +188,16 @@ List :: apply (mu_list_action_t* action, void* cbdata) ...@@ -157,16 +188,16 @@ List :: apply (mu_list_action_t* action, void* cbdata)
157 } 188 }
158 189
159 mu_list_comparator_t 190 mu_list_comparator_t
160 List :: setComparator (mu_list_comparator_t comp) 191 List :: set_comparator (mu_list_comparator_t comp)
161 { 192 {
162 return mu_list_set_comparator (mu_list, comp); 193 return mu_list_set_comparator (mu_list, comp);
163 } 194 }
164 195
165 void 196 void
166 List :: setDestroyItem (void (*mu_destroy_item) (void *item)) 197 List :: set_destroy_item (void (*mu_destroy_item) (void *item))
167 { 198 {
168 int status = mu_list_set_destroy_item (mu_list, mu_destroy_item); 199 int status = mu_list_set_destroy_item (mu_list, mu_destroy_item);
169 if (status) 200 if (status)
170 throw Exception ("List::setDestroyItem", status); 201 throw Exception ("List::set_destroy_item", status);
171 } 202 }
172 203
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -30,6 +30,14 @@ using namespace mailutils; ...@@ -30,6 +30,14 @@ using namespace mailutils;
30 // 30 //
31 31
32 void 32 void
33 MailboxBase :: open ()
34 {
35 int status = mu_mailbox_open (mbox, MU_STREAM_READ);
36 if (status)
37 throw Exception ("MailboxBase::open", status);
38 }
39
40 void
33 MailboxBase :: open (int flag) 41 MailboxBase :: open (int flag)
34 { 42 {
35 int status = mu_mailbox_open (mbox, flag); 43 int status = mu_mailbox_open (mbox, flag);
...@@ -46,7 +54,7 @@ MailboxBase :: close () ...@@ -46,7 +54,7 @@ MailboxBase :: close ()
46 } 54 }
47 55
48 size_t 56 size_t
49 MailboxBase :: messagesCount () 57 MailboxBase :: messages_count ()
50 { 58 {
51 size_t total; 59 size_t total;
52 mu_mailbox_messages_count (mbox, &total); 60 mu_mailbox_messages_count (mbox, &total);
...@@ -54,23 +62,17 @@ MailboxBase :: messagesCount () ...@@ -54,23 +62,17 @@ MailboxBase :: messagesCount ()
54 } 62 }
55 63
56 Message& 64 Message&
57 MailboxBase :: getMessage (size_t num) 65 MailboxBase :: get_message (size_t num)
58 { 66 {
59 mu_message_t c_msg; 67 mu_message_t c_msg;
60 68
61 int status = mu_mailbox_get_message (mbox, num, &c_msg); 69 int status = mu_mailbox_get_message (mbox, num, &c_msg);
62 if (status) 70 if (status)
63 throw Exception ("MailboxBase::getMessage", status); 71 throw Exception ("MailboxBase::get_message", status);
64 72
65 return *new Message (c_msg); 73 return *new Message (c_msg);
66 } 74 }
67 75
68 Message&
69 MailboxBase :: operator [] (size_t num)
70 {
71 return this->getMessage (num);
72 }
73
74 // 76 //
75 // Mailbox 77 // Mailbox
76 // 78 //
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -50,23 +50,23 @@ Mailcap :: ~Mailcap () ...@@ -50,23 +50,23 @@ Mailcap :: ~Mailcap ()
50 } 50 }
51 51
52 size_t 52 size_t
53 Mailcap :: getCount () 53 Mailcap :: entries_count ()
54 { 54 {
55 size_t count = 0; 55 size_t count = 0;
56 int status = mu_mailcap_entries_count (mailcap, &count); 56 int status = mu_mailcap_entries_count (mailcap, &count);
57 if (status) 57 if (status)
58 throw Exception ("Mailcap::getCount", status); 58 throw Exception ("Mailcap::entries_count", status);
59 return count; 59 return count;
60 } 60 }
61 61
62 MailcapEntry& 62 MailcapEntry&
63 Mailcap :: getEntry (size_t i) 63 Mailcap :: get_entry (size_t i)
64 { 64 {
65 mu_mailcap_entry_t c_entry; 65 mu_mailcap_entry_t c_entry;
66 66
67 int status = mu_mailcap_get_entry (mailcap, i, &c_entry); 67 int status = mu_mailcap_get_entry (mailcap, i, &c_entry);
68 if (status) 68 if (status)
69 throw Exception ("Mailcap::getEntry", status); 69 throw Exception ("Mailcap::get_entry", status);
70 70
71 MailcapEntry* entry = new MailcapEntry (c_entry); 71 MailcapEntry* entry = new MailcapEntry (c_entry);
72 return *entry; 72 return *entry;
...@@ -85,42 +85,42 @@ MailcapEntry :: MailcapEntry (mu_mailcap_entry_t entry) ...@@ -85,42 +85,42 @@ MailcapEntry :: MailcapEntry (mu_mailcap_entry_t entry)
85 } 85 }
86 86
87 size_t 87 size_t
88 MailcapEntry :: fieldsCount () 88 MailcapEntry :: fields_count ()
89 { 89 {
90 size_t count = 0; 90 size_t count = 0;
91 int status = mu_mailcap_entry_fields_count (entry, &count); 91 int status = mu_mailcap_entry_fields_count (entry, &count);
92 if (status) 92 if (status)
93 throw Exception ("MailcapEntry::fieldsCount", status); 93 throw Exception ("MailcapEntry::fields_count", status);
94 return count; 94 return count;
95 } 95 }
96 96
97 std::string 97 std::string
98 MailcapEntry :: getField (size_t i) 98 MailcapEntry :: get_field (size_t i)
99 { 99 {
100 int status = mu_mailcap_entry_get_field (entry, i, buf, 100 int status = mu_mailcap_entry_get_field (entry, i, buf,
101 sizeof (buf), NULL); 101 sizeof (buf), NULL);
102 if (status) 102 if (status)
103 throw Exception ("MailcapEntry::getField", status); 103 throw Exception ("MailcapEntry::get_field", status);
104 return std::string (buf); 104 return std::string (buf);
105 } 105 }
106 106
107 std::string 107 std::string
108 MailcapEntry :: getTypeField () 108 MailcapEntry :: get_typefield ()
109 { 109 {
110 int status = mu_mailcap_entry_get_typefield (entry, buf, 110 int status = mu_mailcap_entry_get_typefield (entry, buf,
111 sizeof (buf), NULL); 111 sizeof (buf), NULL);
112 if (status) 112 if (status)
113 throw Exception ("MailcapEntry::getTypeField", status); 113 throw Exception ("MailcapEntry::get_typefield", status);
114 return std::string (buf); 114 return std::string (buf);
115 } 115 }
116 116
117 std::string 117 std::string
118 MailcapEntry :: getViewCommand () 118 MailcapEntry :: get_viewcommand ()
119 { 119 {
120 int status = mu_mailcap_entry_get_viewcommand (entry, buf, 120 int status = mu_mailcap_entry_get_viewcommand (entry, buf,
121 sizeof (buf), NULL); 121 sizeof (buf), NULL);
122 if (status) 122 if (status)
123 throw Exception ("MailcapEntry::getViewCommand", status); 123 throw Exception ("MailcapEntry::get_viewcommand", status);
124 return std::string (buf); 124 return std::string (buf);
125 } 125 }
126 126
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -64,12 +64,12 @@ Mailer :: close () ...@@ -64,12 +64,12 @@ Mailer :: close ()
64 } 64 }
65 65
66 void 66 void
67 Mailer :: sendMessage (const Message& msg, const Address& from, 67 Mailer :: send_message (const Message& msg, const Address& from,
68 const Address& to) 68 const Address& to)
69 { 69 {
70 int status = mu_mailer_send_message (mailer, msg.msg, 70 int status = mu_mailer_send_message (mailer, msg.msg,
71 from.addr, to.addr); 71 from.addr, to.addr);
72 if (status) 72 if (status)
73 throw Exception ("Mailer::sendMessage", status); 73 throw Exception ("Mailer::send_message", status);
74 } 74 }
75 75
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
20 20
21 #include <mailutils/cpp/message.h> 21 #include <mailutils/cpp/message.h>
22 #include <mailutils/cpp/header.h> 22 #include <mailutils/cpp/header.h>
23 #include <mailutils/cpp/body.h>
24 #include <mailutils/cpp/stream.h>
23 #include <mailutils/cpp/error.h> 25 #include <mailutils/cpp/error.h>
24 #include <errno.h> 26 #include <errno.h>
25 27
...@@ -30,7 +32,12 @@ using namespace mailutils; ...@@ -30,7 +32,12 @@ using namespace mailutils;
30 // 32 //
31 33
32 Message :: Message () 34 Message :: Message ()
33 { 35 {
36 int status = mu_message_create (&msg, this);
37 if (status)
38 throw Exception ("Message::Message", status);
39
40 this->owner = true;
34 } 41 }
35 42
36 Message :: Message (const mu_message_t msg) 43 Message :: Message (const mu_message_t msg)
...@@ -39,17 +46,161 @@ Message :: Message (const mu_message_t msg) ...@@ -39,17 +46,161 @@ Message :: Message (const mu_message_t msg)
39 throw Exception ("Message::Message", EINVAL); 46 throw Exception ("Message::Message", EINVAL);
40 47
41 this->msg = msg; 48 this->msg = msg;
49 this->owner = false;
50 }
51
52 Message&
53 Message :: operator = (const Message& m)
54 {
55 if (this != &m)
56 {
57 if (this->owner)
58 mu_message_destroy (&this->msg, this);
59
60 int status = mu_message_create_copy (&this->msg, m.msg);
61 if (status)
62 throw Exception ("Message::operator=", status);
63
64 this->owner = true;
65 }
66 return *this;
67 }
68
69 Message :: ~Message ()
70 {
71 if (this->owner)
72 mu_message_destroy (&msg, this);
42 } 73 }
43 74
44 Header& 75 Header&
45 Message :: getHeader () 76 Message :: get_header ()
46 { 77 {
47 mu_header_t c_hdr; 78 mu_header_t c_hdr;
48 79
49 int status = mu_message_get_header (msg, &c_hdr); 80 int status = mu_message_get_header (msg, &c_hdr);
50 if (status) 81 if (status)
51 throw Exception ("Message::getHeader", status); 82 throw Exception ("Message::get_header", status);
52 83
53 return *new Header (c_hdr); 84 return *new Header (c_hdr);
54 } 85 }
55 86
87 Body&
88 Message :: get_body ()
89 {
90 mu_body_t c_body;
91
92 int status = mu_message_get_body (msg, &c_body);
93 if (status)
94 throw Exception ("Message::get_body", status);
95
96 return *new Body (c_body);
97 }
98
99 Stream&
100 Message :: get_stream ()
101 {
102 mu_stream_t c_stream;
103
104 int status = mu_message_get_stream (msg, &c_stream);
105 if (status)
106 throw Exception ("Message::get_stream", status);
107
108 return *new Stream (c_stream);
109 }
110
111 bool
112 Message :: is_multipart ()
113 {
114 int pmulti;
115 int status = mu_message_is_multipart (msg, &pmulti);
116 if (status)
117 throw Exception ("Message::is_multipart", status);
118 return (bool) pmulti;
119 }
120
121 size_t
122 Message :: size ()
123 {
124 size_t c_size;
125 int status = mu_message_size (msg, &c_size);
126 if (status)
127 throw Exception ("Message::size", status);
128 return c_size;
129 }
130
131 size_t
132 Message :: lines ()
133 {
134 size_t c_lines;
135 int status = mu_message_lines (msg, &c_lines);
136 if (status)
137 throw Exception ("Message::lines", status);
138 return c_lines;
139 }
140
141 size_t
142 Message :: get_num_parts ()
143 {
144 size_t c_parts;
145 int status = mu_message_get_num_parts (msg, &c_parts);
146 if (status)
147 throw Exception ("Message::get_num_parts", status);
148 return c_parts;
149 }
150
151 Message&
152 Message :: get_part (const size_t npart)
153 {
154 mu_message_t c_part;
155
156 int status = mu_message_get_part (msg, npart, &c_part);
157 if (status)
158 throw Exception ("Message::get_part", status);
159
160 return *new Message (c_part);
161 }
162
163 void
164 Message :: save_attachment ()
165 {
166 int status = mu_message_save_attachment (msg, NULL, NULL);
167 if (status)
168 throw Exception ("Message::save_attachment", status);
169 }
170
171 void
172 Message :: save_attachment (const std::string& filename)
173 {
174 int status = mu_message_save_attachment (msg, filename.c_str (), NULL);
175 if (status)
176 throw Exception ("Message::save_attachment", status);
177 }
178
179 Message&
180 Message :: unencapsulate ()
181 {
182 mu_message_t c_msg;
183
184 int status = mu_message_unencapsulate (msg, &c_msg, NULL);
185 if (status)
186 throw Exception ("Message::unencapsulate", status);
187
188 return *new Message (c_msg);
189 }
190
191 std::string
192 Message :: get_attachment_name ()
193 {
194 char *c_name;
195 std::string name;
196
197 int status = mu_message_aget_attachment_name (msg, &c_name);
198 if (status)
199 throw Exception ("Message::get_attachment_name", status);
200 if (c_name) {
201 name = c_name;
202 free (c_name);
203 }
204 return name;
205 }
206
......
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/mime.h>
22 #include <mailutils/cpp/error.h>
23 #include <errno.h>
24
25 using namespace mailutils;
26
27 //
28 // Mime
29 //
30
31 Mime :: Mime (const Message& msg, int flags)
32 {
33 int status = mu_mime_create (&mime, msg.msg, flags);
34 if (status)
35 throw Exception ("Mime::Mime", status);
36 }
37
38 Mime :: Mime (const mu_mime_t mime)
39 {
40 if (mime == 0)
41 throw Exception ("Mime::Mime", EINVAL);
42
43 this->mime = mime;
44 }
45
46 Mime :: ~Mime ()
47 {
48 mu_mime_destroy (&mime);
49 }
50
51 bool
52 Mime :: is_multipart ()
53 {
54 return (bool) mu_mime_is_multipart (mime);
55 }
56
57 size_t
58 Mime :: get_num_parts ()
59 {
60 size_t nparts;
61
62 int status = mu_mime_get_num_parts (mime, &nparts);
63 if (status)
64 throw Exception ("Mime::get_num_parts", status);
65 return nparts;
66 }
67
68 Message&
69 Mime :: get_part (size_t part)
70 {
71 mu_message_t c_msg;
72
73 int status = mu_mime_get_part (mime, part, &c_msg);
74 if (status)
75 throw Exception ("Mime::get_part", status);
76
77 return *new Message (c_msg);
78 }
79
80 void
81 Mime :: add_part (const Message& msg)
82 {
83 int status = mu_mime_add_part (mime, msg.msg);
84 if (status)
85 throw Exception ("Mime::add_part", status);
86 }
87
88 Message&
89 Mime :: get_message ()
90 {
91 mu_message_t c_msg;
92
93 int status = mu_mime_get_message (mime, &c_msg);
94 if (status)
95 throw Exception ("Mime::get_message", status);
96
97 return *new Message (c_msg);
98 }
99
100 inline int
101 rfc2047_decode (const char *tocode, const char *fromstr, char **ptostr)
102 {
103 return mu_rfc2047_decode (tocode, fromstr, ptostr);
104 }
105
106 inline int
107 rfc2047_encode (const char *charset, const char *encoding,
108 const char *text, char **result)
109 {
110 return mu_rfc2047_encode (charset, encoding, text, result);
111 }
112
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 <string>
22 #include <mailutils/cpp/mutil.h>
23
24 using namespace mailutils;
25
26 //
27 // MUtil
28 //
29
30 int
31 mailutils :: set_user_email (const std::string& str)
32 {
33 return mu_set_user_email (str.c_str ());
34 }
35
36 int
37 mailutils :: set_user_email_domain (const std::string& str)
38 {
39 return mu_set_user_email_domain (str.c_str ());
40 }
41
42 std::string
43 mailutils :: tempname ()
44 {
45 std::string name;
46 char *c_str = mu_tempname (NULL);
47 if (c_str) {
48 name = c_str;
49 free (c_str);
50 }
51 return name;
52 }
53
54 std::string
55 mailutils :: tempname (const std::string& tmpdir)
56 {
57 std::string name;
58 char *c_str = mu_tempname (tmpdir.c_str ());
59 if (c_str) {
60 name = c_str;
61 free (c_str);
62 }
63 return name;
64 }
65
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -52,17 +52,17 @@ Pop3 :: ~Pop3 () ...@@ -52,17 +52,17 @@ Pop3 :: ~Pop3 ()
52 } 52 }
53 53
54 void 54 void
55 Pop3 :: setCarrier (const Stream& carrier) 55 Pop3 :: set_carrier (const Stream& carrier)
56 { 56 {
57 int status = mu_pop3_set_carrier (pop3, carrier.stm); 57 int status = mu_pop3_set_carrier (pop3, carrier.stm);
58 if (status) 58 if (status)
59 throw Exception ("Pop3::setCarrier", status); 59 throw Exception ("Pop3::set_carrier", status);
60 60
61 this->pStream = (Stream*) &carrier; 61 this->pStream = (Stream*) &carrier;
62 } 62 }
63 63
64 Stream& 64 Stream&
65 Pop3 :: getCarrier () 65 Pop3 :: get_carrier ()
66 { 66 {
67 return *pStream; 67 return *pStream;
68 } 68 }
...@@ -84,26 +84,34 @@ Pop3 :: disconnect () ...@@ -84,26 +84,34 @@ Pop3 :: disconnect ()
84 } 84 }
85 85
86 void 86 void
87 Pop3 :: setTimeout (int timeout) 87 Pop3 :: set_timeout (int timeout)
88 { 88 {
89 int status = mu_pop3_set_timeout (pop3, timeout); 89 int status = mu_pop3_set_timeout (pop3, timeout);
90 if (status) 90 if (status)
91 throw Exception ("Pop3::setTimeout", status); 91 throw Exception ("Pop3::set_timeout", status);
92 } 92 }
93 93
94 int 94 int
95 Pop3 :: getTimeout () 95 Pop3 :: get_timeout ()
96 { 96 {
97 int timeout; 97 int timeout;
98 98
99 int status = mu_pop3_get_timeout (pop3, &timeout); 99 int status = mu_pop3_get_timeout (pop3, &timeout);
100 if (status) 100 if (status)
101 throw Exception ("Pop3::getTimeout", status); 101 throw Exception ("Pop3::get_timeout", status);
102 102
103 return timeout; 103 return timeout;
104 } 104 }
105 105
106 void 106 void
107 Pop3 :: apop (const char* name, const char* digest)
108 {
109 int status = mu_pop3_apop (pop3, name, digest);
110 if (status)
111 throw Exception ("Pop3::apop", status);
112 }
113
114 void
107 Pop3 :: stls () 115 Pop3 :: stls ()
108 { 116 {
109 int status = mu_pop3_stls (pop3); 117 int status = mu_pop3_stls (pop3);
...@@ -144,13 +152,13 @@ Pop3 :: list (unsigned int msgno) ...@@ -144,13 +152,13 @@ Pop3 :: list (unsigned int msgno)
144 } 152 }
145 153
146 Iterator& 154 Iterator&
147 Pop3 :: listAll () 155 Pop3 :: list_all ()
148 { 156 {
149 mu_iterator_t mu_itr; 157 mu_iterator_t mu_itr;
150 158
151 int status = mu_pop3_list_all (pop3, &mu_itr); 159 int status = mu_pop3_list_all (pop3, &mu_itr);
152 if (status) 160 if (status)
153 throw Exception ("Pop3::listAll", status); 161 throw Exception ("Pop3::list_all", status);
154 162
155 return *new Iterator (mu_itr); 163 return *new Iterator (mu_itr);
156 } 164 }
...@@ -219,6 +227,35 @@ Pop3 :: top (unsigned int msgno, unsigned int lines) ...@@ -219,6 +227,35 @@ Pop3 :: top (unsigned int msgno, unsigned int lines)
219 return *new Stream (c_stm); 227 return *new Stream (c_stm);
220 } 228 }
221 229
230 std::string
231 Pop3 :: uidl (unsigned int msgno)
232 {
233 char *c_uidl = NULL;
234
235 int status = mu_pop3_uidl (pop3, msgno, &c_uidl);
236 if (status)
237 throw Exception ("Pop3::uidl", status);
238
239 if (c_uidl) {
240 std::string uidl (c_uidl);
241 free (c_uidl);
242 return uidl;
243 }
244 return NULL;
245 }
246
247 Iterator&
248 Pop3 :: uidl_all ()
249 {
250 mu_iterator_t mu_itr;
251
252 int status = mu_pop3_uidl_all (pop3, &mu_itr);
253 if (status)
254 throw Exception ("Pop3::uidl_all", status);
255
256 return *new Iterator (mu_itr);
257 }
258
222 void 259 void
223 Pop3 :: user (const char* user) 260 Pop3 :: user (const char* user)
224 { 261 {
...@@ -228,13 +265,13 @@ Pop3 :: user (const char* user) ...@@ -228,13 +265,13 @@ Pop3 :: user (const char* user)
228 } 265 }
229 266
230 size_t 267 size_t
231 Pop3 :: readLine (char* buf, size_t buflen) 268 Pop3 :: readline (char* buf, size_t buflen)
232 { 269 {
233 size_t nread; 270 size_t nread;
234 271
235 int status = mu_pop3_readline (pop3, buf, buflen, &nread); 272 int status = mu_pop3_readline (pop3, buf, buflen, &nread);
236 if (status) 273 if (status)
237 throw Exception ("Pop3::readLine", status); 274 throw Exception ("Pop3::readline", status);
238 } 275 }
239 276
240 size_t 277 size_t
...@@ -248,11 +285,11 @@ Pop3 :: response (char* buf, size_t buflen) ...@@ -248,11 +285,11 @@ Pop3 :: response (char* buf, size_t buflen)
248 } 285 }
249 286
250 void 287 void
251 Pop3 :: sendLine (const char* line) 288 Pop3 :: sendline (const char* line)
252 { 289 {
253 int status = mu_pop3_sendline (pop3, line); 290 int status = mu_pop3_sendline (pop3, line);
254 if (status) 291 if (status)
255 throw Exception ("Pop3::sendLine", status); 292 throw Exception ("Pop3::sendline", status);
256 } 293 }
257 294
258 void 295 void
......
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 <string>
22 #include <mailutils/cpp/registrar.h>
23 #include <mailutils/cpp/error.h>
24 #include <errno.h>
25
26 using namespace mailutils;
27
28 //
29 // Registrar
30 //
31
32 Record :: Record (const mu_record_t record)
33 {
34 if (record == 0)
35 throw Exception ("Record::Record", EINVAL);
36
37 this->record = record;
38 }
39
40 Record :: ~Record ()
41 {
42 }
43
44 // Record Class Defaults
45 int
46 Record :: set_default_scheme (const std::string& scheme)
47 {
48 return mu_registrar_set_default_scheme (scheme.c_str ());
49 }
50
51 std::string
52 Record :: get_default_scheme ()
53 {
54 return std::string (mu_registrar_get_default_scheme ());
55 }
56
57 int
58 Record :: get_default_record (mu_record_t* prec)
59 {
60 return mu_registrar_get_default_record (prec);
61 }
62
63 void
64 Record :: set_default_record ()
65 {
66 mailutils::registrar_set_default_record (this->record);
67 }
68
69 // Record Class Registration
70 int
71 Record :: registrar ()
72 {
73 return mailutils::registrar_record (this->record);
74 }
75
76 int
77 Record :: unregistrar ()
78 {
79 return mailutils::unregistrar_record (this->record);
80 }
81
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -86,7 +86,7 @@ Stream :: close () ...@@ -86,7 +86,7 @@ Stream :: close ()
86 } 86 }
87 87
88 void 88 void
89 Stream :: setWaitFlags (int flags) 89 Stream :: set_waitflags (int flags)
90 { 90 {
91 this->wflags = flags; 91 this->wflags = flags;
92 } 92 }
...@@ -108,50 +108,54 @@ Stream :: wait (int flags) ...@@ -108,50 +108,54 @@ Stream :: wait (int flags)
108 throw Exception ("Stream::wait", status); 108 throw Exception ("Stream::wait", status);
109 } 109 }
110 110
111 void 111 int
112 Stream :: read (char* rbuf, size_t size, off_t offset) 112 Stream :: read (char* rbuf, size_t size, off_t offset)
113 { 113 {
114 int status = mu_stream_read (stm, rbuf, size, offset, &readn); 114 int status = mu_stream_read (stm, rbuf, size, offset, &read_count);
115 if (status == EAGAIN) 115 if (status == EAGAIN)
116 throw Stream::EAgain ("Stream::read", status); 116 throw Stream::EAgain ("Stream::read", status);
117 else if (status) 117 else if (status)
118 throw Exception ("Stream::read", status); 118 throw Exception ("Stream::read", status);
119 return status;
119 } 120 }
120 121
121 void 122 int
122 Stream :: write (const std::string& wbuf, size_t size, off_t offset) 123 Stream :: write (const std::string& wbuf, size_t size, off_t offset)
123 { 124 {
124 int status = mu_stream_write (stm, wbuf.c_str (), size, offset, &writen); 125 int status = mu_stream_write (stm, wbuf.c_str (), size, offset,
126 &write_count);
125 if (status == EAGAIN) 127 if (status == EAGAIN)
126 throw Stream::EAgain ("Stream::write", status); 128 throw Stream::EAgain ("Stream::write", status);
127 else if (status) 129 else if (status)
128 throw Exception ("Stream::write", status); 130 throw Exception ("Stream::write", status);
131 return status;
129 } 132 }
130 133
131 void 134 int
132 Stream :: readLine (char* rbuf, size_t size, off_t offset) 135 Stream :: readline (char* rbuf, size_t size, off_t offset)
133 { 136 {
134 int status = mu_stream_readline (stm, rbuf, size, offset, &readn); 137 int status = mu_stream_readline (stm, rbuf, size, offset, &read_count);
135 if (status == EAGAIN) 138 if (status == EAGAIN)
136 throw Stream::EAgain ("Stream::readLine", status); 139 throw Stream::EAgain ("Stream::readline", status);
137 else if (status) 140 else if (status)
138 throw Exception ("Stream::readLine", status); 141 throw Exception ("Stream::readline", status);
142 return status;
139 } 143 }
140 144
141 void 145 void
142 Stream :: sequentialReadLine (char* rbuf, size_t size) 146 Stream :: sequential_readline (char* rbuf, size_t size)
143 { 147 {
144 int status = mu_stream_sequential_readline (stm, rbuf, size, &readn); 148 int status = mu_stream_sequential_readline (stm, rbuf, size, &read_count);
145 if (status) 149 if (status)
146 throw Exception ("Stream::sequentialReadLine", status); 150 throw Exception ("Stream::sequential_readline", status);
147 } 151 }
148 152
149 void 153 void
150 Stream :: sequentialWrite (const std::string& wbuf, size_t size) 154 Stream :: sequential_write (const std::string& wbuf, size_t size)
151 { 155 {
152 int status = mu_stream_sequential_write (stm, wbuf.c_str (), size); 156 int status = mu_stream_sequential_write (stm, wbuf.c_str (), size);
153 if (status) 157 if (status)
154 throw Exception ("Stream::sequentialWrite", status); 158 throw Exception ("Stream::sequential_write", status);
155 } 159 }
156 160
157 void 161 void
......
1 /* 1 /*
2 GNU Mailutils -- a suite of utilities for electronic mail 2 GNU Mailutils -- a suite of utilities for electronic mail
3 Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
...@@ -64,90 +64,90 @@ Url :: parse () ...@@ -64,90 +64,90 @@ Url :: parse ()
64 } 64 }
65 65
66 long 66 long
67 Url :: getPort () 67 Url :: get_port ()
68 { 68 {
69 long port; 69 long port;
70 int status = mu_url_get_port (url, &port); 70 int status = mu_url_get_port (url, &port);
71 if (status) 71 if (status)
72 throw Exception ("Url::getPort", status); 72 throw Exception ("Url::get_port", status);
73 return port; 73 return port;
74 } 74 }
75 75
76 std::string 76 std::string
77 Url :: getScheme () 77 Url :: get_scheme ()
78 { 78 {
79 int status = mu_url_get_scheme (url, buf, sizeof (buf), NULL); 79 int status = mu_url_get_scheme (url, buf, sizeof (buf), NULL);
80 if (status == MU_ERR_NOENT) 80 if (status == MU_ERR_NOENT)
81 return ""; 81 return "";
82 else if (status) 82 else if (status)
83 throw Exception ("Url::getScheme", status); 83 throw Exception ("Url::get_scheme", status);
84 return std::string (buf); 84 return std::string (buf);
85 } 85 }
86 86
87 std::string 87 std::string
88 Url :: getUser () 88 Url :: get_user ()
89 { 89 {
90 int status = mu_url_get_user (url, buf, sizeof (buf), NULL); 90 int status = mu_url_get_user (url, buf, sizeof (buf), NULL);
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::getUser", status); 94 throw Exception ("Url::get_user", status);
95 return std::string (buf); 95 return std::string (buf);
96 } 96 }
97 97
98 std::string 98 std::string
99 Url :: getPasswd () 99 Url :: get_passwd ()
100 { 100 {
101 int status = mu_url_get_passwd (url, buf, sizeof (buf), NULL); 101 int status = mu_url_get_passwd (url, buf, sizeof (buf), NULL);
102 if (status == MU_ERR_NOENT) 102 if (status == MU_ERR_NOENT)
103 return ""; 103 return "";
104 else if (status) 104 else if (status)
105 throw Exception ("Url::getPasswd", status); 105 throw Exception ("Url::get_passwd", status);
106 return std::string (buf); 106 return std::string (buf);
107 } 107 }
108 108
109 std::string 109 std::string
110 Url :: getAuth () 110 Url :: get_auth ()
111 { 111 {
112 int status = mu_url_get_auth (url, buf, sizeof (buf), NULL); 112 int status = mu_url_get_auth (url, buf, sizeof (buf), NULL);
113 if (status == MU_ERR_NOENT) 113 if (status == MU_ERR_NOENT)
114 return ""; 114 return "";
115 else if (status) 115 else if (status)
116 throw Exception ("Url::getAuth", status); 116 throw Exception ("Url::get_auth", status);
117 return std::string (buf); 117 return std::string (buf);
118 } 118 }
119 119
120 std::string 120 std::string
121 Url :: getHost () 121 Url :: get_host ()
122 { 122 {
123 int status = mu_url_get_host (url, buf, sizeof (buf), NULL); 123 int status = mu_url_get_host (url, buf, sizeof (buf), NULL);
124 if (status == MU_ERR_NOENT) 124 if (status == MU_ERR_NOENT)
125 return ""; 125 return "";
126 else if (status) 126 else if (status)
127 throw Exception ("Url::getHost", status); 127 throw Exception ("Url::get_host", status);
128 return std::string (buf); 128 return std::string (buf);
129 } 129 }
130 130
131 std::string 131 std::string
132 Url :: getPath () 132 Url :: get_path ()
133 { 133 {
134 int status = mu_url_get_path (url, buf, sizeof (buf), NULL); 134 int status = mu_url_get_path (url, buf, sizeof (buf), NULL);
135 if (status == MU_ERR_NOENT) 135 if (status == MU_ERR_NOENT)
136 return ""; 136 return "";
137 else if (status) 137 else if (status)
138 throw Exception ("Url::getPath", status); 138 throw Exception ("Url::get_path", status);
139 return std::string (buf); 139 return std::string (buf);
140 } 140 }
141 141
142 std::vector<std::string> 142 std::vector<std::string>
143 Url :: getQuery () 143 Url :: get_query ()
144 { 144 {
145 size_t argc; 145 size_t argc;
146 char **argv; 146 char **argv;
147 147
148 int status = mu_url_sget_query (url, &argc, &argv); 148 int status = mu_url_sget_query (url, &argc, &argv);
149 if (status) 149 if (status)
150 throw Exception ("Url::getQuery", status); 150 throw Exception ("Url::get_query", status);
151 151
152 std::vector<std::string> params; 152 std::vector<std::string> params;
153 153
......