annotate cmd/sievemgr/internal/config/parser.go @ 19:854167f55839

Fix SRV record lookup Do not use a configuration file default value for port in order to detect when it is not set by the user so that SRV record lookup is triggered. Depend on version 0.8.1 of go.guido-berhoerster.org/managesieve which contains an additional necessary fix.
author Guido Berhoerster <guido+sievemgr@berhoerster.name>
date Wed, 03 Feb 2021 13:34:44 +0100
parents 4dff4c3f0fbb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
1 // Copyright (C) 2020 Guido Berhoerster <guido+sievemgr@berhoerster.name>
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
2 //
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
3 // Permission is hereby granted, free of charge, to any person obtaining
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
4 // a copy of this software and associated documentation files (the
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
5 // "Software"), to deal in the Software without restriction, including
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
6 // without limitation the rights to use, copy, modify, merge, publish,
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
7 // distribute, sublicense, and/or sell copies of the Software, and to
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
8 // permit persons to whom the Software is furnished to do so, subject to
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
9 // the following conditions:
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
10 //
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
11 // The above copyright notice and this permission notice shall be included
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
12 // in all copies or substantial portions of the Software.
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
13 //
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
17 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
18 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
19 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
20 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
21
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
22 package config
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
23
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
24 import (
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
25 "fmt"
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
26 "strconv"
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
27 )
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
28
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
29 type parser struct {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
30 s *scanner
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
31 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
32
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
33 func (p *parser) scanType(expectedTok token) (string, error) {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
34 tok, lit, err := p.s.scan()
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
35 if err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
36 return lit, NewParserError(err.Error(), p.s.line)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
37 } else if tok != expectedTok {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
38 return lit, NewParserError(fmt.Sprintf("expected %s, got %s %q", expectedTok, tok, lit), p.s.line)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
39 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
40 return lit, nil
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
41 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
42
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
43 func (p *parser) validateAccount(acct *Account) error {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
44 if acct.Host == "" {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
45 return NewParserError(fmt.Sprintf("no host specified for account %q",
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
46 acct.Name), 0)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
47 } else if acct.User == "" {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
48 return NewParserError(fmt.Sprintf("no user specified for account %q",
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
49 acct.Name), 0)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
50 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
51 return nil
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
52 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
53
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
54 func (p *parser) parse(conf *Configuration) error {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
55 var acct *Account
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
56 var isDefault bool
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
57 var tok token
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
58 var lit string
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
59 var err error
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
60 parsing:
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
61 for {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
62 tok, lit, err = p.s.scan()
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
63 if err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
64 err = NewParserError(err.Error(), p.s.line)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
65 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
66 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
67 if tok == tokenIllegal {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
68 err = NewParserError(fmt.Sprintf("illegal token %q", lit), p.s.line)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
69 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
70 } else if tok == tokenEOF {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
71 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
72 } else if tok != tokenIdent {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
73 err = NewParserError(fmt.Sprintf("expected identifier, got %s %q", tok, lit), p.s.line)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
74 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
75 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
76 switch lit {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
77 case "account":
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
78 if acct != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
79 if err = p.validateAccount(acct); err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
80 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
81 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
82 conf.Accounts = append(conf.Accounts, acct)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
83 if isDefault {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
84 conf.Default = acct
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
85 isDefault = false
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
86 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
87 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
88
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
89 // account name
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
90 if lit, err = p.scanType(tokenString); err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
91 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
92 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
93 acct = &Account{
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
94 Name: lit,
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
95 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
96 case "default":
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
97 isDefault = true
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
98 case "host":
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
99 if lit, err = p.scanType(tokenString); err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
100 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
101 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
102 acct.Host = lit
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
103 case "port":
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
104 if lit, err = p.scanType(tokenNumber); err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
105 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
106 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
107 var port int
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
108 if port, err = strconv.Atoi(lit); err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
109 err = NewParserError(fmt.Sprintf("failed to parse port: %s", err), p.s.line)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
110 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
111 } else if port < 1 || port > 65535 {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
112 err = NewParserError(fmt.Sprintf("invalid port number %d", port), p.s.line)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
113 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
114 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
115 acct.Port = lit
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
116 case "user":
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
117 if lit, err = p.scanType(tokenString); err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
118 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
119 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
120 acct.User = lit
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
121 case "pass":
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
122 if lit, err = p.scanType(tokenString); err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
123 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
124 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
125 acct.Password = lit
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
126 case "insecure":
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
127 acct.Insecure = true
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
128 default:
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
129 err = NewParserError(fmt.Sprintf("unknown %s: %q", tok, lit), p.s.line)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
130 break parsing
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
131 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
132 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
133 if err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
134 return err
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
135 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
136 if acct != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
137 if err = p.validateAccount(acct); err != nil {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
138 return err
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
139 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
140 conf.Accounts = append(conf.Accounts, acct)
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
141 if isDefault {
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
142 conf.Default = acct
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
143 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
144 }
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
145
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
146 return nil
4dff4c3f0fbb Introduce configuration file where account information is specified
Guido Berhoerster <guido+sievemgr@berhoerster.name>
parents:
diff changeset
147 }