-
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 = fflintstone@gmail.com
from = Fred Flintstone
}
# google mail imap
mail {
imap
inserver = imap.gmail.com
outserver = smtp.gmail.com
secure
login = fflintstone@gmail.com
password = Pebbles276
from = Fred Flintstone
reply = fflintstone@gmail.com
# imask = 1,6,8
# isub = [Gmail]/
#dx = 8,2,6
}
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.
The instructional message at the end is not printed under db0.
edbrowse -d0 -f2
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.
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 in Linux. 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.
If you delete an email from inbox with the d command, it is still in all mail. It isn't really gone. As mentioned earlier, you have to move it to trash and then delete it from there. This can be helpful however if you accidentally delete an email. Find it in all mail, then move it back to inbox. In this special case, move isn't really a move, it is a relink, connecting it to both inbox and all mail, which is the way it was before.
If you uncomment the dx line, then hard deletes only take place in folders 8, 2, and 6 - trash, spam, and all-mail. d in any other folder moves the mail to trash. Trash is assumed to be the first entry in the dx list. As mentioned earlier, this is how you delete emails in gmail. d covertly moves it to trash, and every week or so you can empty the trash with the bulk delete command. Other imap servers don't work this way; they aren't this complicated. In comcast, delete is delete, wherever you are. However, you can still choose to have d mean move to trash, if you want to guard against accidental deletes from your inbox.
If you uncomment the isub line, the initial substring is not printed. [Gmail]/Spam is simply Spam. It is a convenience.
If you uncomment the imask line, you will see only those folders so designated, in this example, INBOX, Spam, and Trash. This can save time; there are often folders that you rarely want to access. The imask command can toggle this feature interactively. Thus you can still view all the folders if you wish, without changing your config file.
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 insensitive. 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
r mark as read
R mark as unread
e envelope format string
l set fetch limit
= print the number of messages in the list
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, z = size, n = number in sequence, and u = unseen. The earlier examples are fsdz, from subject date size, however, the default is fs, from and subject. This is usually all I need.
The number is the position of the email in your buffer, not on the imap server. If you delete an email, the numbers shift. At first this seems strange, but it's the same as editing a text buffer. Delete a line, and the subsequent line numbers shift. Type = to see how many emails are still in your buffer.
If u is in the format, a star appears by the emails you haven't read yet. These are "unseen". Once you read an email, its star goes away. Use r to mark an email as read, and R to mark it as unread. The * disappears, and appears, respectively.
If you are looking at someone else's email, with their permission I hope, and you read an email that is not spam, something you want to keep, you need to type R to mark it as unread. If you don't do this, her mail client might not pick it up. In other words, she might never see it. Similarly, if it is your own email account, and you sometimes view it with a different client, you should mark it as unread, to make sure the other client sees it.
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 sitting 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. I try to put you back in that folder, and recover gracefully. This usually works well, but sometimes it doesn't, depending on the error conditions.
Imap Within Edbrowse.
Edbrowse presents an ed-like interface in almost everything it does: browsing, file manager, sql database, irc client, etc. In fact that is part of its appeal. To this end, there is an integrated interface to imap. This presents a seamless user experience, as seen on other platforms. While reading an email, you can go to a hyperlink, issue a reply, delete the email, save its attachments, etc. The stand-alone client is faster for some things, but it can't perform all these integrated operations.
Suppose Susan sends you an email asking if you are coming to her party. You don't need to keep this email forever, you just want to reply and delete. There is no reply in the stand-alone mail client, because there is no editor; but within edbrowse you can do this.
# Your primary email account is first in .ebrc
imap 1
# you now have a list of folders one per line
/Inbox
Inbox 7
# You usually keep your inbox clean, there are 7 new messages
g
95
# now in the inbox folder, like going to a directory
# Envelopes are one per line
/Susan
Susan Fransisco | Party this Saturday Night
g
5346
1547
# raw mail is 5346 bytes, browsed is 1547
,p
# let's just say you read a few lines to see that she's asking if you're coming to the party
re
# now ready to reply, staying in the thread, if that matters
5,$c
Yes I can come, and I'm looking forward to it
.
sm
ok
# reply is sent
bw
^
# back up to the envelopes
d
# don't need that email any more
,p
# look through the other 6 emails and decide what to do with them
Because you are writing a reply, the integrated approach is preferred. However, the imap client is faster for checking folders, deleting spam, and other simple tasks.
Call up a server by the "imap n" command. n is the number of the mail block in your config file. imap 0 closes down the connection and clears the buffer.
If the connection is made successfully, there is one folder per line in the buffer. This line will have the message count, so many messages in the folder; unless that folder is excluded by an imask directive in its mail block. In that case the count is simply a question mark. This behavior is similar to, though not identical to, the stand-alone mail client. The client doesn't print the excluded folders at all. In an edbrowse buffer, all the folders are present, with counts by those that are active.
The imask command toggles the imask feature on and off. It is only available in this window, and is per account.
Type /expression to find the folder you want, then type g to go to it, as we did with INBOX above. You can do this even if the folder is excluded by imask.
In a new buffer, you will find the most recent emails, one envelope per line. (The folders are still up one level in your history.) These are in time order, with the newest email at the bottom. Type g to go to an email, and it is in a new buffer. From here the contents of an email, raw or browsed, can be manipulated in the usual way. If a link interests you, go to it; you couldn't do that from the imap client, because it is not a browser.
^ goes back up to the list of envelopes, and ^ again goes back up to the folders.
d deletes an email, either the email you are reading, or the email indicated by the current envelope. In the page of envelopes, you can delete a range of emails, or a collection of emails via g/re/d. Be careful, there is no undo. However, delete might not actually delete on the server, depending on the server - and you can use the dx directive, as described above, to make d act like a move to trash in certain folders.
d removes the envelope you are on, but does not adjust the page above. Back up to folders and the message count is still what it was before. Type rf to get a new, accurate message count on all the folders.
When viewing the folders or the envelopes, "l number" will change the fetch limit, how many envelopes fetched at a time, and "e format" changes the format of the envelope. These are the same as the imap client. For instance, "e fstd" shows from, subject, to, and date. The n attribute is not meaningful here, since edbrowse already maintains line numbers for you. If you are on the envelopes page, you might want to refresh, so you can see them in the new format.
A limit of -n fetches the first n emails, rather than the most recent. This makes it easy to clear out the old emails.
edbrowse can perform a remote search on the imap server. This isn't just a search through the emails in your buffer; the search takes place on the server, through all of your emails. For the folder on the current line, the following searches apply.
/f fred : emails that come from Fred
/t wilma : emails that were sent to Wilma
/s paypal transfer : emails with paypal and transfer in the subject line
/b baseball : emails that mention baseball anywhere in the body
Any other /expression is just a text search through the buffer as usual.
The envelope and fetch limits still apply. You can ask for the first 20, or last 30, emails of this search, for example.
When viewing an envelope, or reading the associated mail, "m abc" will move the email to the folder whose name contains abc. Because the email is gone, edbrowse automatically pops the window, and puts you back in the envelopes. The envelope for this email is also gone. "t abc" copies the email to the abc folder. This leaves you where you are. On the page of envelopes, you can move or copy a range of emails, or a collection via g/re/m abc. (Copy is not implemented in stand-alone imap.)
Numbers are also valid in the move and copy commands. If abc is the third folder, you can type "m 3" or "t 3". It is probably safer and easier however, to type in the name of the folder or a fragment of its name.
If you happen to have the abc folder open in another buffer, and you move an email into that folder, it will not appear in that list of envelopes. It can't, because it acquires a new uid from the imap server once it moves. The uid is how edbrowse accesses that email, to perform any operations. You must refresh the abc envelopes to see that email. It will be the most recent, even if it was send years ago. In that sense, it probably doesn't help to have multiple folders open simultaneously. Descend into a folder, do some work, go back up, descend into another folder, etc.
When reading an email, there is a write command that mirrors the imap client. "w foo" writes the email formatted to the file foo, and saves the raw email in the directory ~/.trash/rawmail. This is what the mail client does, although it places your files in the mailbox directory, while this session saves the files wherever you are.
The w command alone, without a filename, may select a default filename based on your address book. If it comes from an email address that is associated with the alias fred, edbrowse will ask you if you want to use fred. Of course you can change the filename to something else.
If the file already exists, the new email is appended, with a line of equal signs separating them. However, an attachment will not append. It might be a binary executable; appending one to another would make no sense. Each attachment must save in a stand-alone file.
The u command saves the email unformatted. Type "u filename" to specify a filename, otherwise edbrowse prompts you for one.
Capital W and U perform the functions of w and u, and then delete the email, just like the imap client. This necessarily takes you back up to the envelopes page, whereupon the envelope for this email will also be gone.
This is a special feature of an email that is in-buffer, when you issue the command w W u or U. If you want to write the text somewhere with no backup email in ~/.trash/rawmail, type ",w filename".
If you move the email away with the M command, this special functionality is lost. u means undo as usual. You can still save the raw email if you wish, by ub and then w. Or save the attachments by going to their hyperlinks. The imap client shortcuts are lost, and that's not a big deal, as long as you are aware of it. It's probably best to leave the email where it is.
The special write commands are also available on the envelopes page. Again, it is a leading w or u with no prefix, and it applies to the current line, that is to say, the email you are on. Edbrowse prints a byte count when the email is written, like writing any other file, then it prints the envelope you are on. This will be the next envelope if you used capital W or U to write and delete the email. The imap client works exactly the same way.
The reply commands re and rea can be used on an envelope. This is simply shorthand for g followed by re.
On the envelopes page, the r command, without suffix, marks a mail as read, without having to read it. Thus ,r marks all emails as read. If you have u in your envelope format, the stars go away.
Use r- to mark an email as unread, as though you had not seen it. If you have u in your envelope format, the stars reappear.