about summary refs log tree commit diff stats
path: root/widgets/msgviewer.go
diff options
context:
space:
mode:
authorClayton Craft <clayton@craftyguy.net>2019-06-08 11:29:26 -0700
committerDrew DeVault <sir@cmpwn.com>2019-06-09 11:49:11 -0400
commitdd178262bb1d01f9f7d4710431547041bde52d89 (patch)
tree4ab22337f7f6d4e2609aaf375df26d83225c5130 /widgets/msgviewer.go
parentacfe7d7625192bc856d5d696f741e35ce38cab25 (diff)
downloadaerc-dd178262bb1d01f9f7d4710431547041bde52d89.tar.gz
Select user's preferred mimetype in MessageViewer
This implements selecting the most preferred mimetype under the
'View->Alternatives' configuration setting when viewing a message.
Mimetypes in the alternatives array are weighted by their position,
where the lower the index in the array the higher the priority, so this
is taken into account during selection.

If no message part matches a mimetype in the alternatives array, then it
selects the first mimetype in the message.
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r--widgets/msgviewer.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 52407b7..10c2182 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -160,14 +160,25 @@ func createSwitcher(switcher *PartSwitcher, conf *config.AercConfig,
 		if err != nil {
 			return err
 		}
-		switcher.selected = -1
+		selectedPriority := -1
 		for i, pv := range switcher.parts {
 			pv.OnInvalidate(func(_ ui.Drawable) {
 				switcher.Invalidate()
 			})
-			// TODO: switch to user's preferred mimetype, if configured
+			// Switch to user's preferred mimetype
 			if switcher.selected == -1 && pv.part.MIMEType != "multipart" {
 				switcher.selected = i
+			} else if selectedPriority == -1 {
+				for idx, m := range conf.Viewer.Alternatives {
+					if m != pv.part.MIMEType+"/"+pv.part.MIMESubType {
+						continue
+					}
+					priority := len(conf.Viewer.Alternatives) - idx
+					if priority > selectedPriority {
+						selectedPriority = priority
+						switcher.selected = i
+					}
+				}
 			}
 		}
 	}