-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch-2.0.3.bk.gmail-customsearch.1
154 lines (146 loc) · 4.96 KB
/
patch-2.0.3.bk.gmail-customsearch.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
diff --git a/PATCHES b/PATCHES
index e69de29b..da7f1db0 100644
--- a/PATCHES
+++ b/PATCHES
@@ -0,0 +1 @@
+pp.gmailcustomsearch
diff --git a/doc/manual.xml.head b/doc/manual.xml.head
index 36543eb5..f7bff066 100644
--- a/doc/manual.xml.head
+++ b/doc/manual.xml.head
@@ -5835,6 +5835,7 @@ e.g. replies to your messages: ~<(~P)</entry></row>
<row><entry>~>(<emphasis>PATTERN</emphasis>)</entry><entry>messages
having an immediate child matching <emphasis>PATTERN</emphasis>,
e.g. messages you replied to: ~>(~P)</entry></row>
+<row><entry>=/ <emphasis>STRING</emphasis></entry><entry>IMAP custom server-side search for <emphasis>STRING</emphasis>. Currently only defined for Gmail.</entry></row>
</tbody>
</tgroup>
</table>
diff --git a/imap/command.c b/imap/command.c
index 5ca04bf0..cd09303f 100644
--- a/imap/command.c
+++ b/imap/command.c
@@ -76,6 +76,7 @@ static const char * const Capabilities[] = {
"QRESYNC",
"LIST-EXTENDED",
"COMPRESS=DEFLATE",
+ "X-GM-EXT-1",
NULL
};
diff --git a/imap/imap.c b/imap/imap.c
index b13dd54d..56b0db0f 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -2135,6 +2135,9 @@ static int do_search (const pattern_t* search, int allpats)
if (pat->stringmatch)
rc++;
break;
+ case MUTT_SERVERSEARCH:
+ rc++;
+ break;
default:
if (pat->child && do_search (pat->child, 1))
rc++;
@@ -2150,7 +2153,7 @@ static int do_search (const pattern_t* search, int allpats)
/* convert mutt pattern_t to IMAP SEARCH command containing only elements
* that require full-text search (mutt already has what it needs for most
* match types, and does a better job (eg server doesn't support regexps). */
-static int imap_compile_search (const pattern_t* pat, BUFFER* buf)
+static int imap_compile_search (CONTEXT* ctx, const pattern_t* pat, BUFFER* buf)
{
if (! do_search (pat, 0))
return 0;
@@ -2176,7 +2179,7 @@ static int imap_compile_search (const pattern_t* pat, BUFFER* buf)
mutt_buffer_addstr (buf, "OR ");
clauses--;
- if (imap_compile_search (clause, buf) < 0)
+ if (imap_compile_search (ctx, clause, buf) < 0)
return -1;
if (clauses)
@@ -2227,6 +2230,19 @@ static int imap_compile_search (const pattern_t* pat, BUFFER* buf)
imap_quote_string (term, sizeof (term), pat->p.str);
mutt_buffer_addstr (buf, term);
break;
+ case MUTT_SERVERSEARCH:
+ {
+ IMAP_DATA* idata = (IMAP_DATA*)ctx->data;
+ if (!mutt_bit_isset (idata->capabilities, X_GM_EXT_1))
+ {
+ mutt_error(_("Server-side custom search not supported: %s"), pat->p.str);
+ return -1;
+ }
+ }
+ mutt_buffer_addstr (buf, "X-GM-RAW ");
+ imap_quote_string (term, sizeof (term), pat->p.str);
+ mutt_buffer_addstr (buf, term);
+ break;
}
}
@@ -2247,7 +2263,7 @@ int imap_search (CONTEXT* ctx, const pattern_t* pat)
mutt_buffer_init (&buf);
mutt_buffer_addstr (&buf, "UID SEARCH ");
- if (imap_compile_search (pat, &buf) < 0)
+ if (imap_compile_search (ctx, pat, &buf) < 0)
{
FREE (&buf.data);
return -1;
diff --git a/imap/imap_private.h b/imap/imap_private.h
index 42078349..7b97b654 100644
--- a/imap/imap_private.h
+++ b/imap/imap_private.h
@@ -123,6 +123,7 @@ enum
QRESYNC, /* RFC 7162 */
LIST_EXTENDED, /* RFC 5258: IMAP4 - LIST Command Extensions */
COMPRESS_DEFLATE, /* RFC 4978: COMPRESS=DEFLATE */
+ X_GM_EXT_1, /* Gmail IMAP Extensions */
CAPMAX
};
diff --git a/mutt.h b/mutt.h
index 8f45e67f..9b2997eb 100644
--- a/mutt.h
+++ b/mutt.h
@@ -275,6 +275,7 @@ enum
MUTT_XLABEL,
MUTT_MIMEATTACH,
MUTT_MIMETYPE,
+ MUTT_SERVERSEARCH,
/* Options for Mailcap lookup */
MUTT_EDIT,
diff --git a/pattern.c b/pattern.c
index 6957a7e8..c6a774a7 100644
--- a/pattern.c
+++ b/pattern.c
@@ -279,6 +279,11 @@ Flags[] =
Pattern Completion Menu description for ~$
*/
N_("unreferenced messages") },
+ { '/', MUTT_SERVERSEARCH, 0, EAT_REGEXP,
+ /* L10N:
+ Pattern Completion Menu description for =/
+ */
+ N_("gmail server-side search") },
{ 0, 0, 0, 0, NULL }
};
@@ -1648,6 +1653,22 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx,
return (h->matched);
#endif
return (pat->not ^ msg_search (ctx, pat, h->msgno));
+ case MUTT_SERVERSEARCH:
+#ifdef USE_IMAP
+ if (!ctx)
+ return 0;
+ if (ctx->magic == MUTT_IMAP)
+ {
+ if (pat->stringmatch)
+ return (h->matched);
+ return 0;
+ }
+ mutt_error (_("error: server custom search only supported with IMAP."));
+ return 0;
+#else
+ mutt_error (_("error: server custom search only supported with IMAP."));
+ return (-1);
+#endif
case MUTT_SENDER:
return (pat->not ^ match_adrlist (pat, flags & MUTT_MATCH_FULL_ADDRESS, 1,
h->env->sender));