* src/imap.c
[claws.git] / src / utils.c
index df158ecab0f5d868b27b5529aba1b709eff883c6..ff10b1d117724fe0748de3b73a80145756f2a182 100644 (file)
@@ -1349,6 +1349,63 @@ GList *uri_list_extract_filenames(const gchar *uri_list)
        } \
 }
 
+gint scan_mailto_url(const gchar *mailto, gchar **to, gchar **cc, gchar **bcc,
+                    gchar **subject, gchar **body)
+{
+       gchar *tmp_mailto;
+       gchar *p;
+
+       Xstrdup_a(tmp_mailto, mailto, return -1);
+
+       if (!strncmp(tmp_mailto, "mailto:", 7))
+               tmp_mailto += 7;
+
+       p = strchr(tmp_mailto, '?');
+       if (p) {
+               *p = '\0';
+               p++;
+       }
+
+       if (to && !*to)
+               *to = g_strdup(tmp_mailto);
+
+       while (p) {
+               gchar *field, *value;
+
+               field = p;
+
+               p = strchr(p, '=');
+               if (!p) break;
+               *p = '\0';
+               p++;
+
+               value = p;
+
+               p = strchr(p, '&');
+               if (p) {
+                       *p = '\0';
+                       p++;
+               }
+
+               if (*value == '\0') continue;
+
+               if (cc && !*cc && !g_strcasecmp(field, "cc")) {
+                       *cc = g_strdup(value);
+               } else if (bcc && !*bcc && !g_strcasecmp(field, "bcc")) {
+                       *bcc = g_strdup(value);
+               } else if (subject && !*subject &&
+                          !g_strcasecmp(field, "subject")) {
+                       *subject = g_malloc(strlen(value) + 1);
+                       decode_uri(*subject, value);
+               } else if (body && !*body && !g_strcasecmp(field, "body")) {
+                       *body = g_malloc(strlen(value) + 1);
+                       decode_uri(*body, value);
+               }
+       }
+
+       return 0;
+}
+
 /*
  * We need this wrapper around g_get_home_dir(), so that
  * we can fix some Windoze things here.  Should be done in glibc of course
@@ -1770,6 +1827,51 @@ gint remove_numbered_files(const gchar *dir, guint first, guint last)
        return 0;
 }
 
+gint remove_numbered_files_not_in_list(const gchar *dir, GSList *numberlist)
+{
+       DIR *dp;
+       struct dirent *d;
+       gchar *prev_dir;
+       gint fileno;
+
+       prev_dir = g_get_current_dir();
+
+       if (chdir(dir) < 0) {
+               FILE_OP_ERROR(dir, "chdir");
+               g_free(prev_dir);
+               return -1;
+       }
+
+       if ((dp = opendir(".")) == NULL) {
+               FILE_OP_ERROR(dir, "opendir");
+               g_free(prev_dir);
+               return -1;
+       }
+
+       while ((d = readdir(dp)) != NULL) {
+               fileno = to_number(d->d_name);
+               if (fileno >= 0 && (g_slist_find(numberlist, GINT_TO_POINTER(fileno)) == NULL)) {
+                       debug_print("removing unwanted file %d from %s\n", fileno, dir);
+                       if (is_dir_exist(d->d_name))
+                               continue;
+                       if (unlink(d->d_name) < 0)
+                               FILE_OP_ERROR(d->d_name, "unlink");
+               }
+       }
+
+       closedir(dp);
+
+       if (chdir(prev_dir) < 0) {
+               FILE_OP_ERROR(prev_dir, "chdir");
+               g_free(prev_dir);
+               return -1;
+       }
+
+       g_free(prev_dir);
+
+       return 0;
+}
+
 gint remove_all_numbered_files(const gchar *dir)
 {
        return remove_numbered_files(dir, 0, UINT_MAX);