-
Notifications
You must be signed in to change notification settings - Fork 329
imapserver: advertise APPENDLIMIT capability #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,35 @@ type ( | |
type UserSession struct { | ||
*user // immutable | ||
*mailbox // may be nil | ||
|
||
// appendLimit is the maximum size in bytes that can be uploaded to this server | ||
// in an APPEND command | ||
appendLimit uint32 | ||
|
||
// discloseLimit indicates whether the append limit should be advertised in the | ||
// CAPABILITY response | ||
discloseLimit bool | ||
} | ||
|
||
var _ imapserver.SessionIMAP4rev2 = (*UserSession)(nil) | ||
var _ imapserver.SessionAppendLimit = (*UserSession)(nil) | ||
|
||
// NewUserSession creates a new user session. | ||
func NewUserSession(user *User) *UserSession { | ||
return &UserSession{user: user} | ||
return &UserSession{ | ||
user: user, | ||
appendLimit: 104857600, // 100 MiB default | ||
discloseLimit: true, // By default, disclose the limit in CAPABILITY | ||
} | ||
} | ||
|
||
// NewUserSessionWithAppendLimit creates a new user session with a custom append limit. | ||
func NewUserSessionWithAppendLimit(user *User, appendLimit uint32, discloseLimit bool) *UserSession { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we keep this simple and only have a single global append limit in imapmemserver? |
||
return &UserSession{ | ||
user: user, | ||
appendLimit: appendLimit, | ||
discloseLimit: discloseLimit, | ||
} | ||
} | ||
|
||
func (sess *UserSession) Close() error { | ||
|
@@ -138,3 +160,19 @@ func (sess *UserSession) Idle(w *imapserver.UpdateWriter, stop <-chan struct{}) | |
} | ||
return sess.mailbox.Idle(w, stop) | ||
} | ||
|
||
// AppendLimit implements the SessionAppendLimit interface. | ||
// It returns the maximum size in bytes that can be uploaded to this server in an APPEND command. | ||
func (sess *UserSession) AppendLimit() uint32 { | ||
// If appendLimit is not set (0), return a default large value | ||
if sess.appendLimit == 0 { | ||
return 104857600 // 100 MiB default | ||
} | ||
return sess.appendLimit | ||
} | ||
|
||
// DiscloseLimit implements the SessionAppendLimit interface. | ||
// It indicates whether the append limit should be advertised in the CAPABILITY response. | ||
func (sess *UserSession) DiscloseLimit() bool { | ||
return sess.discloseLimit | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,3 +114,18 @@ type SessionUnauthenticate interface { | |
// Authenticated state | ||
Unauthenticate() error | ||
} | ||
|
||
// SessionAppendLimit is an IMAP session which has the same APPEND limit for | ||
// all mailboxes. | ||
type SessionAppendLimit interface { | ||
Session | ||
|
||
// AppendLimit returns the maximum size in bytes that can be uploaded to this server | ||
// in an APPEND command. | ||
AppendLimit() uint32 | ||
|
||
// DiscloseLimit indicates whether the limit should be advertised in the CAPABILITY | ||
// response. If false, only "APPENDLIMIT" will be listed, without the actual limit. | ||
// If true, "APPENDLIMIT=<limit>" will be listed. | ||
DiscloseLimit() bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the purpose of this method? Servers can already reject literals which are too large in APPEND without advertising a limit (by returning an error). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. APPENDLIMIT capability can be advertised as APPENDLIMIT only or with explicit limit APPENDLIMIT=. In first you have to try to discover the limit while in the second you know before you try. The method allows to server to configure whether it will advertise it or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I'm not sure I'm following. If APPENDLIMIT is listed in How about the following:
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep this comment next to the
addAvailableCaps
list below?