@@ -11,6 +11,15 @@ import (
1111 "github.com/floatpane/matcha/daemonrpc"
1212)
1313
14+ // Per-handler timeouts. fetchTimeout covers reads against the upstream IMAP
15+ // provider, which can return large bodies and so are given more headroom.
16+ // mutateTimeout covers state-changing operations and folder listings, which
17+ // are bounded by IMAP command latency rather than payload size.
18+ const (
19+ fetchTimeout = 60 * time .Second
20+ mutateTimeout = 30 * time .Second
21+ )
22+
1423func (d * Daemon ) handleRequest (conn * daemonrpc.Conn , req * daemonrpc.Request ) {
1524 switch req .Method {
1625 case daemonrpc .MethodPing :
@@ -117,7 +126,7 @@ func (d *Daemon) handleFetchEmails(conn *daemonrpc.Conn, req *daemonrpc.Request)
117126 return
118127 }
119128
120- ctx , cancel := context .WithTimeout (context .Background (), 60 * time . Second )
129+ ctx , cancel := context .WithTimeout (context .Background (), fetchTimeout )
121130 defer cancel ()
122131
123132 emails , err := p .FetchEmails (ctx , params .Folder , params .Limit , params .Offset )
@@ -142,7 +151,7 @@ func (d *Daemon) handleFetchEmailBody(conn *daemonrpc.Conn, req *daemonrpc.Reque
142151 return
143152 }
144153
145- ctx , cancel := context .WithTimeout (context .Background (), 60 * time . Second )
154+ ctx , cancel := context .WithTimeout (context .Background (), fetchTimeout )
146155 defer cancel ()
147156
148157 body , attachments , err := p .FetchEmailBody (ctx , params .Folder , params .UID )
@@ -181,7 +190,7 @@ func (d *Daemon) handleDeleteEmails(conn *daemonrpc.Conn, req *daemonrpc.Request
181190 return
182191 }
183192
184- ctx , cancel := context .WithTimeout (context .Background (), 30 * time . Second )
193+ ctx , cancel := context .WithTimeout (context .Background (), mutateTimeout )
185194 defer cancel ()
186195
187196 if err := p .DeleteEmails (ctx , params .Folder , params .UIDs ); err != nil {
@@ -204,7 +213,7 @@ func (d *Daemon) handleArchiveEmails(conn *daemonrpc.Conn, req *daemonrpc.Reques
204213 return
205214 }
206215
207- ctx , cancel := context .WithTimeout (context .Background (), 30 * time . Second )
216+ ctx , cancel := context .WithTimeout (context .Background (), mutateTimeout )
208217 defer cancel ()
209218
210219 if err := p .ArchiveEmails (ctx , params .Folder , params .UIDs ); err != nil {
@@ -227,7 +236,7 @@ func (d *Daemon) handleMoveEmails(conn *daemonrpc.Conn, req *daemonrpc.Request)
227236 return
228237 }
229238
230- ctx , cancel := context .WithTimeout (context .Background (), 30 * time . Second )
239+ ctx , cancel := context .WithTimeout (context .Background (), mutateTimeout )
231240 defer cancel ()
232241
233242 if err := p .MoveEmails (ctx , params .UIDs , params .SourceFolder , params .DestFolder ); err != nil {
@@ -250,7 +259,7 @@ func (d *Daemon) handleMarkRead(conn *daemonrpc.Conn, req *daemonrpc.Request) {
250259 return
251260 }
252261
253- ctx , cancel := context .WithTimeout (context .Background (), 30 * time . Second )
262+ ctx , cancel := context .WithTimeout (context .Background (), mutateTimeout )
254263 defer cancel ()
255264
256265 // MarkAsRead only supports one UID at a time in the Provider interface.
@@ -275,7 +284,7 @@ func (d *Daemon) handleFetchFolders(conn *daemonrpc.Conn, req *daemonrpc.Request
275284 return
276285 }
277286
278- ctx , cancel := context .WithTimeout (context .Background (), 30 * time . Second )
287+ ctx , cancel := context .WithTimeout (context .Background (), mutateTimeout )
279288 defer cancel ()
280289
281290 folders , err := p .FetchFolders (ctx )
@@ -306,7 +315,7 @@ func (d *Daemon) handleRefreshFolder(conn *daemonrpc.Conn, req *daemonrpc.Reques
306315 Folder : params .Folder ,
307316 })
308317
309- ctx , cancel := context .WithTimeout (context .Background (), 60 * time . Second )
318+ ctx , cancel := context .WithTimeout (context .Background (), fetchTimeout )
310319 defer cancel ()
311320
312321 emails , err := p .FetchEmails (ctx , params .Folder , 50 , 0 )
0 commit comments