53
53
# include < gmime/gmime.h>
54
54
# include < utils/gmime/gmime-compat.h>
55
55
56
- # include < libsoup/soup.h>
57
-
58
56
using namespace std ;
59
57
using namespace boost ::filesystem;
60
58
@@ -126,7 +124,7 @@ namespace Astroid {
126
124
# ifdef DEBUG
127
125
( " test-config,t" , " use test config (same as used when tests are run), only makes sense from the source root" )
128
126
# endif
129
- ( " mailto,m" , po::value<ustring>(), " compose mail with mailto url or address" )
127
+ ( " mailto,m" , po::value< vector< ustring> >()-> composing (), " compose mail with mailto url or address" )
130
128
( " no-auto-poll" , " do not poll automatically" )
131
129
( " disable-log" , " disable logging" )
132
130
( " log-stdout" , " log to stdout regardless of configuration" )
@@ -139,6 +137,9 @@ namespace Astroid {
139
137
# else
140
138
;
141
139
# endif
140
+
141
+ /* default option (without --<option> prefix) */
142
+ pdesc.add (" mailto" , -1 );
142
143
}
143
144
// }}}
144
145
@@ -153,7 +154,11 @@ namespace Astroid {
153
154
bool show_help = false ;
154
155
155
156
try {
156
- po::store ( po::parse_command_line (argc, argv, desc), vm );
157
+ po::store ( po::command_line_parser (argc, argv).
158
+ options (desc).
159
+ positional (pdesc).
160
+ run (),
161
+ vm );
157
162
} catch (po::unknown_option &ex) {
158
163
LOG (error) << " unknown option" << endl;
159
164
LOG (error) << ex.what () << endl;
@@ -438,16 +443,40 @@ namespace Astroid {
438
443
po::variables_map vm;
439
444
440
445
try {
441
- po::store ( po::parse_command_line (argc, argv, desc), vm );
446
+ po::store ( po::command_line_parser (argc, argv).
447
+ options (desc).
448
+ positional (pdesc).
449
+ run (),
450
+ vm );
442
451
} catch (po::unknown_option &ex) {
443
452
LOG (error) << " unknown option" << endl;
444
453
LOG (error) << ex.what () << endl;
445
454
return 1 ;
446
455
}
447
456
448
457
if (vm.count (" mailto" )) {
449
- ustring mailtourl = vm[" mailto" ].as <ustring>();
450
- send_mailto (mailtourl);
458
+ vector <ustring> mailto_list = vm[" mailto" ].as <vector <ustring>>();
459
+
460
+ // is the conversion from ustring to std::string really safe?
461
+ std::string mailto = " " ;
462
+ std::string next;
463
+
464
+ ustring::size_type sep;
465
+
466
+ for (std::vector<ustring>::size_type i = 0 ; i < mailto_list.size (); i++) {
467
+ next = mailto_list[i];
468
+ sep = next.find (" ?" );
469
+ if (sep != next.npos )
470
+ next[sep] = ' &' ;
471
+ if (next.substr (0 , 7 ) == " mailto:" )
472
+ next.erase (0 ,7 );
473
+ mailto += " &to=" + next;
474
+ }
475
+
476
+ mailto[0 ] = ' ?' ;
477
+ mailto.insert (0 , " mailto:" );
478
+
479
+ send_mailto (mailto);
451
480
new_window = false ;
452
481
}
453
482
@@ -545,53 +574,11 @@ namespace Astroid {
545
574
open_new_window ();
546
575
}
547
576
548
- void Astroid::send_mailto (ustring url ) {
549
- LOG (info) << " astroid: mailto: " << url ;
577
+ void Astroid::send_mailto (ustring uri ) {
578
+ LOG (info) << " astroid: mailto: " << uri ;
550
579
551
580
MainWindow * mw = (MainWindow*) get_windows ()[0 ];
552
-
553
- SoupURI *uri = soup_uri_new (url.c_str ());
554
-
555
- if (SOUP_URI_IS_VALID (uri)) {
556
- /* we got an mailto url */
557
- ustring from, to, cc, bcc, subject, body;
558
-
559
- to = soup_uri_decode (soup_uri_get_path (uri));
560
-
561
- const char * soup_query = soup_uri_get_query (uri);
562
- if (soup_query) {
563
- std::istringstream query_string (soup_query);
564
- std::string keyval;
565
- while (std::getline (query_string, keyval, ' &' )) {
566
- ustring::size_type pos = keyval.find (" =" );
567
-
568
- ustring key = keyval.substr (0 , pos);
569
- key = key.lowercase ();
570
-
571
- ustring val = soup_uri_decode (keyval.substr (pos+1 ).c_str ());
572
-
573
- if (key == " from" ) {
574
- from = ustring (val);
575
- } else if (key == " cc" ) {
576
- cc = ustring (val);
577
- } else if (key == " bcc" ) {
578
- bcc = ustring (val);
579
- } else if (key == " subject" ) {
580
- subject = ustring (val);
581
- } else if (key == " body" ) {
582
- body = ustring (val);
583
- }
584
- }
585
- }
586
-
587
- mw->add_mode (new EditMessage (mw, to, from, cc, bcc, subject, body));
588
-
589
- } else {
590
- /* we probably just got the address on the cmd line */
591
- mw->add_mode (new EditMessage (mw, url));
592
- }
593
-
594
- soup_uri_free (uri);
581
+ mw->add_mode (new EditMessage (mw, uri));
595
582
}
596
583
597
584
int Astroid::hint_level () {
0 commit comments