* [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender @ 2010-01-23 10:05 Aneesh Kumar K.V 2010-01-23 10:05 ` [PATCH -V2 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V 2010-04-06 7:11 ` [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender Sebastian Spaeth 0 siblings, 2 replies; 5+ messages in thread From: Aneesh Kumar K.V @ 2010-01-23 10:05 UTC (permalink / raw) To: cworth; +Cc: Aneesh Kumar K.V, notmuch From: Aneesh Kumar K.V <aneesh.kumar@gmail.com> This patch add --format=sender-only option. Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com> --- notmuch-reply.c | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 40 insertions(+), 14 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index 0cda72d..859b725 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -23,15 +23,23 @@ #include "notmuch-client.h" #include "gmime-filter-reply.h" -static const struct { +struct reply_map { const char *header; const char *fallback; GMimeRecipientType recipient_type; -} reply_to_map[] = { +}; + +static const struct reply_map reply_to_all_map[] = { { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO }, { "to", NULL, GMIME_RECIPIENT_TYPE_TO }, { "cc", NULL, GMIME_RECIPIENT_TYPE_CC }, - { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC } + { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }, + { NULL, NULL, 0} +}; + +static const struct reply_map reply_to_sender_map[] = { + { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO }, + { NULL, NULL, 0} }; static void @@ -200,7 +208,8 @@ add_recipients_for_string (GMimeMessage *message, } static int -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +__notmuch_reply(void *ctx, notmuch_config_t *config, + notmuch_query_t *query, const struct reply_map *map) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -229,17 +238,19 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ subject = talloc_asprintf (ctx, "Re: %s", subject); g_mime_message_set_subject (reply, subject); - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { + for (i = 0;; i++) { const char *addr; + if (!map[i].header) + break; recipients = notmuch_message_get_header (message, - reply_to_map[i].header); - if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback) + map[i].header); + if ((recipients == NULL || recipients[0] == '\0') && map[i].fallback) recipients = notmuch_message_get_header (message, - reply_to_map[i].fallback); + map[i].fallback); addr = add_recipients_for_string (reply, config, - reply_to_map[i].recipient_type, + map[i].recipient_type, recipients); if (from_addr == NULL) from_addr = addr; @@ -289,6 +300,12 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ return 0; } +static int +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +{ + return __notmuch_reply(ctx, config, query, reply_to_all_map); +} + /* This format is currently tuned for a git send-email --notmuch hook */ static int notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query) @@ -332,17 +349,18 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q g_mime_object_set_header (GMIME_OBJECT (reply), "References", references); - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { + for (i = 0; i < ARRAY_SIZE (reply_to_all_map); i++) { const char *addr; recipients = notmuch_message_get_header (message, - reply_to_map[i].header); - if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback) + reply_to_all_map[i].header); + if ((recipients == NULL || recipients[0] == '\0') && + reply_to_all_map[i].fallback) recipients = notmuch_message_get_header (message, - reply_to_map[i].fallback); + reply_to_all_map[i].fallback); addr = add_recipients_for_string (reply, config, - reply_to_map[i].recipient_type, + reply_to_all_map[i].recipient_type, recipients); } @@ -361,6 +379,12 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q return 0; } +static int +notmuch_reply_format_sender_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +{ + return __notmuch_reply(ctx, config, query, reply_to_sender_map); +} + int notmuch_reply_command (void *ctx, int argc, char *argv[]) { @@ -384,6 +408,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) reply_format_func = notmuch_reply_format_default; } else if (strcmp (opt, "headers-only") == 0) { reply_format_func = notmuch_reply_format_headers_only; + } else if (strcmp (opt, "sender-only") == 0) { + reply_format_func = notmuch_reply_format_sender_only; } else { fprintf (stderr, "Invalid value for --format: %s\n", opt); return 1; -- 1.6.6.1.394.gdedc0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH -V2 2/2] notmuch.el: Add support for reply-to sender 2010-01-23 10:05 [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V @ 2010-01-23 10:05 ` Aneesh Kumar K.V 2010-04-06 7:11 ` [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender Sebastian Spaeth 1 sibling, 0 replies; 5+ messages in thread From: Aneesh Kumar K.V @ 2010-01-23 10:05 UTC (permalink / raw) To: cworth; +Cc: Aneesh Kumar K.V, notmuch From: Aneesh Kumar K.V <aneesh.kumar@gmail.com> Add key binding to do a reply-to sender. This is mapped to 'R' Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com> --- notmuch.el | 24 ++++++++++++++++++++++-- 1 files changed, 22 insertions(+), 2 deletions(-) diff --git a/notmuch.el b/notmuch.el index 97914f2..5589350 100644 --- a/notmuch.el +++ b/notmuch.el @@ -62,7 +62,8 @@ (define-key map "s" 'notmuch-search) (define-key map "m" 'message-mail) (define-key map "f" 'notmuch-show-forward-current) - (define-key map "r" 'notmuch-show-reply) + (define-key map "r" 'notmuch-show-reply-all) + (define-key map "R" 'notmuch-show-reply) (define-key map "|" 'notmuch-show-pipe-message) (define-key map "w" 'notmuch-show-save-attachments) (define-key map "V" 'notmuch-show-view-raw-message) @@ -363,12 +364,31 @@ buffer." (forward-line))) (message-mode)) -(defun notmuch-show-reply () +(defun notmuch-show-reply-all () "Begin composing a reply to the current message in a new buffer." (interactive) (let ((message-id (notmuch-show-get-message-id))) (notmuch-reply message-id))) + +(defun notmuch-format-reply (format-string query-string) + (switch-to-buffer (generate-new-buffer "notmuch-draft")) + (call-process notmuch-command nil t nil "reply" + (concat "--format=" format-string) query-string) + (message-insert-signature) + (goto-char (point-min)) + (if (re-search-forward "^$" nil t) + (progn + (insert "--text follows this line--") + (forward-line))) + (message-mode)) + +(defun notmuch-show-reply () + "Begin composing a reply to the current message in a new buffer." + (interactive) + (let ((message-id (notmuch-show-get-message-id))) + (notmuch-format-reply "sender-only" message-id))) + (defun notmuch-show-forward-current () "Forward the current message." (interactive) -- 1.6.6.1.394.gdedc0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender 2010-01-23 10:05 [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V 2010-01-23 10:05 ` [PATCH -V2 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V @ 2010-04-06 7:11 ` Sebastian Spaeth 2010-04-06 7:12 ` [PATCH " Sebastian Spaeth 1 sibling, 1 reply; 5+ messages in thread From: Sebastian Spaeth @ 2010-04-06 7:11 UTC (permalink / raw) To: Aneesh Kumar K.V, cworth, notmuch I just rebased these two patches as the files have been moved around. I use those patches and they work fine for me, by the way. Patches will arrive in a second as reply to this message. Sebastian ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] notmuch-reply: Add support for replying only to sender 2010-04-06 7:11 ` [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender Sebastian Spaeth @ 2010-04-06 7:12 ` Sebastian Spaeth 2010-04-06 7:12 ` [PATCH 2/2] notmuch.el: Add support for reply-to sender Sebastian Spaeth 0 siblings, 1 reply; 5+ messages in thread From: Sebastian Spaeth @ 2010-04-06 7:12 UTC (permalink / raw) To: notmuch; +Cc: Aneesh Kumar K.V From: Aneesh Kumar K.V <aneesh.kumar@gmail.com> This patch add --recipient=all|sender option Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com> --- notmuch-client.h | 2 + notmuch-reply.c | 55 ++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index d36b9ec..3ca4b32 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -73,6 +73,8 @@ #define STRNCMP_LITERAL(var, literal) \ strncmp ((var), (literal), sizeof (literal) - 1) +#define NOTMUCH_REPLY_ALL 0x1 +#define NOTMUCH_REPLY_SENDER_ONLY 0x2 static inline void chomp_newline (char *str) { diff --git a/notmuch-reply.c b/notmuch-reply.c index 6c15536..e8a0820 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -232,20 +232,37 @@ reply_to_header_is_redundant (notmuch_message_t *message) static const char * add_recipients_from_message (GMimeMessage *reply, notmuch_config_t *config, - notmuch_message_t *message) + notmuch_message_t *message, + int reply_options) { - struct { + struct reply_to_map { const char *header; const char *fallback; GMimeRecipientType recipient_type; - } reply_to_map[] = { + } ; + const char *from_addr = NULL; + unsigned int i; + struct reply_to_map *reply_to_map; + + struct reply_to_map reply_to_map_all[] = { { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO }, { "to", NULL, GMIME_RECIPIENT_TYPE_TO }, { "cc", NULL, GMIME_RECIPIENT_TYPE_CC }, - { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC } + { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC }, + { NULL, NULL, 0 } }; - const char *from_addr = NULL; - unsigned int i; + + /* we try from first and then reply-to */ + struct reply_to_map reply_to_map_sender[] = { + { "from", "reply-to", GMIME_RECIPIENT_TYPE_TO }, + { NULL, NULL, 0 } + }; + + if (reply_options == NOTMUCH_REPLY_SENDER_ONLY) { + reply_to_map = reply_to_map_sender; + } else { + reply_to_map = reply_to_map_all; + } /* Some mailing lists munge the Reply-To header despite it being A Bad * Thing, see http://www.unicom.com/pw/reply-to-harmful.html @@ -263,7 +280,7 @@ add_recipients_from_message (GMimeMessage *reply, reply_to_map[0].fallback = NULL; } - for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { + for (i = 0; reply_to_map[i].header; i++) { const char *addr, *recipients; recipients = notmuch_message_get_header (message, @@ -283,7 +300,7 @@ add_recipients_from_message (GMimeMessage *reply, } static int -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -311,7 +328,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ subject = talloc_asprintf (ctx, "Re: %s", subject); g_mime_message_set_subject (reply, subject); - from_addr = add_recipients_from_message (reply, config, message); + from_addr = add_recipients_from_message (reply, config, message, reply_options); if (from_addr == NULL) from_addr = notmuch_config_get_user_primary_email (config); @@ -359,7 +376,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ /* This format is currently tuned for a git send-email --notmuch hook */ static int -notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -399,7 +416,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q g_mime_object_set_header (GMIME_OBJECT (reply), "References", references); - (void)add_recipients_from_message (reply, config, message); + (void)add_recipients_from_message (reply, config, message, reply_options); g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc", notmuch_config_get_user_primary_email (config)); @@ -423,8 +440,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) notmuch_database_t *notmuch; notmuch_query_t *query; char *opt, *query_string; - int i, ret = 0; - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query); + int i, ret = 0, reply_to = NOTMUCH_REPLY_ALL; + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_options); reply_format_func = notmuch_reply_format_default; @@ -443,6 +460,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) fprintf (stderr, "Invalid value for --format: %s\n", opt); return 1; } + } else if (STRNCMP_LITERAL (argv[i], "--recipient=") == 0) { + opt = argv[i] + sizeof ("--recipient=") - 1; + if (strcmp (opt, "all") == 0) { + reply_to = NOTMUCH_REPLY_ALL; + } else if (strcmp (opt, "sender") == 0) { + reply_to = NOTMUCH_REPLY_SENDER_ONLY; + } else { + fprintf (stderr, "Invalid value for --recipient: %s\n", opt); + return 1; + } } else { fprintf (stderr, "Unrecognized option: %s\n", argv[i]); return 1; @@ -478,7 +505,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) return 1; } - if (reply_format_func (ctx, config, query) != 0) + if (reply_format_func (ctx, config, query, reply_to) != 0) return 1; notmuch_query_destroy (query); -- 1.6.3.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] notmuch.el: Add support for reply-to sender 2010-04-06 7:12 ` [PATCH " Sebastian Spaeth @ 2010-04-06 7:12 ` Sebastian Spaeth 0 siblings, 0 replies; 5+ messages in thread From: Sebastian Spaeth @ 2010-04-06 7:12 UTC (permalink / raw) To: notmuch; +Cc: Aneesh Kumar K.V From: Aneesh Kumar K.V <aneesh.kumar@gmail.com> Add key binding to do a reply-to sender. This is mapped to 'R' Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com> Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> --- emacs/notmuch-show.el | 21 ++++++++++++++++++++- 1 files changed, 20 insertions(+), 1 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index cc1f905..3d89861 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -63,7 +63,8 @@ (define-key map "s" 'notmuch-search) (define-key map "m" 'message-mail) (define-key map "f" 'notmuch-show-forward-current) - (define-key map "r" 'notmuch-show-reply) + (define-key map "r" 'notmuch-show-reply-all) + (define-key map "R" 'notmuch-show-reply) (define-key map "|" 'notmuch-show-pipe-message) (define-key map "w" 'notmuch-show-save-attachments) (define-key map "V" 'notmuch-show-view-raw-message) @@ -360,10 +361,28 @@ buffer." mm-handle (> (notmuch-count-attachments mm-handle) 1)))) (message "Done")) +(defun notmuch-recipient-reply (recipient query-string) + (switch-to-buffer (generate-new-buffer "notmuch-draft")) + (call-process notmuch-command nil t nil "reply" + (concat "--recipient=" recipient) query-string) + (message-insert-signature) + (goto-char (point-min)) + (if (re-search-forward "^$" nil t) + (progn + (insert "--text follows this line--") + (forward-line))) + (message-mode)) + (defun notmuch-show-reply () "Begin composing a reply to the current message in a new buffer." (interactive) (let ((message-id (notmuch-show-get-message-id))) + (notmuch-recipient-reply "sender" message-id))) + +(defun notmuch-show-reply-all () + "Begin composing a reply to the current message in a new buffer." + (interactive) + (let ((message-id (notmuch-show-get-message-id))) (notmuch-reply message-id))) (defun notmuch-show-forward-current () -- 1.6.3.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-04-06 7:12 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-01-23 10:05 [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V 2010-01-23 10:05 ` [PATCH -V2 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V 2010-04-06 7:11 ` [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender Sebastian Spaeth 2010-04-06 7:12 ` [PATCH " Sebastian Spaeth 2010-04-06 7:12 ` [PATCH 2/2] notmuch.el: Add support for reply-to sender Sebastian Spaeth
Code repositories for project(s) associated with this public inbox https://yhetil.org/notmuch.git/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).