mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-02 18:23:33 +01:00
This allows setting viewer options for specific message senders or subjects via conditional `viewer` blocks in the main configuration file, similar to contextual UI configuration. Each block can target the envelope sender and the From/Subject headers, as either an exact match with `=` (on the email address for sender/from) or a regex with `~` (on the full "$name <$email>" string representation). For example, some senders like to include a useless plain text part in their alternatives, telling you that your client doesn't support HTML. The documented example would prefer plain text where present by default, but switch to the HTML part for such senders. Signed-off-by: Terrance <git@terrance.allofti.me> Reviewed-by: Julio B <julio.bacel@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package msg
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"git.sr.ht/~rjarry/aerc/app"
|
|
"git.sr.ht/~rjarry/aerc/commands"
|
|
"git.sr.ht/~rjarry/aerc/config"
|
|
"git.sr.ht/~rjarry/aerc/lib"
|
|
"git.sr.ht/~rjarry/aerc/models"
|
|
)
|
|
|
|
type helper struct {
|
|
msgProvider app.ProvidesMessages
|
|
statusInfo func(string)
|
|
}
|
|
|
|
func newHelper() *helper {
|
|
msgProvider, ok := app.SelectedTabContent().(app.ProvidesMessages)
|
|
if !ok {
|
|
msgProvider = app.SelectedAccount()
|
|
}
|
|
return &helper{
|
|
msgProvider: msgProvider,
|
|
statusInfo: func(s string) {
|
|
app.PushStatus(s, 10*time.Second)
|
|
},
|
|
}
|
|
}
|
|
|
|
func (h *helper) markedOrSelectedUids() ([]models.UID, error) {
|
|
return commands.MarkedOrSelected(h.msgProvider)
|
|
}
|
|
|
|
func (h *helper) store() (*lib.MessageStore, error) {
|
|
store := h.msgProvider.Store()
|
|
if store == nil {
|
|
return nil, errors.New("Cannot perform action. Messages still loading")
|
|
}
|
|
return store, nil
|
|
}
|
|
|
|
func (h *helper) account() (*app.AccountView, error) {
|
|
acct := h.msgProvider.SelectedAccount()
|
|
if acct == nil {
|
|
return nil, errors.New("No account selected")
|
|
}
|
|
return acct, nil
|
|
}
|
|
|
|
func (h *helper) messages() ([]*models.MessageInfo, error) {
|
|
uid, err := commands.MarkedOrSelected(h.msgProvider)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
store, err := h.store()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return commands.MsgInfoFromUids(store, uid, h.statusInfo)
|
|
}
|
|
|
|
func getMessagePart(msg *models.MessageInfo, provider app.ProvidesMessage) []int {
|
|
p := provider.SelectedMessagePart()
|
|
if p != nil {
|
|
return p.Index
|
|
}
|
|
viewerConfig := config.Viewer().ForEnvelope(msg.Envelope)
|
|
for _, mime := range viewerConfig.Alternatives {
|
|
part := lib.FindMIMEPart(mime, msg.BodyStructure, nil)
|
|
if part != nil {
|
|
return part
|
|
}
|
|
}
|
|
return nil
|
|
}
|