Fix mbox scanning

This commit is contained in:
Michal Horejsek
2020-10-12 15:23:19 +02:00
parent e4a341af3a
commit 64fbcdc1ca

View File

@ -40,6 +40,8 @@ func getGmailLabelsFromMboxFile(filePath string) (stringSet, error) {
func getGmailLabelsFromMboxReader(f io.Reader) (stringSet, error) { func getGmailLabelsFromMboxReader(f io.Reader) (stringSet, error) {
allLabels := map[string]bool{} allLabels := map[string]bool{}
// Scanner is not used as it does not support long lines and some mbox
// files contain very long lines even though that should not be happening.
r := bufio.NewReader(f) r := bufio.NewReader(f)
for { for {
b, isPrefix, err := r.ReadLine() b, isPrefix, err := r.ReadLine()
@ -49,14 +51,11 @@ func getGmailLabelsFromMboxReader(f io.Reader) (stringSet, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if isPrefix { for isPrefix {
for !isPrefix { _, isPrefix, err = r.ReadLine()
_, isPrefix, err = r.ReadLine() if err != nil {
if err != nil { break
break
}
} }
continue
} }
if bytes.HasPrefix(b, []byte(xGmailLabelsHeader)) { if bytes.HasPrefix(b, []byte(xGmailLabelsHeader)) {
for label := range getGmailLabelsFromValue(string(b)) { for label := range getGmailLabelsFromValue(string(b)) {