[PATCH] Index Content-Type of attachments with a contenttype prefix
On Sat, 10 Jan 2015, Todd wrote: > I wanted to tag messages with calendar invitations, but couldn't as > the information wasn't indexed. > > This patch allows for queries for like: > > Find calendar invites > - contenttype:text/calendar or contenttype:applicaton/ics > > Find any image attachments > - contenttype:image > > Find all patches > - contenttype:text/x-patch > > > - Todd > > --- > NEWS | 6 ++ > completion/notmuch-completion.bash | 2 +- > doc/man7/notmuch-search-terms.rst | 6 ++ > emacs/notmuch.el | 2 +- > lib/database.cc| 1 + > lib/index.cc | 5 + > test/T190-multipart.sh | 32 IMO these could be split into several patches. > 7 files changed, 52 insertions(+), 2 deletions(-) > > diff --git a/NEWS b/NEWS > index 44e8d05..5f4622c 100644 > --- a/NEWS > +++ b/NEWS > @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. > Command-Line Interface > -- > > +There is a new `contenttype:` search prefix > + > + The new `contenttype:` search prefix allows searching for the > + content-type of attachments, which is now indexed by `notmuch > + insert`. See the `notmuch-search-terms` manual page for details. > + Admittedly I did not have the time to dig into details, but I think "attachment" is misleading, as it's really all mime parts, right? Will this also index the Content-Type: header of the message itself, regardless of whether it has mime structure or not? Maybe it should? > Stopped `notmuch dump` failing if someone writes to the database > >The dump command now takes the write lock when running. This > diff --git a/completion/notmuch-completion.bash > b/completion/notmuch-completion.bash > index d58dc8b..05b5969 100644 > --- a/completion/notmuch-completion.bash > +++ b/completion/notmuch-completion.bash > @@ -61,7 +61,7 @@ _notmuch_search_terms() > sed "s|^$path/||" | grep -v "\(^\|/\)\(cur\|new\|tmp\)$" ) ) > ;; > *) > - local search_terms="from: to: subject: attachment: tag: id: thread: > folder: path: date:" > + local search_terms="from: to: subject: attachment: contenttype: > tag: id: thread: folder: path: date:" > compopt -o nospace > COMPREPLY=( $(compgen -W "${search_terms}" -- ${cur}) ) > ;; > diff --git a/doc/man7/notmuch-search-terms.rst > b/doc/man7/notmuch-search-terms.rst > index 1acdaa0..d126ce6 100644 > --- a/doc/man7/notmuch-search-terms.rst > +++ b/doc/man7/notmuch-search-terms.rst > @@ -40,6 +40,8 @@ indicate user-supplied values): > > - attachment: > > +- contenttype: > + > - tag: (or is:) > > - id: > @@ -66,6 +68,10 @@ by including quotation marks around the phrase, > immediately following > The **attachment:** prefix can be used to search for specific filenames > (or extensions) of attachments to email messages. > > +The **contenttype:** prefix can be used to search for specific > +content-types of attachments to email messages (as specified by the > +sender). > + > For **tag:** and **is:** valid tag values include **inbox** and > **unread** by default for new messages added by **notmuch new** as well > as any other tag values added manually with **notmuch tag**. > diff --git a/emacs/notmuch.el b/emacs/notmuch.el > index 218486a..702700c 100644 > --- a/emacs/notmuch.el > +++ b/emacs/notmuch.el > @@ -858,7 +858,7 @@ PROMPT is the string to prompt with." >(lexical-let >((completions > (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:" > - "subject:" "attachment:") > + "subject:" "attachment:" "contenttype:") > (mapcar (lambda (tag) > (concat "tag:" (notmuch-escape-boolean-term tag))) > (process-lines notmuch-command "search" "--output=tags" > "*") > diff --git a/lib/database.cc b/lib/database.cc > index 3601f9d..a7a64c9 100644 > --- a/lib/database.cc > +++ b/lib/database.cc > @@ -254,6 +254,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= { > { "from","XFROM" }, > { "to", "XTO" }, > { "attachment", "XATTACHMENT" }, > +{ "contenttype", "XCONTENTTYPE"}, > { "subject", "XSUBJECT"}, Is the use of probabilistic prefix intentional? I think it's probably the right thing to do, but just checking. BR, Jani. > }; > > diff --git a/lib/index.cc b/lib/index.cc > index 1a2e63d..c3f7c6b 100644 > --- a/lib/index.cc > +++ b/lib/index.cc > @@ -346,6 +346,11 @@ _index_mime_part (notmuch_message_t *message, > return; > } > > +GMimeContentType* content_type = g_mime_object_get_content_type(part); > +if (content_type) { > + _notmuch_message_gen_terms (message, "contenttype", > g_mime_content_type_to_string(content_type)); > +} > + > if (GMIME_IS_MESSAGE_PART
[PATCH] Index Content-Type of attachments with a contenttype prefix
Todd writes: > I wanted to tag messages with calendar invitations, but couldn't as > the information wasn't indexed. > > This patch allows for queries for like: > > Find calendar invites > - contenttype:text/calendar or contenttype:applicaton/ics > > Find any image attachments > - contenttype:image > > Find all patches > - contenttype:text/x-patch The main issue, that I won't really address in this message (because I'm hoping Austin finds time to comment) is upgrading the database. The short version is that a new "database feature" needs to be created. > --- a/NEWS > +++ b/NEWS > @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. > Command-Line Interface > -- Minor point, 0.19 was released, you should start a new NEWS section for 0.20 with date UNRELEASED > --- a/completion/notmuch-completion.bash > +++ b/completion/notmuch-completion.bash If you can without too much suffering, it would be nice to update the zsh completion at the same time. > +The **contenttype:** prefix can be used to search for specific > +content-types of attachments to email messages (as specified by the > +sender). > + I'm not 100% sure, but I did wonder if the docs should mention MIME somewhere, for people searching. > { "attachment", "XATTACHMENT" }, > +{ "contenttype", "XCONTENTTYPE"}, > { "subject", "XSUBJECT"}, I didn't work through all the details, but I did wonder if it was in some sense redundant to be indexing contenttype and also the existing attachement and encrypted pseudotags. I guess this might be one of those cases where we are stuck with the extra indexing for now, until we sort out some query parsing issues. d
[PATCH] Index Content-Type of attachments with a contenttype prefix
> "Jani" == Jani Nikula writes: Jani> On Sat, 10 Jan 2015, Todd wrote: >> I wanted to tag messages with calendar invitations, but couldn't as >> the information wasn't indexed. >> >> This patch allows for queries for like: >> >> Find calendar invites >> - contenttype:text/calendar or contenttype:applicaton/ics >> >> Find any image attachments >> - contenttype:image >> >> Find all patches >> - contenttype:text/x-patch >> >> >> - Todd >> >> --- >> NEWS | 6 ++ >> completion/notmuch-completion.bash | 2 +- >> doc/man7/notmuch-search-terms.rst | 6 ++ >> emacs/notmuch.el | 2 +- >> lib/database.cc| 1 + >> lib/index.cc | 5 + >> test/T190-multipart.sh | 32 Jani> IMO these could be split into several patches. No problem, I'll split them up the next time I post. >> 7 files changed, 52 insertions(+), 2 deletions(-) >> >> diff --git a/NEWS b/NEWS >> index 44e8d05..5f4622c 100644 >> --- a/NEWS >> +++ b/NEWS >> @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. >> Command-Line Interface >> -- >> >> +There is a new `contenttype:` search prefix >> + >> + The new `contenttype:` search prefix allows searching for the >> + content-type of attachments, which is now indexed by `notmuch >> + insert`. See the `notmuch-search-terms` manual page for details. >> + Jani> Admittedly I did not have the time to dig into details, but I think Jani> "attachment" is misleading, as it's really all mime parts, right? Jani> Will this also index the Content-Type: header of the message itself, Jani> regardless of whether it has mime structure or not? Maybe it Jani> should? Yes, all mime-parts. It does not index the Content-Type of the message itself. That probably wouldn't be difficult to add if it's a desired feature, but if there are plans for indexing other message headers it may fit better there. I also wasn't too happy with a "contenttype" keyword and debated just indexing the information under "attachment" along with the filename. >> Stopped `notmuch dump` failing if someone writes to the database >> >> The dump command now takes the write lock when running. This >> diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash >> index d58dc8b..05b5969 100644 >> --- a/completion/notmuch-completion.bash >> +++ b/completion/notmuch-completion.bash >> @@ -61,7 +61,7 @@ _notmuch_search_terms() >> sed "s|^$path/||" | grep -v "\(^\|/\)\(cur\|new\|tmp\)$" ) ) >> ;; >> *) >> -local search_terms="from: to: subject: attachment: tag: id: thread: folder: path: date:" >> +local search_terms="from: to: subject: attachment: contenttype: tag: id: thread: folder: path: date:" >> compopt -o nospace >> COMPREPLY=( $(compgen -W "${search_terms}" -- ${cur}) ) >> ;; >> diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst >> index 1acdaa0..d126ce6 100644 >> --- a/doc/man7/notmuch-search-terms.rst >> +++ b/doc/man7/notmuch-search-terms.rst >> @@ -40,6 +40,8 @@ indicate user-supplied values): >> >> - attachment: >> >> +- contenttype: >> + >> - tag: (or is:) >> >> - id: >> @@ -66,6 +68,10 @@ by including quotation marks around the phrase, immediately following >> The **attachment:** prefix can be used to search for specific filenames >> (or extensions) of attachments to email messages. >> >> +The **contenttype:** prefix can be used to search for specific >> +content-types of attachments to email messages (as specified by the >> +sender). >> + >> For **tag:** and **is:** valid tag values include **inbox** and >> **unread** by default for new messages added by **notmuch new** as well >> as any other tag values added manually with **notmuch tag**. >> diff --git a/emacs/notmuch.el b/emacs/notmuch.el >> index 218486a..702700c 100644 >> --- a/emacs/notmuch.el >> +++ b/emacs/notmuch.el >> @@ -858,7 +858,7 @@ PROMPT is the string to prompt with." >> (lexical-let >> ((completions >> (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:" >> - "subject:" "attachment:") >> + "subject:" "attachment:" "contenttype:") >> (mapcar (lambda (tag) >> (concat "tag:" (notmuch-escape-boolean-term tag))) >> (process-lines notmuch-command "search" "--output=tags" "*") >> diff --git a/lib/database.cc b/lib/database.cc >> index 3601f9d..a7a64c9 100644 >> --- a/lib/database.cc >> +++
[PATCH] Index Content-Type of attachments with a contenttype prefix
> "DB" == David Bremner writes: DB> Todd writes: >> I wanted to tag messages with calendar invitations, but couldn't as >> the information wasn't indexed. >> >> This patch allows for queries for like: >> >> Find calendar invites >> - contenttype:text/calendar or contenttype:applicaton/ics >> >> Find any image attachments >> - contenttype:image >> >> Find all patches >> - contenttype:text/x-patch DB> The main issue, that I won't really address in this message (because I'm DB> hoping Austin finds time to comment) is upgrading the database. The short DB> version is that a new "database feature" needs to be created. I just discovered and starting using notmuch this week, so I'm not entirely familiar with the project yet. I had suspected there might be more work :) I'll look into the "database feature". My other thought was to just index the content-type with the attachment prefix. This would have made the first search that I attempted (without reading the docs/source) work (e.g. attachment:text/calendar or attachment:application/ics). Is this preferred to adding a new search term? >> --- a/NEWS >> +++ b/NEWS >> @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. >> Command-Line Interface >> -- DB> Minor point, 0.19 was released, you should start a new NEWS section for DB> 0.20 with date UNRELEASED I'll make that change. >> --- a/completion/notmuch-completion.bash >> +++ b/completion/notmuch-completion.bash DB> If you can without too much suffering, it would be nice to update the zsh completion at the same DB> time. I don't use zsh, but I'll look into what's needed. >> +The **contenttype:** prefix can be used to search for specific >> +content-types of attachments to email messages (as specified by the >> +sender). >> + DB> I'm not 100% sure, but I did wonder if the docs should mention MIME DB> somewhere, for people searching. Agreed. >> { "attachment", "XATTACHMENT" }, >> +{ "contenttype","XCONTENTTYPE"}, >> { "subject", "XSUBJECT"}, DB> I didn't work through all the details, but I did wonder if it was in DB> some sense redundant to be indexing contenttype and also the existing DB> attachement and encrypted pseudotags. I guess this might be one of DB> those cases where we are stuck with the extra indexing for now, until we DB> sort out some query parsing issues. DB> d - Todd
Re: [PATCH] Index Content-Type of attachments with a contenttype prefix
Todd t...@electricoding.com writes: I wanted to tag messages with calendar invitations, but couldn't as the information wasn't indexed. This patch allows for queries for like: Find calendar invites - contenttype:text/calendar or contenttype:applicaton/ics Find any image attachments - contenttype:image Find all patches - contenttype:text/x-patch The main issue, that I won't really address in this message (because I'm hoping Austin finds time to comment) is upgrading the database. The short version is that a new database feature needs to be created. --- a/NEWS +++ b/NEWS @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. Command-Line Interface -- Minor point, 0.19 was released, you should start a new NEWS section for 0.20 with date UNRELEASED --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash If you can without too much suffering, it would be nice to update the zsh completion at the same time. +The **contenttype:** prefix can be used to search for specific +content-types of attachments to email messages (as specified by the +sender). + I'm not 100% sure, but I did wonder if the docs should mention MIME somewhere, for people searching. { attachment, XATTACHMENT }, +{ contenttype, XCONTENTTYPE}, { subject, XSUBJECT}, I didn't work through all the details, but I did wonder if it was in some sense redundant to be indexing contenttype and also the existing attachement and encrypted pseudotags. I guess this might be one of those cases where we are stuck with the extra indexing for now, until we sort out some query parsing issues. d ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH] Index Content-Type of attachments with a contenttype prefix
Jani == Jani Nikula j...@nikula.org writes: Jani On Sat, 10 Jan 2015, Todd t...@electricoding.com wrote: I wanted to tag messages with calendar invitations, but couldn't as the information wasn't indexed. This patch allows for queries for like: Find calendar invites - contenttype:text/calendar or contenttype:applicaton/ics Find any image attachments - contenttype:image Find all patches - contenttype:text/x-patch - Todd --- NEWS | 6 ++ completion/notmuch-completion.bash | 2 +- doc/man7/notmuch-search-terms.rst | 6 ++ emacs/notmuch.el | 2 +- lib/database.cc| 1 + lib/index.cc | 5 + test/T190-multipart.sh | 32 Jani IMO these could be split into several patches. No problem, I'll split them up the next time I post. 7 files changed, 52 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 44e8d05..5f4622c 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. Command-Line Interface -- +There is a new `contenttype:` search prefix + + The new `contenttype:` search prefix allows searching for the + content-type of attachments, which is now indexed by `notmuch + insert`. See the `notmuch-search-terms` manual page for details. + Jani Admittedly I did not have the time to dig into details, but I think Jani attachment is misleading, as it's really all mime parts, right? Jani Will this also index the Content-Type: header of the message itself, Jani regardless of whether it has mime structure or not? Maybe it Jani should? Yes, all mime-parts. It does not index the Content-Type of the message itself. That probably wouldn't be difficult to add if it's a desired feature, but if there are plans for indexing other message headers it may fit better there. I also wasn't too happy with a contenttype keyword and debated just indexing the information under attachment along with the filename. Stopped `notmuch dump` failing if someone writes to the database The dump command now takes the write lock when running. This diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index d58dc8b..05b5969 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -61,7 +61,7 @@ _notmuch_search_terms() sed s|^$path/|| | grep -v \(^\|/\)\(cur\|new\|tmp\)$ ) ) ;; *) -local search_terms=from: to: subject: attachment: tag: id: thread: folder: path: date: +local search_terms=from: to: subject: attachment: contenttype: tag: id: thread: folder: path: date: compopt -o nospace COMPREPLY=( $(compgen -W ${search_terms} -- ${cur}) ) ;; diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst index 1acdaa0..d126ce6 100644 --- a/doc/man7/notmuch-search-terms.rst +++ b/doc/man7/notmuch-search-terms.rst @@ -40,6 +40,8 @@ indicate user-supplied values): - attachment:word +- contenttype:word + - tag:tag (or is:tag) - id:message-id @@ -66,6 +68,10 @@ by including quotation marks around the phrase, immediately following The **attachment:** prefix can be used to search for specific filenames (or extensions) of attachments to email messages. +The **contenttype:** prefix can be used to search for specific +content-types of attachments to email messages (as specified by the +sender). + For **tag:** and **is:** valid tag values include **inbox** and **unread** by default for new messages added by **notmuch new** as well as any other tag values added manually with **notmuch tag**. diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 218486a..702700c 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -858,7 +858,7 @@ PROMPT is the string to prompt with. (lexical-let ((completions (append (list folder: path: thread: id: date: from: to: - subject: attachment:) + subject: attachment: contenttype:) (mapcar (lambda (tag) (concat tag: (notmuch-escape-boolean-term tag))) (process-lines notmuch-command search --output=tags *) diff --git a/lib/database.cc b/lib/database.cc index 3601f9d..a7a64c9 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -254,6 +254,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= { { from,XFROM }, { to, XTO }, { attachment, XATTACHMENT },
Re: [PATCH] Index Content-Type of attachments with a contenttype prefix
On Sat, 10 Jan 2015, Todd t...@electricoding.com wrote: I wanted to tag messages with calendar invitations, but couldn't as the information wasn't indexed. This patch allows for queries for like: Find calendar invites - contenttype:text/calendar or contenttype:applicaton/ics Find any image attachments - contenttype:image Find all patches - contenttype:text/x-patch - Todd --- NEWS | 6 ++ completion/notmuch-completion.bash | 2 +- doc/man7/notmuch-search-terms.rst | 6 ++ emacs/notmuch.el | 2 +- lib/database.cc| 1 + lib/index.cc | 5 + test/T190-multipart.sh | 32 IMO these could be split into several patches. 7 files changed, 52 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 44e8d05..5f4622c 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. Command-Line Interface -- +There is a new `contenttype:` search prefix + + The new `contenttype:` search prefix allows searching for the + content-type of attachments, which is now indexed by `notmuch + insert`. See the `notmuch-search-terms` manual page for details. + Admittedly I did not have the time to dig into details, but I think attachment is misleading, as it's really all mime parts, right? Will this also index the Content-Type: header of the message itself, regardless of whether it has mime structure or not? Maybe it should? Stopped `notmuch dump` failing if someone writes to the database The dump command now takes the write lock when running. This diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index d58dc8b..05b5969 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -61,7 +61,7 @@ _notmuch_search_terms() sed s|^$path/|| | grep -v \(^\|/\)\(cur\|new\|tmp\)$ ) ) ;; *) - local search_terms=from: to: subject: attachment: tag: id: thread: folder: path: date: + local search_terms=from: to: subject: attachment: contenttype: tag: id: thread: folder: path: date: compopt -o nospace COMPREPLY=( $(compgen -W ${search_terms} -- ${cur}) ) ;; diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst index 1acdaa0..d126ce6 100644 --- a/doc/man7/notmuch-search-terms.rst +++ b/doc/man7/notmuch-search-terms.rst @@ -40,6 +40,8 @@ indicate user-supplied values): - attachment:word +- contenttype:word + - tag:tag (or is:tag) - id:message-id @@ -66,6 +68,10 @@ by including quotation marks around the phrase, immediately following The **attachment:** prefix can be used to search for specific filenames (or extensions) of attachments to email messages. +The **contenttype:** prefix can be used to search for specific +content-types of attachments to email messages (as specified by the +sender). + For **tag:** and **is:** valid tag values include **inbox** and **unread** by default for new messages added by **notmuch new** as well as any other tag values added manually with **notmuch tag**. diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 218486a..702700c 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -858,7 +858,7 @@ PROMPT is the string to prompt with. (lexical-let ((completions (append (list folder: path: thread: id: date: from: to: - subject: attachment:) + subject: attachment: contenttype:) (mapcar (lambda (tag) (concat tag: (notmuch-escape-boolean-term tag))) (process-lines notmuch-command search --output=tags *) diff --git a/lib/database.cc b/lib/database.cc index 3601f9d..a7a64c9 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -254,6 +254,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= { { from,XFROM }, { to, XTO }, { attachment, XATTACHMENT }, +{ contenttype, XCONTENTTYPE}, { subject, XSUBJECT}, Is the use of probabilistic prefix intentional? I think it's probably the right thing to do, but just checking. BR, Jani. }; diff --git a/lib/index.cc b/lib/index.cc index 1a2e63d..c3f7c6b 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -346,6 +346,11 @@ _index_mime_part (notmuch_message_t *message, return; } +GMimeContentType* content_type = g_mime_object_get_content_type(part); +if (content_type) { + _notmuch_message_gen_terms (message, contenttype, g_mime_content_type_to_string(content_type)); +} + if (GMIME_IS_MESSAGE_PART (part)) { GMimeMessage *mime_message; diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh index 85cbf67..e3270a7 100755 ---
Re: [PATCH] Index Content-Type of attachments with a contenttype prefix
DB == David Bremner da...@tethera.net writes: DB Todd t...@electricoding.com writes: I wanted to tag messages with calendar invitations, but couldn't as the information wasn't indexed. This patch allows for queries for like: Find calendar invites - contenttype:text/calendar or contenttype:applicaton/ics Find any image attachments - contenttype:image Find all patches - contenttype:text/x-patch DB The main issue, that I won't really address in this message (because I'm DB hoping Austin finds time to comment) is upgrading the database. The short DB version is that a new database feature needs to be created. I just discovered and starting using notmuch this week, so I'm not entirely familiar with the project yet. I had suspected there might be more work :) I'll look into the database feature. My other thought was to just index the content-type with the attachment prefix. This would have made the first search that I attempted (without reading the docs/source) work (e.g. attachment:text/calendar or attachment:application/ics). Is this preferred to adding a new search term? --- a/NEWS +++ b/NEWS @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. Command-Line Interface -- DB Minor point, 0.19 was released, you should start a new NEWS section for DB 0.20 with date UNRELEASED I'll make that change. --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash DB If you can without too much suffering, it would be nice to update the zsh completion at the same DB time. I don't use zsh, but I'll look into what's needed. +The **contenttype:** prefix can be used to search for specific +content-types of attachments to email messages (as specified by the +sender). + DB I'm not 100% sure, but I did wonder if the docs should mention MIME DB somewhere, for people searching. Agreed. { attachment, XATTACHMENT }, +{ contenttype,XCONTENTTYPE}, { subject, XSUBJECT}, DB I didn't work through all the details, but I did wonder if it was in DB some sense redundant to be indexing contenttype and also the existing DB attachement and encrypted pseudotags. I guess this might be one of DB those cases where we are stuck with the extra indexing for now, until we DB sort out some query parsing issues. DB d - Todd ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH] Index Content-Type of attachments with a contenttype prefix
I wanted to tag messages with calendar invitations, but couldn't as the information wasn't indexed. This patch allows for queries for like: Find calendar invites - contenttype:text/calendar or contenttype:applicaton/ics Find any image attachments - contenttype:image Find all patches - contenttype:text/x-patch - Todd --- NEWS | 6 ++ completion/notmuch-completion.bash | 2 +- doc/man7/notmuch-search-terms.rst | 6 ++ emacs/notmuch.el | 2 +- lib/database.cc| 1 + lib/index.cc | 5 + test/T190-multipart.sh | 32 7 files changed, 52 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 44e8d05..5f4622c 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. Command-Line Interface -- +There is a new `contenttype:` search prefix + + The new `contenttype:` search prefix allows searching for the + content-type of attachments, which is now indexed by `notmuch + insert`. See the `notmuch-search-terms` manual page for details. + Stopped `notmuch dump` failing if someone writes to the database The dump command now takes the write lock when running. This diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index d58dc8b..05b5969 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -61,7 +61,7 @@ _notmuch_search_terms() sed "s|^$path/||" | grep -v "\(^\|/\)\(cur\|new\|tmp\)$" ) ) ;; *) - local search_terms="from: to: subject: attachment: tag: id: thread: folder: path: date:" + local search_terms="from: to: subject: attachment: contenttype: tag: id: thread: folder: path: date:" compopt -o nospace COMPREPLY=( $(compgen -W "${search_terms}" -- ${cur}) ) ;; diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst index 1acdaa0..d126ce6 100644 --- a/doc/man7/notmuch-search-terms.rst +++ b/doc/man7/notmuch-search-terms.rst @@ -40,6 +40,8 @@ indicate user-supplied values): - attachment: +- contenttype: + - tag: (or is:) - id: @@ -66,6 +68,10 @@ by including quotation marks around the phrase, immediately following The **attachment:** prefix can be used to search for specific filenames (or extensions) of attachments to email messages. +The **contenttype:** prefix can be used to search for specific +content-types of attachments to email messages (as specified by the +sender). + For **tag:** and **is:** valid tag values include **inbox** and **unread** by default for new messages added by **notmuch new** as well as any other tag values added manually with **notmuch tag**. diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 218486a..702700c 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -858,7 +858,7 @@ PROMPT is the string to prompt with." (lexical-let ((completions (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:" - "subject:" "attachment:") + "subject:" "attachment:" "contenttype:") (mapcar (lambda (tag) (concat "tag:" (notmuch-escape-boolean-term tag))) (process-lines notmuch-command "search" "--output=tags" "*") diff --git a/lib/database.cc b/lib/database.cc index 3601f9d..a7a64c9 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -254,6 +254,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= { { "from", "XFROM" }, { "to","XTO" }, { "attachment","XATTACHMENT" }, +{ "contenttype", "XCONTENTTYPE"}, { "subject", "XSUBJECT"}, }; diff --git a/lib/index.cc b/lib/index.cc index 1a2e63d..c3f7c6b 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -346,6 +346,11 @@ _index_mime_part (notmuch_message_t *message, return; } +GMimeContentType* content_type = g_mime_object_get_content_type(part); +if (content_type) { + _notmuch_message_gen_terms (message, "contenttype", g_mime_content_type_to_string(content_type)); +} + if (GMIME_IS_MESSAGE_PART (part)) { GMimeMessage *mime_message; diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh index 85cbf67..e3270a7 100755 --- a/test/T190-multipart.sh +++ b/test/T190-multipart.sh @@ -104,6 +104,30 @@ Content-Transfer-Encoding: base64 7w0K --==-=-=-- EOF + +cat < content_types +From: Todd +To: todd at electricoding.com +Subject: odd content types +Date: Fri, 05 Jan 2001 15:42:57 + +User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu) +Message-ID: <87liy5ap01.fsf at yoom.home.cworth.org> +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="==-=-==" + +--==-=-== +Content-Type: application/unique_identifier + +This
[PATCH] Index Content-Type of attachments with a contenttype prefix
I wanted to tag messages with calendar invitations, but couldn't as the information wasn't indexed. This patch allows for queries for like: Find calendar invites - contenttype:text/calendar or contenttype:applicaton/ics Find any image attachments - contenttype:image Find all patches - contenttype:text/x-patch - Todd --- NEWS | 6 ++ completion/notmuch-completion.bash | 2 +- doc/man7/notmuch-search-terms.rst | 6 ++ emacs/notmuch.el | 2 +- lib/database.cc| 1 + lib/index.cc | 5 + test/T190-multipart.sh | 32 7 files changed, 52 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 44e8d05..5f4622c 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,12 @@ keyboard shortcuts to saved searches. Command-Line Interface -- +There is a new `contenttype:` search prefix + + The new `contenttype:` search prefix allows searching for the + content-type of attachments, which is now indexed by `notmuch + insert`. See the `notmuch-search-terms` manual page for details. + Stopped `notmuch dump` failing if someone writes to the database The dump command now takes the write lock when running. This diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash index d58dc8b..05b5969 100644 --- a/completion/notmuch-completion.bash +++ b/completion/notmuch-completion.bash @@ -61,7 +61,7 @@ _notmuch_search_terms() sed s|^$path/|| | grep -v \(^\|/\)\(cur\|new\|tmp\)$ ) ) ;; *) - local search_terms=from: to: subject: attachment: tag: id: thread: folder: path: date: + local search_terms=from: to: subject: attachment: contenttype: tag: id: thread: folder: path: date: compopt -o nospace COMPREPLY=( $(compgen -W ${search_terms} -- ${cur}) ) ;; diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst index 1acdaa0..d126ce6 100644 --- a/doc/man7/notmuch-search-terms.rst +++ b/doc/man7/notmuch-search-terms.rst @@ -40,6 +40,8 @@ indicate user-supplied values): - attachment:word +- contenttype:word + - tag:tag (or is:tag) - id:message-id @@ -66,6 +68,10 @@ by including quotation marks around the phrase, immediately following The **attachment:** prefix can be used to search for specific filenames (or extensions) of attachments to email messages. +The **contenttype:** prefix can be used to search for specific +content-types of attachments to email messages (as specified by the +sender). + For **tag:** and **is:** valid tag values include **inbox** and **unread** by default for new messages added by **notmuch new** as well as any other tag values added manually with **notmuch tag**. diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 218486a..702700c 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -858,7 +858,7 @@ PROMPT is the string to prompt with. (lexical-let ((completions (append (list folder: path: thread: id: date: from: to: - subject: attachment:) + subject: attachment: contenttype:) (mapcar (lambda (tag) (concat tag: (notmuch-escape-boolean-term tag))) (process-lines notmuch-command search --output=tags *) diff --git a/lib/database.cc b/lib/database.cc index 3601f9d..a7a64c9 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -254,6 +254,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= { { from, XFROM }, { to,XTO }, { attachment,XATTACHMENT }, +{ contenttype, XCONTENTTYPE}, { subject, XSUBJECT}, }; diff --git a/lib/index.cc b/lib/index.cc index 1a2e63d..c3f7c6b 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -346,6 +346,11 @@ _index_mime_part (notmuch_message_t *message, return; } +GMimeContentType* content_type = g_mime_object_get_content_type(part); +if (content_type) { + _notmuch_message_gen_terms (message, contenttype, g_mime_content_type_to_string(content_type)); +} + if (GMIME_IS_MESSAGE_PART (part)) { GMimeMessage *mime_message; diff --git a/test/T190-multipart.sh b/test/T190-multipart.sh index 85cbf67..e3270a7 100755 --- a/test/T190-multipart.sh +++ b/test/T190-multipart.sh @@ -104,6 +104,30 @@ Content-Transfer-Encoding: base64 7w0K --==-=-=-- EOF + +cat EOF content_types +From: Todd t...@electricoding.com +To: t...@electricoding.com +Subject: odd content types +Date: Fri, 05 Jan 2001 15:42:57 + +User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.3.1 (i486-pc-linux-gnu) +Message-ID: 87liy5ap01@yoom.home.cworth.org +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary===-=-== + +--==-=-== +Content-Type: application/unique_identifier + +pThis is an embedded message,