update email settings
This commit is contained in:
		
							parent
							
								
									9dca602bd1
								
							
						
					
					
						commit
						fb5a779c9e
					
				
					 1 changed files with 71 additions and 32 deletions
				
			
		
							
								
								
									
										103
									
								
								user/email.nix
									
										
									
									
									
								
							
							
						
						
									
										103
									
								
								user/email.nix
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,43 +1,82 @@
 | 
			
		|||
{ pkgs, ... }: {
 | 
			
		||||
{ pkgs, ... }:
 | 
			
		||||
let
 | 
			
		||||
 | 
			
		||||
  downloadEmails = "${pkgs.offlineimap}/bin/offlineimap";
 | 
			
		||||
  afterSync = "${pkgs.notmuch}/bin/notmuch new";
 | 
			
		||||
  onNewEmails = "${pkgs.libnotify}/bin/notify-send 'You've got mail!'";
 | 
			
		||||
 | 
			
		||||
  defaultAccountSettings = {
 | 
			
		||||
    astroid.enable = true;
 | 
			
		||||
    imapnotify = {
 | 
			
		||||
      enable = true;
 | 
			
		||||
      boxes = [ "INBOX" ];
 | 
			
		||||
      onNotify = downloadEmails;
 | 
			
		||||
      onNotifyPost = afterSync;
 | 
			
		||||
    };
 | 
			
		||||
    offlineimap = {
 | 
			
		||||
      enable = true;
 | 
			
		||||
      postSyncHookCommand = afterSync;
 | 
			
		||||
    };
 | 
			
		||||
    msmtp.enable = true;
 | 
			
		||||
    notmuch.enable = true;
 | 
			
		||||
  };
 | 
			
		||||
in
 | 
			
		||||
{
 | 
			
		||||
  accounts.email.accounts =
 | 
			
		||||
    let
 | 
			
		||||
      mkAccount = username: host: passName: {
 | 
			
		||||
        realName = "Leonardo Eugênio";
 | 
			
		||||
        address = "${username}@${host}";
 | 
			
		||||
        userName = username;
 | 
			
		||||
        astroid.enable = true;
 | 
			
		||||
        imap.host = host;
 | 
			
		||||
        smtp.host = host;
 | 
			
		||||
        imapnotify = {
 | 
			
		||||
          enable = true;
 | 
			
		||||
          onNotify = "${pkgs.isync}/bin/mbsync -a";
 | 
			
		||||
          onNotifyPost =
 | 
			
		||||
            "${pkgs.notmuch}/bin/notmuch new && ${pkgs.libnotify}/bin/ notify-send 'New mail arrived'";
 | 
			
		||||
        };
 | 
			
		||||
        mbsync = {
 | 
			
		||||
          enable = true;
 | 
			
		||||
          create = "both";
 | 
			
		||||
        };
 | 
			
		||||
        msmtp.enable = true;
 | 
			
		||||
        notmuch.enable = true;
 | 
			
		||||
        passwordCommand = toString (pkgs.writeShellScript "get_pass" ''
 | 
			
		||||
          pass ${passName} | head -n1
 | 
			
		||||
        '');
 | 
			
		||||
      };
 | 
			
		||||
    in
 | 
			
		||||
    {
 | 
			
		||||
      "personal" = (mkAccount "lelgenio" "disroot.org" "disroot.org") // { primary = true; };
 | 
			
		||||
      "work" = mkAccount "leonardo" "wopus.com.br" "Trabalho/wopus_email/leonardo@wopus.com.br";
 | 
			
		||||
      "personal" = {
 | 
			
		||||
        primary = true;
 | 
			
		||||
        realName = "Leonardo Eugênio";
 | 
			
		||||
        address = "lelgenio@disroot.org";
 | 
			
		||||
        userName = "lelgenio";
 | 
			
		||||
        imap.host = "disroot.org";
 | 
			
		||||
        smtp.host = "disroot.org";
 | 
			
		||||
        passwordCommand = toString (pkgs.writeShellScript "get_pass" ''
 | 
			
		||||
          pass "disroot.org" | head -n1
 | 
			
		||||
        '');
 | 
			
		||||
      } // defaultAccountSettings;
 | 
			
		||||
      "work" = {
 | 
			
		||||
        realName = "Leonardo Eugênio";
 | 
			
		||||
        address = "leonardo@wopus.com.br";
 | 
			
		||||
        userName = "leonardo@wopus.com.br";
 | 
			
		||||
        imap.host = "imap.wopus.com.br";
 | 
			
		||||
        smtp.host = "smtp.wopus.com.br";
 | 
			
		||||
        passwordCommand = toString (pkgs.writeShellScript "get_pass" ''
 | 
			
		||||
          pass "Trabalho/wopus_email/leonardo@wopus.com.br" | head -n1
 | 
			
		||||
        '');
 | 
			
		||||
      } // defaultAccountSettings;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
  services.imapnotify.enable = true;
 | 
			
		||||
 | 
			
		||||
  programs.mbsync.enable = true;
 | 
			
		||||
  services.mbsync.enable = true;
 | 
			
		||||
  services.mbsync.postExec = "${pkgs.notmuch}/bin/notmuch new";
 | 
			
		||||
  programs.offlineimap.enable = true;
 | 
			
		||||
  systemd.user.services.offlineimap = {
 | 
			
		||||
    Unit = {
 | 
			
		||||
      Description = "offlineimap mailbox synchronization";
 | 
			
		||||
    };
 | 
			
		||||
    Service = {
 | 
			
		||||
      Type = "oneshot";
 | 
			
		||||
      ExecStart = downloadEmails;
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
  systemd.user.timers.offlineimap = {
 | 
			
		||||
    Unit = { Description = "offlineimap mailbox synchronization"; };
 | 
			
		||||
    Timer = {
 | 
			
		||||
      OnCalendar = "*:0/5";
 | 
			
		||||
      Unit = "offlineimap.service";
 | 
			
		||||
    };
 | 
			
		||||
    Install = { WantedBy = [ "timers.target" ]; };
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  programs.notmuch.enable = true;
 | 
			
		||||
  programs.notmuch.hooks.postInsert = onNewEmails;
 | 
			
		||||
 | 
			
		||||
  programs.msmtp.enable = true;
 | 
			
		||||
 | 
			
		||||
  programs.astroid.enable = true;
 | 
			
		||||
  programs.astroid = {
 | 
			
		||||
    enable = true;
 | 
			
		||||
    externalEditor = "terminal -e kak %1";
 | 
			
		||||
    pollScript = downloadEmails;
 | 
			
		||||
    extraConfig = { };
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue