summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-12-17 01:44:23 +0700
committerShulhan <ms@kilabit.info>2021-12-17 01:44:23 +0700
commit49f0a0ddc2546c2a8d87999718e8febadbb43d85 (patch)
tree79c73b34d638ba9d8a2b79aaa4b3214391503694
parent5adf8d6c75a5f143f3a6da7f40b06ece699ae0d4 (diff)
downloadpakakeh.go-49f0a0ddc2546c2a8d87999718e8febadbb43d85.tar.xz
lib/email: refacforing ParseMailbox
This commit changes the signature of ParseMailbox by returning no error.
-rw-r--r--lib/email/mailbox.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/email/mailbox.go b/lib/email/mailbox.go
index 07a3758b..5b4c1e5b 100644
--- a/lib/email/mailbox.go
+++ b/lib/email/mailbox.go
@@ -57,18 +57,20 @@ func (mbox *Mailbox) String() string {
}
//
-// ParseMailbox parse the raw address and return a single mailbox, the first
-// mailbox in the list.
+// ParseMailbox parse the raw address(es) and return the first mailbox in the
+// list.
+// If the raw parameter is empty or no mailbox present or mailbox format is
+// invalid, it will return nil.
//
-func ParseMailbox(raw []byte) (mbox *Mailbox, err error) {
+func ParseMailbox(raw []byte) (mbox *Mailbox) {
mboxes, err := ParseMailboxes(raw)
if err != nil {
- return nil, err
+ return nil
}
if len(mboxes) > 0 {
- return mboxes[0], nil
+ return mboxes[0]
}
- return nil, errors.New("empty mailbox")
+ return nil
}
//
@@ -327,9 +329,9 @@ func (mbox *Mailbox) UnmarshalJSON(b []byte) (err error) {
if b[len(b)-1] == '"' {
b = b[:len(b)-1]
}
- got, err := ParseMailbox(b)
- if err != nil {
- return err
+ got := ParseMailbox(b)
+ if got == nil {
+ return nil
}
*mbox = *got
return nil