aboutsummaryrefslogtreecommitdiff
path: root/.local/lib
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-03-09 12:48:12 +0100
committerPatrick Spek <p.spek@tyil.nl>2021-08-14 11:59:32 +0200
commitc8123c155b237e6717a500923376918bb0a4c38a (patch)
tree31d494ba02c8a3b476433a8ea189ce586588c359 /.local/lib
parent06683b22c139a8ebf637256fad1a79734d872964 (diff)
Add Mutt configuration
Diffstat (limited to '.local/lib')
-rw-r--r--.local/lib/perl5/App/Localmail.pm54
1 files changed, 54 insertions, 0 deletions
diff --git a/.local/lib/perl5/App/Localmail.pm b/.local/lib/perl5/App/Localmail.pm
new file mode 100644
index 0000000..db39fae
--- /dev/null
+++ b/.local/lib/perl5/App/Localmail.pm
@@ -0,0 +1,54 @@
+#!/usr/bin/env false
+
+use v5.20;
+use feature qw/say signatures/;
+use strict;
+use utf8;
+use warnings;
+
+use YAML::XS;
+use File::Basename;
+use File::Slurp;
+
+package App::Localmail;
+
+sub base_config () {
+ my $config_dir = "$ENV{HOME}/.config/localmail";
+ my $config = {};
+
+ # Load main configuration
+ $config->{localmail} = YAML::XS::Load(File::Slurp::read_file("$config_dir/config.yaml"));
+
+ # Load account configurations
+ for (glob("$config_dir/accounts/*.yaml")) {
+ my ($name, $path, $suffix) = File::Basename::fileparse($_, ('.yaml'));
+ my $yaml = File::Slurp::read_file($_);
+
+ $config->{accounts}->{$name} = YAML::XS::Load($yaml);
+ }
+
+ $config->{localmail}{maildir} //= "$ENV{HOME}/.maildir";
+
+ $config;
+}
+
+sub config_passwords ($config) {
+ # Get passwords where necessary
+ for (keys %{$config->{accounts}}) {
+ if (!defined($config->{accounts}{$_}{incoming}{password}{plain})) {
+ my $file = $config->{accounts}{$_}{incoming}{password}{file};
+ chomp (my $password = qx/gpg -d "$file" | head -n 1/);
+
+ $config->{accounts}{$_}{incoming}{password}{plain} = $password;
+ }
+
+ if (!defined($config->{accounts}{$_}{outgoing}{password}{plain})) {
+ my $file = $config->{accounts}{$_}{outgoing}{password}{file};
+ chomp (my $password = qx/gpg -d "$file" | head -n 1/);
+
+ $config->{accounts}{$_}{outgoing}{password}{plain} = $password;
+ }
+ }
+}
+
+1;