Monday, July 18, 2016

Read Mail from command line

Enabled IMAP access for your Gmail

Heirloom Mailx offers IMAP support, a nice threaded view


The .mailrc
===========

account gmail {
   set folder=imaps://USERNAME@imap.gmail.com
   set imap-use-starttls
   set nss-config-dir=/path/to/your/home/dir/etc/.nss-config
   set ssl-ca-dir=/path/to/your/home/dir/etc/.certs
   set record=+[Google\ Mail]/Sent\ Mail
   set from="Your Name <USERNAME@gmail.com>"
   set replyto="USERNAME@gmail.com"
   set sender="USERNAME@gmail.com"
   set smtp-use-starttls
   set smtp="smtp.gmail.com:587"
   set smtp-auth="login"
   set smtp-auth-user=USERNAME@gmail.com

# IMAP SHORTCUTS SECTION for standard Gmail folders
   shortcut allmail +[Google\ Mail]/All\ Mail
   shortcut in +INBOX
   shortcut spam +[Google\ Mail]/Spam
   shortcut trash +[Google\ Mail]/Bin
   shortcut sent +[Google\ Mail]/Sent\ Mail
   }

# Binary options
set askattach
set askcc
set askbcc
set autoinc
set autothread
set bsdannounce
set bsdflags
set bsdheadline
set bsdmsgs
set bsdorder
set datefield
set dot
set editheaders
set emptystart
set fullnames
set hold
set keep
set markanswered
set print-alternatives
set quiet
set reply-in-same-charset
set showlast
set showname
set showto
set noautocollapse

# String Options
fwdretain subject date from to
ignore received in-reply-to message-id references
ignore mime-version content-transfer-encoding
retain subject date from to cc x-mailer user-agent message-id list-Id
set autosort=thread
set contenttype-cntrl=text/plain
set crt=20
set encoding=quoted-printable
set headline="%>%a%m %27f  %24d %4l/%-5o %i%S"
set imap-keepalive=240
set imap-list-depth=5
set indentprefix="> "
set newmail=nopoll
set PAGER="/usr/pkg/bin/most -C -d +u"
# set pipe-text/plain="/usr/pkg/bin/par -B=ISO8859-15 -R0f0g1l0w70j0 | /usr/pkg/bin/most -C -d +u"
set pipe-text/plain="/usr/bin/fold -s | /usr/pkg/bin/most -C -d +u"
set quote=headers
set sendcharsets=iso-8859-1,iso-8859-15,utf-8
set signature=/arpa/gm/h//happy/.signature

# Reading HTML mail
set pipe-text/html="elinks -dump -dump-charset utf-8 -default-mime-type text/htm
l /dev/stdin"

# Address Book
alias  friend1    my_friend@server.foo
..


Notes about the config
======================

The config  is in two  parts, the  "account gmail {...}"  section will
only be utilised if mailx is  invoked with the "-A" option e.g. "mailx
-A  gmail". I actually  have  three  separate accounts  set  up in  my
".mailrc".

The options  given above are  my choices and  are detailed in  the man
page for heirloom mailx.


Security certificates
=====================

This is where it gets a bit complicated - sorry.


Method 1:

"set nss-config-dir=/path/to/your/home/dir/etc/.nss-config"

This folder needs to contain three files

cert8.db
key3.db
secmod.db

They can  be found in  your local mozilla profile  directory (assuming
you have a mozilla product  such as Firefox or Thunderbird installed),
for  Linux  and  BSD  users  the location  will  be  some  thing  like
"~/.mozilla/firefox/xxxxxxxx.default/" Just copy  the three files over
to SDF.


Method 2:

"ssl-ca-dir=/path/to/your/home/dir/etc/.certs"

Here you need three certs, the  gmail cert, the google cert (which the
gmail cert is signed with) and the equifax cert (which the google cert
is signed with).

To get the gmail & google certs run the following command

"openssl s_client -connect imap.gmail.com:993 -showcerts"

You should see two blocks of text like
-----BEGIN CERTIFICATE-----
some stuff
-----END CERTIFICATE-----

Copy the first  of these (including the beginning and  end lines) to a
file named "gmail.crt", and the second to a file named "google.crt"

Next you need  the equifax cert in  the PEM format, you  may have this
locally (check  in /usr/share/ for  a CA-Certs or similar  folder), if
not

wget -O Equifax_Secure_Certificate_Authority.pem \
https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Certificate_Authority.cer

works  at the  time  of  posting this,  if  this  fails google  should
be  able  to   provide. Either  way  copy  it  the  file   to  sdf  as
Equifax_Secure_Certificate_Authority.pem  and chmod  all the  certs to
644.

Now the magic  (i.e. I've no real idea what this  does but it worked),
run the following commands

openssl x509 -in Equifax_Secure_Certificate_Authority.pem \
            -fingerprint -subject -issuer -serial -hash -noout
c_rehash .
file 594f1775.*

and  it   should  all   be  working.


Method 3:

Alternativly just use "set ssl-verify=ignore" in your ".mailrc"


Passwords
=========

As I  have things set  up mailx will ask  you for your  gmail password
each time  it is invoked, if  this is to  much like hard work  for you
then adding

"set password-USERNAME@imap.gmail.com="YOURPASSWORD"
"set smtp-auth-password="YOURPASSWORD"

to the gmail section of your ".mailrc" will solve your problems.


Shell like commandline history and editing
==========================================

If you use  the "ile" command to  start mailx then ile  will provide a
shell like command  line in mailx e.g. "ile mailx  -A gmail".  See the
ile man page for  more details (ile can be found  in the NetBSD pkgsrc
package "lile").


Using Mailx
===========

Start mailx with the command

ile mailx -A  gmail


To see a list of folders type

folders

the first time use this command you may need to use "folders @"


To go to a folder type

fold +Folder_name

or

fold predefined_shortcut


To read a message just type its  number, to to see all the headers etc
use "Type xxx" where xxx is the message number.


To move through the  message list use "z+" or "z-"  this will move you
up or  down a page, these  commands also accept numbers  so "z-4" will
move you down  4 pages. "z1" and  "z$" will take you  to the beginning
and end of the message list.

https://gopherproxy.meulie.net/sdf.org/0/users/happy/phlog/13122012.txt

No comments:

Blog Archive