CUIでGmail

記事タイトルとURLをコピーする

はじまり

こんにちはCI部の千葉です。 当社では、お客さまとのコミュニケーションには Backlog 、社内のコミュニケーションには Slack を使っているので多くのエンジニアは日々の業務でメールを利用しません。

とは言え、名刺にメールアドレスを書いているのでメールチェックしない。ってワケにもいかないのでWebブラウザGmailを開いているのが実情です。

わたしは、ずっと Inbox by Gmail を好きで使っていたのですが、残念ながら2019年3月末をもってサービス終了してしまいました。 しかたがないので4月からは Gmail を使っているのですが、これがウンザリする程にメモリを喰うんです。(なんと1.5GB!)

業務でメインに使うツールがリソースを消費するのは良いのですが、上記のとおり殆ど利用しないメールにメモリを掴まれるなんて許せません。 ってワケで、なんとか最小のリソースでGmailを使えないかと挑戦したので結果をココに報告したいと思います。

実行環境

  • macOS Mojave (Version 10.14.4)
  • iTerm 3.2.8
  • Homebrew 2.1.1

Mutt のインストール

Mutt(マット) はテキストベースのメールクライアントです。 これをGmailのキーボードショートカットで操作できるようにカスタマイズしたいと思います。

$ brew install mutt

Google アカウントのアプリパスワードを生成

Sign in using App Passwords の『アプリ パスワードの生成方法』手順に従ってアプリパスワードを生成します。

設定ファイルの作成

Gmailのショートカットキーと操作感を合わせておきたいので以下の内容で ~/.muttrc ファイルを作成します。

set realname = "{{first and last name}}"
set from = "{{gmail username}}@gmail.com"
set use_from = yes
set envelope_from = yes
set smtp_url = "smtps://{{gmail username}}@gmail.com@smtp.gmail.com:465/"
set smtp_pass = "{{app password}}"
set imap_user = "{{gmail username}}@gmail.com"
set imap_pass = "{{app password}}"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set ssl_force_tls = yes
set hostname = gmail.com
set mail_check = 300
set timeout = 300
set postponed = "+[GMail]/Drafts"
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
set signature =~/.mutt/signature
set move = no
set include
set sort = 'threads'
set sort_aux = 'reverse-last-date-received'
set auto_tag = yes
set editor = "vim"
set charset = "utf-8"
set record = ""
set pager_index_lines = 10
set pager_context = 3
set pager_stop
set menu_scroll
set tilde
unset markers
set quote_regexp = "^( {0,4}[>|:#%]| {0,4}[a-z0-9]+[>|]+)+"
alternative_order text/plain text/enriched text/html
ignore "Authentication-Results:"
ignore "DomainKey-Signature:"
ignore "DKIM-Signature:"
hdr_order Date From To Cc
alternative_order text/plain text/html *
auto_view text/html

# Shortcuts
macro index,pager y "unset trash
 " "Gmail archive message"
macro index,pager d "set trash=\"imaps://imap.googlemail.com/[GMail]/Bin\"
 " "Gmail delete message"
macro index,pager gi "=INBOX" "Go to inbox"
macro index,pager ga "=[Gmail]/All Mail" "Go to all mail"
macro index,pager gs "=[Gmail]/Starred" "Go to starred messages"
macro index,pager gd "=[Gmail]/Drafts" "Go to drafts"
bind pager k previous-line
bind pager j next-line
bind attach  view-mailcap

# Side
set sidebar_visible = yes
set sidebar_width = 30
color sidebar_new color221 color233
bind index,pager  sidebar-next
bind index,pager  sidebar-prev
bind index,pager  sidebar-open

# Status
set status_chars = " *%A"
set status_format = "---[ Folder: %f ]---[%r%m messages%?n? (%n new)?%?d? (%d to delete)?%?t? (%t tagged)? ]---%>-%?p?( %p postponed )?---"

# Index
set date_format = "%m/%d"
set index_format = "[%Z] %D %-20.20F %s"
set sort = threads
set sort_aux = reverse-last-date-received
set uncollapse_jump
set sort_re
set reply_regexp = "^(([Rr][Ee]?(\[[0-9]+\])?: *)?(\^+\] *)?)*"

# Deleted message
color index red default "!~N ~D"
color index red white "~N ~D"

動的な値は以下を参考に編集してください。

項目
{{first and last name}} 名前 User Name
{{gmail username}} Gmail のアカウント名 account_name
{{app password}} Google のアプリパスワード example_secret

実行

以下のコマンドを実行してメーラーを起動します。

$ mutt

起動されたイメージが↓こちらです。 実際のメールが表示されちゃうのでモザイクだらけになってしまいましたが、ブラウザ版のGmailのデザイン・ショートカットキーを踏襲しています。

この状態でのiTerm2が利用しているメモリが150MBでした。ブラウザ利用の1/10で済むようになったので大満足です。

ども