-
Notifications
You must be signed in to change notification settings - Fork 31
Imap gmail
There are two separate protocols to access your email, pop3 and imap. As of version 3.6.0, edbrowse supports both, with new imap features added in 3.7.4. However, imap servers can behave quite differently from one another. This article describes the behavior of the gmail imap server, which could differ from other servers in subtle ways. First, a brief review of pop3.
The pop3 interface fetches your emails from one or more pop3 accounts and stores them on your computer, deleting them from the server(s) in the process. You are presented with each email in turn, whereupon you can delete it, or save it to a file. Some emails are saved in files for you automatically, based on filters in your .ebrc config file or your address book. (See the documentation for more details.) Assuming none of these filters applies, edbrowse presents the email to you, page by page, until you decide what to do with it. If you type h for help, the following help screen appears.
h print this help message
q quit this program
space read more of this email
g go to top
t read as plain text
n next email
d delete this email
w write this email to a file and delete it
u write this email unformatted to a file and delete it
Most emails come in html format. You don't see the tags; edbrowse formats it for you. Sometimes there is a plain text version. You can access this with the t command. However, sometimes there is no plain text version, and sometimes it is supremely unhelpful: "This email is in html, please enable html on your mail client."
If you save an email to a file that already exists, the email is appended, with a line of equal signs as delimiter. This can happen when the email is directed to a file by a filter, in your config file or implied by your address book. For example, consider this line in my .ebrc.
Scientific American Newsletters > -sciam
Each issue is saved unformatted, as indicated by the minus sign. If I don't get around to reading them for a week or two, the sciam file could contain several issues. Use the csplit command to separate them, like this.
csplit --suppress-matched sciam /======================================================================/ '{*}'
Now each issue can be read, clicking on the articles of interest, and then deleted.
If an email has been saved in a local file, and you are viewing that file under edbrowse, the re command allows you to reply to this email. Use rea to reply all. This places various headers at the top of the file, including a References: line that you should not edit or delete. Edit the body, inserting your own comments, and type sm to send your reply back to the sender. This is the reply procedure for both pop3 and imap. The mail must be on your computer for edit, whereupon the rea and sm commands facilitate the reply.
If the mail was saved unformatted via the u command, then type b to browse, whereupon you can once again type re to reply, if that is what you wish to do.
It is generally safe to save the mail formatted, via the w command, because an unformatted copy is stored in ~/.trash/rawmail, in case you need it in the future.
Imap is an entirely different philosophy. The server retains your emails, and you can view them from many different devices: computer, tablet, smart phone, etc. You don't typically delete an email from the Imap server unless you are sure you really don't need it any more, or you have copied it onto your computer and you don't need to view it from other devices any longer. Before we run a sample Imap session, let's look at the entries in the config file that provide both pop3 and imap access to gmail.
# google mail pop3
mail {
inserver = pop.gmail.com
outserver = smtp.gmail.com
secure
login = fflintstone
password = Pebbles276
reply = [email protected]
from = Fred Flintstone
}
# google mail imap
mail {
imap
inserver = imap.gmail.com
outserver = smtp.gmail.com
secure
login = [email protected]
password = Pebbles276
from = Fred Flintstone
reply = [email protected]
}
If these are the first two email entries in your config file,
then edbrowse -f1
fetches the outstanding gmail via pop3,
edbrowse -m
views the emails just fetched,
and edbrowse -fm1
does both in one go.
edbrowse -f2
accesses your gmail through imap, and presents a screen somewhat like the following.
1 INBOX, 0 messages
2 [Gmail]/All Mail, 7 messages
3 [Gmail]/Drafts, 0 messages
4 [Gmail]/Important, 0 messages
5 [Gmail]/Sent Mail, 0 messages
6 [Gmail]/Spam, 41 messages
7 [Gmail]/Starred, 0 messages
8 [Gmail]/Trash, 21 messages
Select a folder by number or by substring. q to quit,
rf to refresh, l number to change fetch limit, e string to set envelope format.
You can create other folders, but these are the default under gmail. Type "create foo" to create a new folder, "rename foo bar" to rename it, and "delete bar" to remove it. These folder commands were introduced in 3.7.4. Returning to standard gmail, the first folder, called inbox, holds email that has not yet been read. pop3 fetches mail out of this folder and moves it to trash. This example shows 21 emails in trash, 21 emails that I have (perhaps) read and downloaded to my computer using pop3, though there are other ways for email to wind up in trash. I can quickly scan and remove emails from trash, gone forever, by selecting the trash folder and deleting each in turn with the d command. Type s to stop reading from this folder, as I did when I saw the Discover card notice, leaving the rest of the emails in the trash for later.
trash
21 messages
Lifeboat Foundation | is now following you on Twitter! Dec 13 2015 26K
delete
Indeed Job Alert | 1 new DBA opportunity Dec 13 2015 18K
delete
Popular in your network | The truth about fetal tissue Dec 13 2015 80K
delete
MSU Honors College | News & Updates Dec 14 2015 79K
delete
MyDomain Deals | get 20% off domains and web hosting Dec 15 2015 15K
delete
Discover Card | Your statement is on its way Dec 17 2015 44K
stop
end of folder
Another housekeeping chore is clearing out the spam. Like the trash, emails really do go away completely when deleted. Of course, if an email is not spam you can use the m command to move it somewhere else, even the inbox, whereupon it is available for pop3 fetch.
spam
41 messages
*Walgreens Notice | Pickup is required Dec 12 2015 5K
delete
*SaveFamilyMemories | Preserve Old 8mm and VHS Films Dec 12 2015 2K
delete
*PET FOOD COUPONS | You Can Save Dec 12 2015 4K
delete
*Josh Radonsky | Meet Life Science Investors Dec 14 2015 26K
delete
...
If I want to leave pop3 behind altogether, I can select inbox through imap and read and review those emails, moving them to other folders as I wish. Under gmail, you cannot meaningfully delete an email from inbox, or any of the other folders; you can only move it to trash, and then delete it from there. It's an awkward 2 step process, but there it is.
The All Mail folder is confusing at first, because it is a virtual folder, the way /proc is a virtual file system. Any email not in spam or trash appears in All Mail. It is a reflection of all your mail, or at least all the mail that you might reasonably care about.
Use the / command to search for a word in the subject of emails in the current folder. This is not a simple text fragment; foo will not match foobar. It is case insenssitive. Use /f Karl to find emails with Karl in the from line, or /b baseball to find emails with baseball in the body of the email. The last 50 of these will be presented, instead of the last 50 emails in the folder. Again, you can step through them one by one, read them, save attachments, delete, write formatted or unformatted, or move to another folder. Type s to stop reading from this folder, or / for another search. Warning: as of this writing you can only search for ascii words. I've tried to make this international using utf8, and that works with some imap servers, but not gmail, for reasons unknown to me.
These searches are done on the imap server; edbrowse merely initiates the search. You might have 50 email envelopes in the edbrowse buffer for review, but the search scans through all the emails in the current folder on the imap server. Some people have ten thousand emails in a folder; this capability searches through all of them. It can be a powerful tool for finding an email that you might have received years ago.
When saving files to your computer, there is a subtle difference between pop3 and imap. w saves the email formatted in both worlds, but it also deletes the email under pop3, but not under imap. If you want to save and delete in imap, use capital W, or capital U to save unformatted. Consider the following imap help screen, produced by typing h.
h print this help message
q quit this program
s stop reading from this folder
n continue to next message
p go back to previous message
d delete this email
m move this email to another folder
v view all
b batch move or delete
f from move or delete
space or g read and manage this email
t read as plain text
/ search for words in subject, from, or body
w write this email to a file
W write this email to a file and delete it
u write this email unformatted to a file
U write this email unformatted to a file and delete it
a scan and save attachments
e envelope format string
The e command, at the main screen or while scanning through a folder, changes the format of an envelope: which fields are displayed and in what order. t = to, f = from, s = subject, d = datetime, and z = size. The earlier examples are fsdz, from subject date size, however, the default is fs, from and subject. This is usually all I need.
The v (view all) command prints all the envelopes for all the emails that have been fetched, all the emails in the current "buffer". If you don't see anything untoward in this list, you can use the b (batch) command to act on all of them in one go. Follow up with d to delete, or m to move to another folder. The f (from) command is similar. Follow up with d or m to delete or move all the emails from this sender. Thus you can easily move all the email from Fred Flintstone into your cartoon folder. Server-side imap filters can do some of this work for you, but if you haven't set up these filters, or if they aren't working as expected, you can do it yourself.
Warning: you may try to log in for imap or pop3, and google says your login or password is invalid, but you know it's right, it's the same credentials you use to sign in to email over the internet. Google insists on a 2 phase app password system for email clients.
- Sign into your Google account.
- Go to the "security" section.
- Go to the "app password" section.
- Generate an app password. Use "Mail" for the app and "Other" for the device (if none of the device descriptions are suitable). Google will generate a password for you to use that is different from your main Google account password.
- Use this 16-character password in your Edbrowse configuration file.
Warning: you must have two-step verification enabled, or you won't see an app password section at all. If you try to go to the apppasswords section directly by a url, it will say this feature is not available. You must activate two-step verification first, then you can generate an app password for edbrowse to use.
Warning: you have to specifically allow pop3 access to your gmail, or pop3 won't work.
To see the communications to and from the email server, type edbrowse -d4 -f2 You can change the debug level during the imap session via the db[n] command at the folder prompt.
If a mail server requires a secure connection, (most of them do), and edbrowse reports a missing or invalid certificate, there is a way around it. As a browser, you could use the vs command to disable verification of ssl connections, but that command is not available in the mail client. However, you can use the novs command in your config file. If imap.something.com is giving you certificate trouble, put this in .ebrc.
novs = imap.something.com
Imap works great on comcast.net. This is rather necessary, because in August 2020 comcast started flagging real emails as spam, and you'd never see them through pop3. Even some of the inbuilt imap clients in phones and tablets don't access the junk folder. One of these "flagged" emails was real money for me. Log in by imap at least once a week and check your junk folder. They clear out the junk folder from time to time, as does gmail, and probably every other mail server, so you do need to check junk periodically.
An imap session has internal time limits. You can't leave a session sit open indefinitely, like you're looking at a web page. If you are in a folder, and time expires, edbrowse will automatically log you back in, however, it will no longer be in that folder. You will get errors as you try to read your emails. Type s to stop reading that folder, then go back into a folder, or type rf to refresh and see all the folders again. I hope to handle this error condition more gracefully in the future.
If you are happily stepping through envelopes, and delete an email that you wish you hadn't, type q to quit the imap session. Emails are not actually deleted until you come to the end of the folder, so if you just abort, they will still be there.