diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2018-10-04 00:29:27 +0200 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2018-10-05 18:18:33 +0200 |
commit | cda29352783efb9be76e76a24ac6d2406697fe4b (patch) | |
tree | 60d6a6cf4815218a1cea428b65a340ca0043b2a0 | |
parent | c7364fe3560681c53e6aeac15a8710297cea3c05 (diff) |
Parse from, cc, bcc, subject, and body from mailto URIs
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/astroid.cc | 49 |
2 files changed, 40 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index eba0ad1..af6fbdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,7 @@ pkg_check_modules (WEBKIT2GTK REQUIRED webkit2gtk-4.0>=2.22) pkg_check_modules (SASS REQUIRED libsass) pkg_check_modules (GIOMM2 REQUIRED giomm-2.4) pkg_check_modules (GIOUNIX REQUIRED gio-unix-2.0) +pkg_check_modules (LIBSOUP REQUIRED libsoup-2.4) string (REGEX REPLACE "([0-9]+\.[0-9]+)\.[0-9]+" "\\1" GMIME_MAJOR_MINOR ${Notmuch_GMIME_VERSION}) pkg_check_modules (GMIME REQUIRED gmime-${GMIME_MAJOR_MINOR}>=${Notmuch_GMIME_VERSION}) @@ -142,6 +143,7 @@ include_directories ( ${GLIBMM2_INCLUDE_DIRS} ${GIOMM2_INCLUDE_DIRS} ${GIOUNIX_INCLUDE_DIRS} + ${LIBSOUP_INCLUDE_DIRS} ${GMIME_INCLUDE_DIRS} ${WEBKIT2GTK_INCLUDE_DIRS} ${VTE2_INCLUDE_DIRS} @@ -155,6 +157,7 @@ add_compile_options ( ${GLIBMM2_CFLAGS} ${GIOMM2_CFLAGS} ${GIOUNIX_CFLAGS} + ${LIBSOUP_CFLAGS} ${GMIME_CFLAGS} ${WEBKIT2GTK_CFLAGS} ${VTE2_CFLAGS} diff --git a/src/astroid.cc b/src/astroid.cc index 682cbe9..d44e6c2 100644 --- a/src/astroid.cc +++ b/src/astroid.cc @@ -53,6 +53,8 @@ # include <gmime/gmime.h> # include <utils/gmime/gmime-compat.h> +# include <libsoup/soup.h> + using namespace std; using namespace boost::filesystem; @@ -534,25 +536,48 @@ namespace Astroid { MainWindow * mw = (MainWindow*) get_windows ()[0]; - ustring scheme = Glib::uri_parse_scheme (url); - if (scheme.length () > 0) { - /* we got an mailto url */ - url = url.substr(scheme.length(), url.length () - scheme.length()); - - ustring to, cc, bcc, subject, body; + SoupURI *uri = soup_uri_new(url.c_str()); - ustring::size_type pos = url.find ("?"); - /* ustring::size_type next; */ - if (pos == ustring::npos) pos = url.length (); - to = url.substr (0, pos); + if (SOUP_URI_IS_VALID(uri)) { + /* we got an mailto url */ + ustring from, to, cc, bcc, subject, body; + + to = soup_uri_decode (soup_uri_get_path (uri)); + + const char * soup_query = soup_uri_get_query (uri); + if (soup_query) { + std::istringstream query_string (soup_query); + std::string keyval; + while (std::getline(query_string, keyval, '&')) { + ustring::size_type pos = keyval.find ("="); + + ustring key = keyval.substr (0, pos); + key = key.lowercase (); + + ustring val = soup_uri_decode (keyval.substr (pos+1).c_str()); + + if (key == "from") { + from = ustring (val); + } else if (key == "cc") { + cc = ustring (val); + } else if (key == "bcc") { + bcc = ustring (val); + } else if (key == "subject" ) { + subject = ustring (val); + } else if (key == "body") { + body = ustring (val); + } + } + } - /* TODO: need to finish the rest of the fields */ - mw->add_mode (new EditMessage (mw, to)); + mw->add_mode (new EditMessage (mw, to, from, cc, bcc, subject, body)); } else { /* we probably just got the address on the cmd line */ mw->add_mode (new EditMessage (mw, url)); } + + soup_uri_free (uri); } int Astroid::hint_level () { |