class MbsyncAccountConfig def initialize account, config @config = config @account = account make_imap_account make_imap_store make_maildir_store make_channel end def make_imap_account @imap_account = <<~END.chomp IMAPAccount #{@account['name']} Host #{@account['imap']} User #{@account['email']} Port 993 SSLType IMAPS PassCmd "pass show #{@account['pass_tag'] || @account['name']}" CertificateFile /etc/ssl/certs/ca-certificates.crt AuthMechs * END end def make_imap_store @imap_store = <<~END.chomp IMAPStore #{@account['name']}-remote Account #{@account['name']} END end def make_maildir_store @maildir_store = <<~END.chomp MaildirStore #{@account['name']}-local Path #{@config['mail_directory']}/#{@account['name']}/ Inbox #{@config['mail_directory']}/#{@account['name']}/INBOX Subfolders Verbatim Flatten . END end def make_channel @channel = <<~END.chomp Channel #{@account['name']} Master :#{@account['name']}-remote: Slave :#{@account['name']}-local: Patterns * !"[Gmail]/All Mail" !"[Gmail]/Wszystkie" Create Slave SyncState * ExpireUnread yes MaxMessages #{@account['max_messages'] || '0'} END end def to_s <<~END.chomp # BEGIN profile generated by mmm #{@imap_account} #{@imap_store} #{@maildir_store} #{@channel} # END profile generated by mmm END end end def make_mbsync_config config accounts = config['accounts'].map do |account_config| account = MbsyncAccountConfig.new account_config, config account.to_s end accounts.join "\n\n" end