]> granicus.if.org Git - neomutt/commitdiff
add $record support
authorKarel Zak <kzak@redhat.com>
Sun, 23 Sep 2012 07:31:54 +0000 (09:31 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 14 Mar 2016 23:11:42 +0000 (23:11 +0000)
Signed-off-by: Karel Zak <kzak@redhat.com>
README.notmuch
compose.c
globals.h
init.h
mutt.h
mutt_notmuch.c
mutt_notmuch.h
protos.h
send.c
sendlib.c

index f2e30f552b039e366d21363e07324876e74ca674..701fbb912020e4d32628cc1c34ebc0b8a9dc7bd0 100644 (file)
@@ -140,6 +140,22 @@ notmuch support for mutt
       the sidebar. It's possible to toggle between virtual and normal folders by
       sidebar-toggle command.
 
+   nm_record = <boolean>
+
+      Add messages stored to the mutt record (see $record in the mutt docs)
+      also to notmuch DB. If you reply to an email then the new email inherits
+      tags from the original email.
+
+   nm_record_tags = <comma delimited list>
+
+      Tags that should be removed or added to the to the messages stored in the mutt record.
+
+      example:
+
+      set record = "~/sent-mails"
+      set nm_record = yes
+      set nm_record_tags = "-inbox,archive,me"
+
    nm_open_timeout = <seconds>
 
       This option specifies timeout for Notmuch database. Default is 5 seconds.
@@ -214,6 +230,10 @@ notmuch support for mutt
 
 * .muttrc example:
 
+       set record="~/Mail/Maildir/sent-mail"
+       set nm_record = yes
+       set nm_record_tags ="-inbox me archive"
+
        set nm_default_uri="notmuch:///home/kzak/Mail/Maildir"
        set virtual_spoolfile   = yes
 
index 0bd17b63312f8c2b0bbfc60dc44921b12a4bf503..f84389061b64647b00fb31c2275eff0b1bdd6a66 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -1226,7 +1226,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
          if (msg->content->next)
            msg->content = mutt_make_multipart (msg->content);
 
-         if (mutt_write_fcc (fname, msg, NULL, 0, NULL) < 0)
+         if (mutt_write_fcc (fname, msg, NULL, 0, NULL, NULL) < 0)
            msg->content = mutt_remove_multipart (msg->content);
          else
            mutt_message _("Message written.");
index e8b2e40a4e2e503d81a448295cf95a7d9e5d49bf..36d489209e78d28e555984c4d480ef0813e671f7 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -286,6 +286,7 @@ WHERE char *NotmuchHiddenTags;
 WHERE char *VirtFolderFormat;
 WHERE int NotmuchDBLimit;
 WHERE char *NotmuchQueryType;
+WHERE char *NotmuchRecordTags;
 #endif
 
 
diff --git a/init.h b/init.h
index 057654d1b632bd5c6e169762494608a7b908bd18..8df5bfbea4c7dad87f6ecfdf93b25eecec26cee0 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1685,6 +1685,16 @@ struct option_t MuttVars[] = {
    ** .pp
    ** This variable specifies the default query type (threads or messages) used in notmuch queries.
    */
+  { "nm_record", DT_BOOL, R_NONE, OPTNOTMUCHRECORD, 0 },
+  /*
+   ** .pp
+   ** This variable specifies if the mutt record should indexed by notmuch.
+   */
+  { "nm_record_tags", DT_STR, R_NONE, UL &NotmuchRecordTags, 0 },
+  /*
+   ** .pp
+   ** This variable specifies the default tags applied to messages stored to the mutt record.
+   */
 #endif
   { "pager",           DT_PATH, R_NONE, UL &Pager, UL "builtin" },
   /*
diff --git a/mutt.h b/mutt.h
index b3457da7dd1edba52004b6b7e11d2276e43aee87..efbc55fc70a0136c8a5e9b06b015839f0b094c42 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -542,6 +542,7 @@ enum
 
 #ifdef USE_NOTMUCH
   OPTVIRTSPOOLFILE,
+  OPTNOTMUCHRECORD,
 #endif
 
   OPTMAX
index 6eb14c7b045431e48e7098851f00c3046a72975a..2c3e72bcc37b7063fa4741c469dd01d9dc067832 100644 (file)
@@ -1541,6 +1541,52 @@ done:
               new_flags ? M_FLAGS : 0;
 }
 
+int nm_record_message(CONTEXT *ctx, char *path, HEADER *h)
+{
+       notmuch_database_t *db;
+       notmuch_status_t st;
+       notmuch_message_t *msg;
+       int rc = -1;
+       struct nm_ctxdata *data = get_ctxdata(ctx);
+
+       if (!path || !data || access(path, F_OK) != 0)
+               return 0;
+       db = get_db(data, TRUE);
+       if (!db)
+               return -1;
+
+       dprint(1, (debugfile, "nm: record message: %s\n", path));
+       st = notmuch_database_begin_atomic(db);
+       if (st)
+               return -1;
+
+       st = notmuch_database_add_message(db, path, &msg);
+
+       if (st != NOTMUCH_STATUS_SUCCESS &&
+           st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
+               dprint(1, (debugfile, "nm: failed to add '%s' [st=%d]\n", path, (int) st));
+               goto done;
+       }
+
+       if (st == NOTMUCH_STATUS_SUCCESS && msg) {
+               notmuch_message_maildir_flags_to_tags(msg);
+               if (h)
+                       update_tags(msg, nm_header_get_tags(h));
+               if (NotmuchRecordTags)
+                       update_tags(msg, NotmuchRecordTags);
+       }
+
+       rc = 0;
+done:
+       if (msg)
+               notmuch_message_destroy(msg);
+       notmuch_database_end_atomic(db);
+
+       if (!is_longrun(data))
+               release_db(data);
+       return rc;
+}
+
 /*
  * Fill a list with all notmuch tags.
  *
@@ -1556,7 +1602,7 @@ int nm_get_all_tags(CONTEXT *ctx, char **tag_list, int *tag_count)
        if (!data)
                return -1;
 
-       if (!(db = get_db(data, TRUE)) ||
+       if (!(db = get_db(data, FALSE)) ||
                        !(tags = notmuch_database_get_all_tags(db)))
                goto done;
 
index bc769eca0243677fcb3e3a4e9f51a3803d75fc4a..7ea77f3941531389f8b02b5dd46ddafe2fea4c72 100644 (file)
@@ -20,6 +20,8 @@ void nm_longrun_done(CONTEXT *cxt);
 
 char *nm_get_description(CONTEXT *ctx);
 
+int nm_record_message(CONTEXT *ctx, char *path, HEADER *h);
+
 void nm_debug_check(CONTEXT *ctx);
 int nm_get_all_tags(CONTEXT *ctx, char **tag_list, int *tag_count);
 
index b0745c05d0cf39395630f60f4524a8ab6f861497..92fd052f18728f8caf6e7a08ae8c4a414014190c 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -375,7 +375,7 @@ int mutt_user_is_recipient (HEADER *);
 void mutt_update_num_postponed (void);
 int mutt_wait_filter (pid_t);
 int mutt_which_case (const char *);
-int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char *);
+int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char *, char **);
 int mutt_write_mime_body (BODY *, FILE *);
 int mutt_write_mime_header (BODY *, FILE *);
 int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, int flags);
diff --git a/send.c b/send.c
index d4e2a7974da48e7169ef5a029567dd523f58b481..6bec036972827a20ad741bb93a030a9224e13a9f 100644 (file)
--- a/send.c
+++ b/send.c
@@ -48,6 +48,9 @@
 #include "remailer.h"
 #endif
 
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
 
 static void append_signature (FILE *f)
 {
@@ -1156,6 +1159,7 @@ ci_send_message (int flags,               /* send mode */
   char *smime_default_key = NULL;
   char *tag = NULL, *err = NULL;
   char *ctype;
+  char *finalpath = NULL;
 
   int rv = -1;
   
@@ -1628,7 +1632,9 @@ main_loop:
       mutt_prepare_envelope (msg->env, 0);
       mutt_env_to_idna (msg->env, NULL, NULL); /* Handle bad IDNAs the next time. */
 
-      if (!Postponed || mutt_write_fcc (NONULL (Postponed), msg, (cur && (flags & SENDREPLY)) ? cur->env->message_id : NULL, 1, fcc) < 0)
+      if (!Postponed || mutt_write_fcc (NONULL (Postponed), msg,
+                           (cur && (flags & SENDREPLY)) ?
+                                    cur->env->message_id : NULL, 1, fcc, NULL) < 0)
       {
        msg->content = mutt_remove_multipart (msg->content);
        decode_descriptions (msg->content);
@@ -1810,7 +1816,7 @@ full_fcc:
        * message was first postponed.
        */
       msg->received = time (NULL);
-      if (mutt_write_fcc (fcc, msg, NULL, 0, NULL) == -1)
+      if (mutt_write_fcc (fcc, msg, NULL, 0, NULL, &finalpath) == -1)
       {
        /*
         * Error writing FCC, we should abort sending.
@@ -1871,6 +1877,7 @@ full_fcc:
       msg->content = mutt_remove_multipart (msg->content);
       decode_descriptions (msg->content);
       mutt_unprepare_envelope (msg->env);
+      FREE(&finalpath);
       goto main_loop;
     }
     else
@@ -1879,8 +1886,13 @@ full_fcc:
       goto cleanup;
     }
   }
-  else if (!option (OPTNOCURSES) && ! (flags & SENDMAILX))
+  else if (!option (OPTNOCURSES) && ! (flags & SENDMAILX)) {
     mutt_message (i == 0 ? _("Mail sent.") : _("Sending in background."));
+#ifdef USE_NOTMUCH
+    if (option(OPTNOTMUCHRECORD))
+      nm_record_message(ctx, finalpath, cur);
+#endif
+  }
 
   if (WithCrypto && (msg->security & ENCRYPT))
     FREE (&pgpkeylist);
@@ -1924,7 +1936,7 @@ cleanup:
    
   safe_fclose (&tempfp);
   mutt_free_header (&msg);
-  
+  FREE(&finalpath);
   return rv;
 }
 
index 446f6146d11dc5ae2ab7e7e144aecfb9afa867d1..4f7dfa8da8f75684808fe40108bd901a3b45043d 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2684,7 +2684,8 @@ static void set_noconv_flags (BODY *b, short flag)
   }
 }
 
-int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, char *fcc)
+int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid,
+                   int post, char *fcc, char **finalpath)
 {
   CONTEXT f;
   MESSAGE *msg;
@@ -2873,6 +2874,8 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post,
 
   if (mx_commit_message (msg, &f) != 0)
     r = -1;
+  else if (finalpath)
+    *finalpath = safe_strdup(msg->commited_path);
   mx_close_message (&msg);
   mx_close_mailbox (&f, NULL);