go-imap icon indicating copy to clipboard operation
go-imap copied to clipboard

v1: add support for raw search fields

Open ahornerr opened this issue 4 years ago • 6 comments

Hi there!

This is my first contribution to this library and I will say it's quite powerful!

I dug around this morning looking for ways to add arbitrary raw attributes to the search queries and was unable to do so. After further consideration it seems the best way would be to add native X-GM-RAW support to this library!

The specification can be found here https://developers.google.com/gmail/imap/imap-extensions but simply put, we can add a X-GM-RAW attribute to the search query.

I find this necessary to my use case and I believe others may also find it useful. I've added the correct logic and tests.

Thanks!

ahornerr avatar Jan 18 '20 21:01 ahornerr

Codecov Report

Merging #334 into master will increase coverage by 0.11%. The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #334      +/-   ##
==========================================
+ Coverage    73.4%   73.52%   +0.11%     
==========================================
  Files          32       32              
  Lines        3516     3531      +15     
==========================================
+ Hits         2581     2596      +15     
  Misses        642      642              
  Partials      293      293
Impacted Files Coverage Δ
search.go 64.4% <88.88%> (+2.27%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c79bafa...ff937cd. Read the comment docs.

codecov[bot] avatar Jan 18 '20 21:01 codecov[bot]

Agreed. I really don't want to support GMail's nonstandard flags upstream.

emersion avatar Jan 18 '20 22:01 emersion

@foxcpp @emersion This seems like a reasonable (and more flexible) request. I will make some changes.

ahornerr avatar Jan 18 '20 22:01 ahornerr

@emersion @foxcpp I've made some changes to generalize the raw search functionality. Originally I had Raw as a map[string][]interface{} but this made testing and repeatability tricky as Maps in Go are unsorted. By specifying them as an array we can ensure that they're always sorted in the same order. Let me know what you think!

ahornerr avatar Jan 18 '20 23:01 ahornerr

Actually I don't think this will work. As is my current approach adds parenthesis around the value which Gmail doesn't interpret as a good command.

UID SEARCH CHARSET UTF-8 ... X-GM-RAW ("filename:docx OR filename:xlsx")
BAD Could not parse command

I'll have to go back to the drawing board with this and correct my issue.

ahornerr avatar Jan 19 '20 00:01 ahornerr

I've pushed up a better solution that I'm happy with.

ahornerr avatar Jan 19 '20 01:01 ahornerr