-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathutil.go
More file actions
24 lines (21 loc) · 719 Bytes
/
Copy pathutil.go
File metadata and controls
24 lines (21 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package imap
import "fmt"
// dropNl removes trailing newline characters from a byte slice
func dropNl(b []byte) []byte {
if len(b) >= 1 && b[len(b)-1] == '\n' {
if len(b) >= 2 && b[len(b)-2] == '\r' {
return b[:len(b)-2]
} else {
return b[:len(b)-1]
}
}
return b
}
// MakeIMAPLiteral generates IMAP literal syntax for non-ASCII strings.
// It returns a string in the format "{bytecount}\r\ntext" where bytecount
// is the number of bytes (not characters) in the input string.
// This is useful for search queries with non-ASCII characters.
// Example: MakeIMAPLiteral("тест") returns "{8}\r\nтест"
func MakeIMAPLiteral(s string) string {
return fmt.Sprintf("{%d}\r\n%s", len([]byte(s)), s)
}