aerc: use aerc as an mbox viewer

Use Aerc as an mbox viewer. Open an mbox file from the command line in a
new tab with the mbox backend. Provide a convenient and quick way to
display emails from an mbox.

Usage: aerc mbox://<path>

where the path can either be a directory or an mbox file. If it is a
directory, every file with an .mbox suffix will be loaded as a folder.

The account config will be copied from the selected account. This allows
the answer emails in the mbox account.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti 2022-07-11 20:11:19 +02:00 committed by Robin Jarry
parent a1a276e002
commit c24a576876
3 changed files with 39 additions and 0 deletions

View File

@ -200,6 +200,7 @@ func main() {
} else {
defer as.Close()
as.OnMailto = aerc.Mailto
as.OnMbox = aerc.Mbox
}
// set the aerc version so that we can use it in the template funcs

View File

@ -21,6 +21,7 @@ type AercServer struct {
logger *log.Logger
listener net.Listener
OnMailto func(addr *url.URL) error
OnMbox func(source string) error
}
func StartServer(logger *log.Logger) (*AercServer, error) {
@ -92,6 +93,16 @@ func (as *AercServer) handleClient(conn net.Conn) {
} else {
conn.Write([]byte("result: success\n"))
}
case "mbox":
var err error
if as.OnMbox != nil {
err = as.OnMbox(msg)
}
if err != nil {
conn.Write([]byte(fmt.Sprintf("result: %v\n", err)))
} else {
conn.Write([]byte("result: success\n"))
}
}
}
as.logger.Printf("Closed Unix connection %d", clientId)

View File

@ -618,6 +618,33 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
return nil
}
func (aerc *Aerc) Mbox(source string) error {
acctConf := config.AccountConfig{}
if selectedAcct := aerc.SelectedAccount(); selectedAcct != nil {
acctConf = *selectedAcct.acct
info := fmt.Sprintf("Loading outgoing mbox mail settings from account [%s]", selectedAcct.Name())
aerc.PushStatus(info, 10*time.Second)
aerc.Logger().Println(info)
} else {
acctConf.From = "<user@localhost>"
}
acctConf.Name = "mbox"
acctConf.Source = source
acctConf.Default = "INBOX"
acctConf.Archive = "Archive"
acctConf.Postpone = "Drafts"
acctConf.CopyTo = "Sent"
mboxView, err := NewAccountView(aerc, aerc.conf, &acctConf, aerc.logger, aerc, nil)
if err != nil {
aerc.NewTab(errorScreen(err.Error(), aerc.conf.Ui), acctConf.Name)
} else {
aerc.accounts[acctConf.Name] = mboxView
aerc.NewTab(mboxView, acctConf.Name)
}
return nil
}
func (aerc *Aerc) CloseBackends() error {
var returnErr error
for _, acct := range aerc.accounts {