@@ -17,13 +17,35 @@ type (
17
17
type UserSession struct {
18
18
* user // immutable
19
19
* mailbox // may be nil
20
+
21
+ // appendLimit is the maximum size in bytes that can be uploaded to this server
22
+ // in an APPEND command
23
+ appendLimit uint32
24
+
25
+ // discloseLimit indicates whether the append limit should be advertised in the
26
+ // CAPABILITY response
27
+ discloseLimit bool
20
28
}
21
29
22
30
var _ imapserver.SessionIMAP4rev2 = (* UserSession )(nil )
31
+ var _ imapserver.SessionAppendLimit = (* UserSession )(nil )
23
32
24
33
// NewUserSession creates a new user session.
25
34
func NewUserSession (user * User ) * UserSession {
26
- return & UserSession {user : user }
35
+ return & UserSession {
36
+ user : user ,
37
+ appendLimit : 104857600 , // 100 MiB default
38
+ discloseLimit : true , // By default, disclose the limit in CAPABILITY
39
+ }
40
+ }
41
+
42
+ // NewUserSessionWithAppendLimit creates a new user session with a custom append limit.
43
+ func NewUserSessionWithAppendLimit (user * User , appendLimit uint32 , discloseLimit bool ) * UserSession {
44
+ return & UserSession {
45
+ user : user ,
46
+ appendLimit : appendLimit ,
47
+ discloseLimit : discloseLimit ,
48
+ }
27
49
}
28
50
29
51
func (sess * UserSession ) Close () error {
@@ -138,3 +160,19 @@ func (sess *UserSession) Idle(w *imapserver.UpdateWriter, stop <-chan struct{})
138
160
}
139
161
return sess .mailbox .Idle (w , stop )
140
162
}
163
+
164
+ // AppendLimit implements the SessionAppendLimit interface.
165
+ // It returns the maximum size in bytes that can be uploaded to this server in an APPEND command.
166
+ func (sess * UserSession ) AppendLimit () uint32 {
167
+ // If appendLimit is not set (0), return a default large value
168
+ if sess .appendLimit == 0 {
169
+ return 104857600 // 100 MiB default
170
+ }
171
+ return sess .appendLimit
172
+ }
173
+
174
+ // DiscloseLimit implements the SessionAppendLimit interface.
175
+ // It indicates whether the append limit should be advertised in the CAPABILITY response.
176
+ func (sess * UserSession ) DiscloseLimit () bool {
177
+ return sess .discloseLimit
178
+ }
0 commit comments