Skip to content

Commit 1a15e07

Browse files
mercataemersion
andcommitted
imapserver: add support for APPENDLIMIT
Co-authored-by: Simon Ser <[email protected]>
1 parent 60b13fa commit 1a15e07

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

imapserver/append.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import (
1010
"github.com/emersion/go-imap/v2/internal/imapwire"
1111
)
1212

13-
// appendLimit is the maximum size of an APPEND payload.
14-
//
15-
// TODO: make configurable
16-
const appendLimit = 100 * 1024 * 1024 // 100MiB
13+
// defaultAppendLimit is the default maximum size of an APPEND payload.
14+
const defaultAppendLimit = 100 * 1024 * 1024 // 100MiB
1715

1816
func (c *Conn) handleAppend(tag string, dec *imapwire.Decoder) error {
1917
var (
@@ -66,6 +64,11 @@ func (c *Conn) handleAppend(tag string, dec *imapwire.Decoder) error {
6664
return err
6765
}
6866

67+
appendLimit := int64(defaultAppendLimit)
68+
if appendLimitSession, ok := c.session.(SessionAppendLimit); ok {
69+
appendLimit = int64(appendLimitSession.AppendLimit())
70+
}
71+
6972
if lit.Size() > appendLimit {
7073
return &imap.Error{
7174
Type: imap.StatusResponseTypeNo,

imapserver/capability.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package imapserver
22

33
import (
4+
"fmt"
5+
46
"github.com/emersion/go-imap/v2"
57
"github.com/emersion/go-imap/v2/internal/imapwire"
68
)
@@ -92,6 +94,13 @@ func (c *Conn) availableCaps() []imap.Cap {
9294
imap.CapLiteralPlus,
9395
imap.CapUnauthenticate,
9496
})
97+
98+
if appendLimitSession, ok := c.session.(SessionAppendLimit); ok {
99+
limit := appendLimitSession.AppendLimit()
100+
caps = append(caps, imap.Cap(fmt.Sprintf("APPENDLIMIT=%d", limit)))
101+
} else {
102+
addAvailableCaps(&caps, available, []imap.Cap{imap.CapAppendLimit})
103+
}
95104
}
96105
return caps
97106
}

imapserver/session.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,13 @@ type SessionUnauthenticate interface {
114114
// Authenticated state
115115
Unauthenticate() error
116116
}
117+
118+
// SessionAppendLimit is an IMAP session which has the same APPEND limit for
119+
// all mailboxes.
120+
type SessionAppendLimit interface {
121+
Session
122+
123+
// AppendLimit returns the maximum size in bytes that can be uploaded to
124+
// this server in an APPEND command.
125+
AppendLimit() uint32
126+
}

0 commit comments

Comments
 (0)