about summary refs log tree commit diff stats
path: root/lib/format
diff options
context:
space:
mode:
authorAndrew Jeffery <dev@jeffas.io>2020-07-02 18:54:17 +0100
committerReto Brunner <reto@labrat.space>2020-07-03 18:26:16 +0200
commit0acd6d0770d6534489e5fb54ce744838e81571ff (patch)
tree20e3ab9e97621c6a96d3575e7548eaa3fea192ca /lib/format
parente1c2b596dc9e45976253d75a6b704914fcdcb82c (diff)
downloadaerc-0acd6d0770d6534489e5fb54ce744838e81571ff.tar.gz
Fix a nil Envelope when getting the format
When getting the format for a message the envelope can be nil and this
shouldn't crash the program.
Diffstat (limited to 'lib/format')
-rw-r--r--lib/format/format.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/format/format.go b/lib/format/format.go
index b66a180..5f45e58 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -76,6 +76,10 @@ func ParseMessageFormat(
 		case '%':
 			retval = append(retval, '%')
 		case 'a':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			if len(msg.Envelope.From) == 0 {
 				return "", nil,
 					errors.New("found no address for sender")
@@ -85,6 +89,10 @@ func ParseMessageFormat(
 			args = append(args,
 				fmt.Sprintf("%s@%s", addr.Mailbox, addr.Host))
 		case 'A':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			var addr *models.Address
 			if len(msg.Envelope.ReplyTo) == 0 {
 				if len(msg.Envelope.From) == 0 {
@@ -111,6 +119,10 @@ func ParseMessageFormat(
 			args = append(args,
 				msg.InternalDate.Local().Format(timestampformat))
 		case 'f':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			if len(msg.Envelope.From) == 0 {
 				return "", nil,
 					errors.New("found no address for sender")
@@ -119,6 +131,10 @@ func ParseMessageFormat(
 			retval = append(retval, 's')
 			args = append(args, addr)
 		case 'F':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			if len(msg.Envelope.From) == 0 {
 				return "", nil,
 					errors.New("found no address for sender")
@@ -143,9 +159,17 @@ func ParseMessageFormat(
 			args = append(args, strings.Join(msg.Labels, ", "))
 
 		case 'i':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			retval = append(retval, 's')
 			args = append(args, msg.Envelope.MessageId)
 		case 'n':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			if len(msg.Envelope.From) == 0 {
 				return "", nil,
 					errors.New("found no address for sender")
@@ -160,17 +184,33 @@ func ParseMessageFormat(
 			retval = append(retval, 's')
 			args = append(args, val)
 		case 'r':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			addrs := models.FormatAddresses(msg.Envelope.To)
 			retval = append(retval, 's')
 			args = append(args, addrs)
 		case 'R':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			addrs := models.FormatAddresses(msg.Envelope.Cc)
 			retval = append(retval, 's')
 			args = append(args, addrs)
 		case 's':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			retval = append(retval, 's')
 			args = append(args, msg.Envelope.Subject)
 		case 't':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			if len(msg.Envelope.To) == 0 {
 				return "", nil,
 					errors.New("found no address for recipient")
@@ -183,6 +223,10 @@ func ParseMessageFormat(
 			retval = append(retval, 's')
 			args = append(args, accountName)
 		case 'u':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			if len(msg.Envelope.From) == 0 {
 				return "", nil,
 					errors.New("found no address for sender")
@@ -191,6 +235,10 @@ func ParseMessageFormat(
 			retval = append(retval, 's')
 			args = append(args, addr.Mailbox)
 		case 'v':
+			if msg.Envelope == nil {
+				return "", nil,
+					errors.New("no envelope available for this message")
+			}
 			if len(msg.Envelope.From) == 0 {
 				return "", nil,
 					errors.New("found no address for sender")