Gnus is a powerful email client.
But many people get lost in its endless features. It would be much easier if they had learned the essential 5% features and ignored the remaining 95% at the beginning.
Here is my guide on that 5%.
- Introduction
- Why (OPTIONAL)
- Quick start
- Essential 5%
- Advanced tips
- Windows setup
- Microsoft Outlook
- Auto-complete mail address
- Synchronize from Gmail contacts
- Customize “From” field
- Why Gnus is slow to start up
- Classify email
- Write HTML mail
- Read HTML mail
- Read mail offline
- Paste image from clipboard
- Multiple accounts
- Why Gnus displays more mails than Gmail
- Subscribe “Sent Mail” folder
- Reconnect mail server
- Use Hydra to avoid remembering key bindings
- Use Gwene to read RSS/Atom feed as a news group
- My “~/.gnus.el”
- Copyright
- Gnus is solid
- Works on all platforms
- Less resource required
- Searcher and filter is great
- Mail can be viewed offline. See the “offline” in section “Advanced tips”
- Powerful when used with other Emacs plugins (Yasnippet, Evil, Swiper, …)
- This guide applies to Emacs24+
- You need install GnuTLS and OpenSSH on Linux/Mac/Window(Cygwin)
C
meansCtrl
andM
meansAlt
. For example,M-x
means pressingAlt
andx
together.M-x mycommand
means pressingAlt
andx
, input “mycommand”, and pressEnter
key.RET
isEnter
keyGroup
is the mail folderGroup buffer
is the buffer which lists mail foldersSummary buffer
is the buffer which lists mails~
means HOME directory. The full path of~
is the value of the environment variableHOME
. For example,~/.gnus.el
means a file named.gnus.el
is placed in HOME directory. Only on Windows, you must setup HOME environment variable manually.- Gmail server is used in sample code but this article is generic enough for all POP3/SMTP/IMAP server
M-x gnus
will load ~/.gnus.el
. Usually we place all setup code in ~/.gnus.el
so third party libraries used only by Gnus is not loaded during Emacs startup.
Before start Gnus, you must create .gnus.el
. You could use my my “~/.gnus.el”.
After starting Gnus by M-x gnus
, you come to the “Group Buffer”. The “Group Buffer” lists the mail folders. In Gnus, the folder is called “Group”. Please note the folders are invisible in Group Buffer by default!
You need subscribe a group to make it visible. For example, INBOX is named “nnimap+gmail:INBOX” in “Group Buffer” and it’s invisible at the beginning! It’s confusing for users.
Check section Subscribe groups on how to subscribe groups.
At minimum, you need subscribe INBOX group. The subscribed group could still be invisible if it contains zero unread mails. Yes, I admit this makes no sense for a modern email client!
You need C-u 5 M-x gnus-group-list-all-groups
to solve this problem.
You can insert below code into ~/.gnus.el
to create hotkey o
for C-u 5 M-x gnus-group-list-all-groups
:
(defun my-gnus-group-list-subscribed-groups ()
"List all subscribed groups with or without un-read messages"
(interactive)
(gnus-group-list-all-groups 5))
(define-key gnus-group-mode-map
;; list all the subscribed groups even they contain zero un-read messages
(kbd "o") 'my-gnus-group-list-subscribed-groups)
In the “Group Buffer”, you can enter a folder by pressing RET
(executing command gnus-topic-select-group
).
But I strongly suggest using C-u RET
in order to see all the mails instead of unread mails. After C-u RET
, you will be asked how many mails to display. If you never delete or move the mail in inbox, the number you provided is usually the exact number of mails to be displayed. If you do delete or move mails in inbox but Gnus is still using the cached data of inbox, you need provide a bigger number instead. Another solution is to delete files .newsrc.eld
or .newsrc-dribble
and restart Gnus.
An opened mail folder is called “Summary Buffer”.
Press RET
or C-u RET
to enter the “Summary Buffer”. Press q
to quit “Summary Buffer”.
In short, “Group Buffer” lists mail folders. “Summary Buffer” lists mails in one folder.
It’s waste of time to memorize keybindings because I provide my Hydra setup in Use Hydra to avoid remembering key bindings.
Press A A
or M-x gnus-group-list-active
in “Group Buffer” to fetch groups from all connected server. It takes a while. I suggest pressing “L” to use local cache instead. You need A A
when it’s the first time you use Gnus.
After A A
or L
, press u
to subscribe/unsubscribe specific group.
In order to see all the mails in “INBOX” folder/group, you need manually subscribe the group “INBOX”!
Pressing o
is much better. It is the hotkey I created for C-u 5 M-x gnus-group-list-all-groups
, as mentioned in previous sections.
Press g
or M-x gnus-group-get-new-news
to refresh groups list.
You can also subscribe groups programmatically by insert below code into ~/.gnus.el
:
;; Please note below code is not included in sample .gnus.el
(defvar gnus-subscribe-groups-done nil
"Only subscribe groups once. Or else Gnus will NOT restart.")
(unless gnus-subscribe-groups-done
(gnus-subscribe-hierarchically "nnimap+hotmail:Inbox")
(setq gnus-subscribe-groups-done t))
Press G G
or M-x gnus-group-make-nnir-group
to search mails at server side in “Group Buffer”.
A temporary group is created to store the search result. Since it’s a group, it can be subscribed, like other groups.
You can press #
to mark the groups (mail folders). Search is limited to marked groups. M-#
to un-mark.
If no group is marked, the group under cursor is searched.
If cursor is placed before the first group, all groups will be searched.
You can use more advanced search syntax (RFC3501 section SEARCH command) by:
- Press
C-u G G
orC-u M-x gnus-group-make-nnir-group
- Input query statements, press Enter
- Type
imap
, press Enter
For example, query statement TEXT github SINCE 1-Jan-2016 FROM chenbin
means searching mails are sent by me and contains keyword “github” on year 2016.
I recommend using dianyou-group-make-nnir-group
from dianyou (I’m the author of dianyou) to replace gnus-group-make-nnir-group
. It supports shortcuts in query. For example “t github s 1y2w3d f chenbin” means search mails containing text “github” and sent by chenbin since 1 year 2 weeks 3 days ago.
People who dislike RFC3501 could use Gmail syntax(Roy Hashimoto provides this tip),
gnus-summary-make-nnir-group
is similar to gnus-group-make-nnir-group
but it only searches mails in current group.
;; Let Gnus know Gmail search syntax
(add-to-list 'nnir-imap-search-arguments '("gmail" . "X-GM-RAW"))
;; `gnus-group-make-nnir-group' use Gmail search syntax *by default*.
;; You can press `G G` instead `C-u G G` instead.
(setq nnir-imap-default-search-key "gmail")
Press / /
to limit the mails by subject at “Summary Buffer”. In Emacs, “Limiting” means filtering mails locally.
Press / a
to limit the mails by author.
/ w
to cancel the current filter.
You can apply the limits sequentially and cancel them in reverse order by pressing / w
multiple times.
“Limiting” is cool. See http://www.gnu.org/software/emacs/manual/html_mono/gnus.html#Limiting for more Limiting tricks.
You can also see http://sachachua.com/blog/2008/05/emacs-gnus-searching-mail/ for technical details.
Press R
or M-x gnus-summary-reply-with-original
to reply with quoted text. Press r
or M-x gnus-summary-reply
to reply WITHOUT quoted text.
Press S W
(capitalized S then capitalized W) or M-x gnus-summary-wide-reply-with-original
to reply all with quoted text. Please note “reply all” is called “wide reply” in Emacs.
Press S w
or M-x gnus-summary-wide-reply
to reply all without quoted text.
Press m
or M-x gnus-new-mail
in “Summary Buffer”.
You could also C-x m
or M-x compose-mail
anywhere in Emacs without bugging Gnus.
Press S D e
or M-x gnus-summary-resend-message-edit
. You could re-send a mail in Draft folder.
Press C-c C-a
or M-x mml-attach-file
.
The attached file is actually plain text embedded in mail body which could be copied and modified.
Move focus over the attachment and press o
or M-x gnus-mime-save-part
. See ”Using Mime” in Emacs manual for details.
Please note gnus-mime-save-part
return the full path of saved file which can be inserted into clipboard. This is an example how Gnus could be extended.
Move focus over the attachment and press Enter
or M-x gnus-article-press-button
.
The variable mailcap-mime-data defines the program to open the attachment.
You can tweak the variable on Windows or macOS.
On Linux, run M-x mailcap-parse-mailcaps
to load data from ~/.mailcap
into mailcap-mime-data
instead of modifying mailcap-mime-data
directly.
Other programs use ~/.mailcap
too. So it’s better to make Gnus follow suit.
My ~/.mailcap
:
# url
text/html; w3m -I %{charset} -T text/html; copiousoutput;
# image viewer
image/*; feh -F -d -S filename '%s';
# pdf
application/pdf; zathura '%s';
image/pdf; zathura '%s'
# video
video/* ; mplayer '%s'
audio/* ; mplayer '%s'
# Office files.
application/msword; soffice '%s'
application/rtf; soffice '%s'
text/richtext; soffice '%s'
application/vnd.ms-excel; soffice '%s'
application/vnd.ms-powerpoint; soffice '%s'
Press C-c C-c
or M-x message-send-and-exit
.
Press / N
or M-x gnus-summary-insert-new-articles
.
Select a group and press C-u RET
in “Group Buffer”. Or C-u M-g
in “Summary Buffer”.
That’s the most important part of this article! By default, Gnus only displays unread mails.
See http://stackoverflow.com/questions/4982831/i-dont-want-to-expire-mail-in-gnus for details.
Press C-c C-f
or M-x gnus-summary-mail-forward
in “Summary Buffer”.
You can mark multiple mails (hotkey is “#”) and forward them in one mail. Holger Schauer provided the tip.
After the forwarded email is created, you may copy the body of that email without sending it. The copied content could be inserted into new mail.
Press c
either in “Summary Buffer” or “Group Buffer”. This is my favorite used command because it’s faster than other mail clients.
Group Topics is used to re-organize the mail folder into tree view.
For example, you can place mail folders from Gmail into “gmail” topic, mails from Outlook.com into “hotmail” topic, place “gmail” and “hotmail” under root topic “Gnus”.
Only one line to enable gnus-topic-mode
,
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
After setup, you can read its official manual to learn how to organize mail folders manually.
It’s tiresome to do this folder organizing thing again and again on different computers.
So you’d better use my way.
All you need to do is to insert below code into ~/.gnus.el
,
(eval-after-load 'gnus-topic
'(progn
(setq gnus-message-archive-group '((format-time-string "sent.%Y")))
(setq gnus-topic-topology '(("Gnus" visible)
(("misc" visible))
(("hotmail" visible nil nil))
(("gmail" visible nil nil))))
;; key of topic is specified in my sample ".gnus.el"
(setq gnus-topic-alist '(("hotmail" ; the key of topic
"nnimap+hotmail:Inbox"
"nnimap+hotmail:Sent"
"nnimap+hotmail:Drafts")
("gmail" ; the key of topic
"nnimap+gmail:INBOX"
"nnimap+gmail:[Gmail]/Sent Mail"
"nnimap+gmail:[Gmail]/Drafts")
("misc" ; the key of topic
"nnfolder+archive:sent.2015-12"
"nnfolder+archive:sent.2016"
"nndraft:drafts")
("Gnus")))))
Instead of remembering extra commands, editing above snippet is more straightforward. The only requirement is a little Emacs Lisp knowledge.
The flag gnus-message-archive-group
defines local folder for archived sent mails. By default, the folder is created monthly. My setup creates the folder yearly.
Please install Cygwin at first.
Gnus from Cygwin version of Emacs works out of the box.
Native Emacs for Windows need a little setup:
- Right-click “My Computer” and go to “Properties -> Advanced -> Environmental Variables”
- Setup user variables which does not require Administrator right
- Set the variable “HOME” to the parent directory of your “.emacs.d” directory
- Set the variable “PATH” to the “C:\cygwin64\bin”. I suppose Cygwin is installed at driver C.
- Install GnuTLS and OpenSSH through Cygwin package manager
If your Exchange Server is not using standard protocol like IMAP or you can’t access IMAP port behind firewall, you need DavMail, a “POP/IMAP/SMTP/CalDAV/CardDAV/LDAP exchange gateway”.
Please read its manual, it’s simple to set up.
Here are a few tips for DavMail setup.
The Administrator might use non-standard OWA url
, you can use EWSEditor to find out the url.
The IMAP setup should set nnimap-stream
to plain
by default.
Here is a sample setup for Davmail:
(setq gnus-select-method
'(nnimap "companyname"
(nnimap-address "127.0.0.1")
(nnimap-server-port 1143)
(nnimap-stream plain)
(nnir-search-engine imap)))
As I tested, IMAP search command of Davmail does not support “OR” and “NOT” operator. Maybe it’s because Davmail is only wrapper of Microsoft’s HTTP API which has limited functionalities.
Install BBDB through melpa. It is an email address database written in Emacs Lisp.
You can always use M-x bbdb-complete-name
and M-x bbdb-complete-mail
provided by BBDB.
But there are other better plugins based on BBDB (so you still need install BBDB at first):
- counsel-bbdb (counsel-bbdb is a lightweight alternative developed by me)
- company-mode
- bbdb-handy
You only need one of above packages.
If BBDB is updated yet, you can insert email address from received mails instead. Run M-x dianyou-insert-email-address-from-received-mails
from dianyou.
Please,
- Go to https://www.google.com/contacts/
- Click “More -> Export -> vCard Format -> Export”
- Install https://github.com/redguardtoo/gmail2bbdb and press
M-x gmail2bbdb-import-file
. The contacts will be output into~/.bbdb
which is automatically detected by Emacs.
Other plugins are strict on versions of BBDB. Mine doesn’t have such issue.
The easiest solution is to switch the “FROM” field dynamically by M-x toggle-mail-from-field
,
;; Please note below code is not included in sample .gnus.el
(defun toggle-mail-from-field ()
(interactive)
(cond
((string= "[email protected]" user-mail-address)
(setq user-mail-address "[email protected]"))
(t
(setq user-mail-address "[email protected]")))
(message "Mail FROM: %s" user-mail-address))
A more complex solution is to set up FROM field by the computer you are using:
;; Please note above code is not included in sample .gnus.el
;; (getenv "HOSTNAME") won't work because $HOSTNAME is not an env variable
;; (system-name) won't work because my /etc/hosts has some weird setup in office
(setq my-hostname (with-temp-buffer
(shell-command "hostname" t)
(goto-char (point-max))
(delete-char -1)
(buffer-string)))
(defun at-office ()
(interactive)
(and (string= my-hostname "my-sydney-workpc")
(not (or (string= my-hostname "homepc")
(string= my-hostname "eee")))))
(setq user-full-name "My Name"
user-mail-address (if (at-office) "[email protected]" "[email protected]"))
Please note,
- Command line program
hostname
is better than Emacs function(system-name)
- I work on several computers which do not belong to me, so I cannot change
/etc/hosts
which(system-name)
try to access - Please verify your email address at Gmail if you use Google’s SMTP server
Gnus need fetch flags of all mails during startup. As I investigated, nnimap-retrieve-group-data-early
sends the command UID FETCH 1:* FLAGS
to the IMAP server.
To speedup startup,
- Don’t restart Gnus
- Move old mails into a folder named “archived”. That folder should be invisible to Gnus
You may think Google Inbox equals to Popfile. Trust me, it’s not. You only need Popfile!
Popfile is open source software. The data is stored locally. So you can use still same setup&data when you switch to another email service.
Check http://blog.binchen.org/posts/use-popfile-at-linux.html for details.
I use the command cd ~/bin/popfile/ && perl popfile.pl
to start popfile
. The “cd” part in CLI is necessary.
Use org-mime.
Usage is simple. Write mail in org format and M-x org-mime-htmlize
.
Please use org-mime which supports Emacs 24+. It’s also the official version of org-mime
.
No setup is required. It works out of box.
Emacs will use built in browser shr
to render HTML since version 24.4
.
The built in browser can display HTML colors.
Another option is use external program w3m and package emacs-w3m.
I prefer w3m
because it has powerful APIs but unfortunately it can’t render colors.
Below code enables w3m
,
(setq mm-text-html-renderer 'w3m)
On Windows, you can install w3m
through Cygwin
.
Go to “Summary Buffer”.
Mark mails by pressing !
or M-x gnus-summary-tick-article-forward
.
The marked mails enter the disk cache. They can be read offline.
M-x gnus-summary-put-mark-as-read-next
to remove the cached mail and move focus to next mail.
You also need insert below code into ~/.emacs
,
(setq gnus-use-cache t)
Above code uses the cache to the full extent by “wasting” tens of megabytes of disk space.
The disk cache is located at ~/News/cache/
which can be pushed to Git private repository.
Use dianyou-paste-image-from-clipboard
from dianyou. CLI program xclip should be installed at first.
You only need copy the code containing gnus-secondary-select-methods
from my setup.
Here is a sample setup,
(add-to-list 'gnus-secondary-select-methods
'(nnimap "gmail-second"
(nnimap-address "imap.gmail.com")
(nnimap-server-port 993)
(nnimap-stream ssl)
(nnir-search-engine imap)
; @see http://www.gnu.org/software/emacs/manual/html_node/gnus/Expiring-Mail.html
;; press 'E' to expire email
(nnmail-expiry-target "nnimap+gmail:[Gmail]/Trash")
(nnmail-expiry-wait 90)))
gnus-secondary-select-methods
is the list of your accounts.
The information of multiple accounts is stored in ~/.authinfo.gpg
.
Gnus counts by individual mail. Gmail counts by mail thread.
It’s recommended to subscribe “[Gmail]/Sent Mail” folder So you can see your sent mails in Gnus.
Press M-x gnus-group-enter-server-mode
to list all the servers.
Move the cursor to the offline server and M-x gnus-server-open-server
.
Install Hydra through http://melpa.org/
Insert below code into ~/.emacs
. Then press C-c C-y
when composing mail. Press y
in other modes,
;; @see https://github.com/redguardtoo/mastering-emacs-in-one-year-guide/blob/master/gnus-guide-en.org
;; gnus-group-mode
(eval-after-load 'gnus-group
'(progn
(defhydra hydra-gnus-group (:color blue)
"
[_A_] Remote groups (A A) [_g_] Refresh
[_L_] Local groups [_\\^_] List servers
[_c_] Mark all read [_m_] Compose new mail
[_G_] Search mails (G G) [_#_] Mark mail
"
("A" gnus-group-list-active)
("L" gnus-group-list-all-groups)
("c" gnus-topic-catchup-articles)
("G" dianyou-group-make-nnir-group)
("g" gnus-group-get-new-news)
("^" gnus-group-enter-server-mode)
("m" gnus-group-new-mail)
("#" gnus-topic-mark-topic)
("q" nil))
;; y is not used by default
(define-key gnus-group-mode-map "y" 'hydra-gnus-group/body)))
;; gnus-summary-mode
(eval-after-load 'gnus-sum
'(progn
(defhydra hydra-gnus-summary (:color blue)
"
[_s_] Show thread [_F_] Forward (C-c C-f)
[_h_] Hide thread [_e_] Resend (S D e)
[_n_] Refresh (/ N) [_r_] Reply
[_!_] Mail -> disk [_R_] Reply with original
[_d_] Disk -> mail [_w_] Reply all (S w)
[_c_] Read all [_W_] Reply all with original (S W)
[_#_] Mark [_G_] Search mails
"
("s" gnus-summary-show-thread)
("h" gnus-summary-hide-thread)
("n" gnus-summary-insert-new-articles)
("F" gnus-summary-mail-forward)
("!" gnus-summary-tick-article-forward)
("d" gnus-summary-put-mark-as-read-next)
("c" gnus-summary-catchup-and-exit)
("e" gnus-summary-resend-message-edit)
("R" gnus-summary-reply-with-original)
("r" gnus-summary-reply)
("W" gnus-summary-wide-reply-with-original)
("w" gnus-summary-wide-reply)
("#" gnus-topic-mark-topic)
("G" dianyou-group-make-nnir-group)
("q" nil))
;; y is not used by default
(define-key gnus-summary-mode-map "y" 'hydra-gnus-summary/body)))
;; gnus-article-mode
(eval-after-load 'gnus-art
'(progn
(defhydra hydra-gnus-article (:color blue)
"
[_o_] Save attachment [_F_] Forward
[_v_] Play video/audio [_r_] Reply
[_d_] CLI to dowloand stream [_R_] Reply with original
[_b_] Open external browser [_w_] Reply all (S w)
[_f_] Click link/button [_W_] Reply all with original (S W)
[_g_] Focus link/button
"
("F" gnus-summary-mail-forward)
("r" gnus-article-reply)
("R" gnus-article-reply-with-original)
("w" gnus-article-wide-reply)
("W" gnus-article-wide-reply-with-original)
("o" gnus-mime-save-part)
("v" w3mext-open-with-mplayer)
("d" w3mext-download-rss-stream)
("b" w3mext-open-link-or-image-or-url)
("f" w3m-lnum-follow)
("g" w3m-lnum-goto)
("q" nil))
;; y is not used by default
(define-key gnus-article-mode-map "y" 'hydra-gnus-article/body)))
;; message-mode
(eval-after-load 'message
'(progn
(defhydra hydra-message (:color blue)
"
[_c_] Complete mail address
[_a_] Attach file
[_s_] Send mail (C-c C-c)
"
("c" counsel-bbdb-complete-mail)
("a" mml-attach-file)
("s" message-send-and-exit)
("i" dianyou-insert-email-address-from-received-mails)
("q" nil))))
(defun message-mode-hook-hydra-setup ()
(local-set-key (kbd "C-c C-y") 'hydra-message/body))
(add-hook 'message-mode-hook 'message-mode-hook-hydra-setup)
You can either submit single RSS/Atom feed url or upload OMPL file.
I suggest using emacs-w3m to upload OPML file because it’s easy to select the links created by Gwene.
Then you can use techniques I introduced in previous section “Tree view of mail folders” to organize the feeds.
To view or download video/audio in feed, you can use mplayer if its support for network streaming is enabled. It’s should be enabled by default at Linux/macOS/Windows.
I created three commands w3mext-open-with-mplayer
, w3mext-download-rss-stream
, and w3mext-open-link-or-image-or-url
to process multimedia,
;; Please note below code is not included in sample .gnus.el
;; https://www.emacswiki.org/emacs/emacs-w3m
(require 'w3m)
;; Install https://github.com/rolandwalker/simpleclip for clipboard support
(require 'simpleclip)
(defun my-buffer-str ()
(buffer-substring-no-properties (point-min) (point-max)))
(defun my-guess-image-viewer-path (file &optional is-stream)
(let ((rlt "mplayer"))
(cond
(*is-a-mac*
(setq rlt
(format "open %s &" file)))
(*linux*
(setq rlt
(if is-stream (format "curl -L %s | feh -F - &" file) (format "feh -F %s &" file))))
(*cygwin* (setq rlt "feh -F"))
(t ; windows
(setq rlt
(format "rundll32.exe %SystemRoot%\\\\System32\\\\\shimgvw.dll, ImageView_Fullscreen %s &" file))))
rlt))
(defun my-guess-mplayer-path ()
(let* ((rlt "mplayer"))
(cond
(*is-a-mac* (setq rlt "mplayer -quiet"))
(*linux* (setq rlt "mplayer -quiet -stop-xscreensaver"))
(*cygwin*
(if (file-executable-p "/cygdrive/c/mplayer/mplayer.exe")
(setq rlt "/cygdrive/c/mplayer/mplayer.exe -quiet")
(setq rlt "/cygdrive/d/mplayer/mplayer.exe -quiet")))
(t ; windows
(if (file-executable-p "c:\\\\mplayer\\\\mplayer.exe")
(setq rlt "c:\\\\mplayer\\\\mplayer.exe -quiet")
(setq rlt "d:\\\\mplayer\\\\mplayer.exe -quiet"))))
rlt))
(defun w3mext-subject-to-target-filename ()
(let (rlt str)
(save-excursion
(goto-char (point-min))
;; first line in email could be some hidden line containing NO to field
(setq str (my-buffer-str)))
(if (string-match "^Subject: \\(.+\\)" str)
(setq rlt (match-string 1 str)))
;; clean the timestamp at the end of subject
(setq rlt (replace-regexp-in-string "[ 0-9_.'/-]+$" "" rlt))
(setq rlt (replace-regexp-in-string "'s " " " rlt))
(setq rlt (replace-regexp-in-string "[ ,_'/-]+" "-" rlt))
rlt))
(defun w3mext-download-rss-stream ()
(interactive)
(let (url cmd)
(when (or (string= major-mode "w3m-mode") (string= major-mode "gnus-article-mode"))
(setq url (w3m-anchor))
(cond
((or (not url) (string= url "buffer://"))
(message "This link is not video/audio stream."))
(t
(setq cmd (format "curl -L %s > %s.%s" url (w3mext-subject-to-target-filename) (file-name-extension url)))
(kill-new cmd)
(simpleclip-set-contents cmd)
(message "%s => clipd/kill-ring" cmd))))))
(defun w3mext-open-link-or-image-or-url ()
"Opens the current link or image or current page's uri or any url-like text under cursor in firefox."
(interactive)
(let* (url)
(when (or (string= major-mode "w3m-mode") (string= major-mode "gnus-article-mode"))
(setq url (w3m-anchor))
(if (or (not url) (string= url "buffer://"))
(setq url (or (w3m-image) w3m-current-url))))
(browse-url-generic (if url url (car (browse-url-interactive-arg "URL: "))))))
(defun w3mext-encode-specials (str)
(setq str (replace-regexp-in-string "(" "%28" str))
(setq str (replace-regexp-in-string ")" "%29" str))
(setq str (replace-regexp-in-string ")" "%20" str)))
(defun w3mext-open-with-mplayer ()
(interactive)
(let (url cmd str)
(when (or (string= major-mode "w3m-mode") (string= major-mode "gnus-article-mode"))
;; weird, `w3m-anchor' fail to extract url while `w3m-image' can
(setq url (or (w3m-anchor) (w3m-image)))
(unless url
(save-excursion
(goto-char (point-min))
(when (string-match "^Archived-at: <?\\([^ <>]*\\)>?" (setq str (my-buffer-str)))
(setq url (match-string 1 str)))))
(setq url (w3mext-encode-specials url))
(setq cmd (format "%s -cache 2000 %s &" (my-guess-mplayer-path) url))
(when (string= url "buffer://")
;; cache 2M data and don't block UI
(setq cmd (my-guess-image-viewer-path url t))))
(if url (shell-command cmd))))
Please note these commands require (setq mm-text-html-renderer 'w3m)
.
Emacs 24.4+ is required,
(require 'nnir)
;; Please note mail folders in `gnus-select-method' have NO prefix like "nnimap+hotmail:" or "nnimap+gmail:"
(setq gnus-select-method '(nntp "news.gwene.org")) ;; Read feeds/atom through gwene
;; ask encryption password once
(setq epa-file-cache-passphrase-for-symmetric-encryption t)
;; @see http://gnus.org/manual/gnus_397.html
(add-to-list 'gnus-secondary-select-methods
'(nnimap "gmail"
(nnimap-address "imap.gmail.com")
(nnimap-server-port 993)
(nnimap-stream ssl)
(nnir-search-engine imap)
; @see http://www.gnu.org/software/emacs/manual/html_node/gnus/Expiring-Mail.html
;; press 'E' to expire email
(nnmail-expiry-target "nnimap+gmail:[Gmail]/Trash")
(nnmail-expiry-wait 90)))
;; OPTIONAL, the setup for Microsoft Hotmail
(add-to-list 'gnus-secondary-select-methods
'(nnimap "hotmail"
(nnimap-address "imap-mail.outlook.com")
(nnimap-server-port 993)
(nnimap-stream ssl)
(nnir-search-engine imap)
(nnmail-expiry-wait 90)))
(setq gnus-thread-sort-functions
'(gnus-thread-sort-by-most-recent-date
(not gnus-thread-sort-by-number)))
; NO 'passive
(setq gnus-use-cache t)
;; {{ press "o" to view all groups
(defun my-gnus-group-list-subscribed-groups ()
"List all subscribed groups with or without un-read messages"
(interactive)
(gnus-group-list-all-groups 5))
(define-key gnus-group-mode-map
;; list all the subscribed groups even they contain zero un-read messages
(kbd "o") 'my-gnus-group-list-subscribed-groups)
;; }}
;; BBDB: Address list
(add-to-list 'load-path "/where/you/place/bbdb/")
(require 'bbdb)
(bbdb-initialize 'message 'gnus 'sendmail)
(add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)
(setq bbdb/mail-auto-create-p t
bbdb/news-auto-create-p t)
;; auto-complete emacs address using bbdb UI
(add-hook 'message-mode-hook
'(lambda ()
(flyspell-mode t)
(local-set-key (kbd "TAB") 'bbdb-complete-name)))
;; Fetch only part of the article if we can.
;; I saw this in someone's .gnus
(setq gnus-read-active-file 'some)
;; open attachment
(eval-after-load 'mailcap
'(progn
(cond
;; on macOS, maybe change mailcap-mime-data?
((eq system-type 'darwin))
;; on Windows, maybe change mailcap-mime-data?
((eq system-type 'windows-nt))
(t
;; Linux, read ~/.mailcap
(mailcap-parse-mailcaps)))))
;; Tree view for groups.
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
;; Threads! I hate reading un-threaded email -- especially mailing
;; lists. This helps a ton!
(setq gnus-summary-thread-gathering-function 'gnus-gather-threads-by-subject)
;; Also, I prefer to see only the top level message. If a message has
;; several replies or is part of a thread, only show the first message.
;; `gnus-thread-ignore-subject' will ignore the subject and
;; look at 'In-Reply-To:' and 'References:' headers.
(setq gnus-thread-hide-subtree t)
(setq gnus-thread-ignore-subject t)
;; Personal Information
(setq user-full-name "My Name"
user-mail-address "[email protected]")
;; Read HTML mail:
;; You need install the command line web browser 'w3m' and Emacs plugin 'w3m'
;; manually. It specify the html render as w3m so my setup works on all versions
;; of Emacs.
;;
;; Since Emacs 24+, a default html rendering engine `shr' is provided:
;; - It works out of box without any cli program dependency or setup
;; - It can render html color
;; So below line is optional.
(setq mm-text-html-renderer 'w3m) ; OPTIONAL
;; Send email through SMTP
(setq message-send-mail-function 'smtpmail-send-it
smtpmail-default-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 587
smtpmail-local-domain "homepc")
;; http://www.gnu.org/software/emacs/manual/html_node/gnus/_005b9_002e2_005d.html
(setq gnus-use-correct-string-widths nil)
;; Sample on how to organize mail folders.
;; It's dependent on `gnus-topic-mode'.
(eval-after-load 'gnus-topic
'(progn
(setq gnus-message-archive-group '((format-time-string "sent.%Y")))
(setq gnus-server-alist '(("archive" nnfolder "archive" (nnfolder-directory "~/Mail/archive")
(nnfolder-active-file "~/Mail/archive/active")
(nnfolder-get-new-mail nil)
(nnfolder-inhibit-expiry t))))
;; "Gnus" is the root folder, and there are three mail accounts, "misc", "hotmail", "gmail"
(setq gnus-topic-topology '(("Gnus" visible)
(("misc" visible))
(("hotmail" visible nil nil))
(("gmail" visible nil nil))))
;; each topic corresponds to a public imap folder
(setq gnus-topic-alist '(("hotmail" ; the key of topic
"nnimap+hotmail:Inbox"
"nnimap+hotmail:Drafts"
"nnimap+hotmail:Sent"
"nnimap+hotmail:Junk"
"nnimap+hotmail:Deleted")
("gmail" ; the key of topic
"nnimap+gmail:INBOX"
"nnimap+gmail:[Gmail]/Sent Mail"
"nnimap+gmail:[Gmail]/Trash"
"nnimap+gmail:Drafts")
("misc" ; the key of topic
"nnfolder+archive:sent.2018"
"nnfolder+archive:sent.2019"
"nndraft:drafts")
("Gnus")))))
Login and password is stored in ~/.authinfo.gpg
which is read by Gnus. Please press C-h v auth-sources
for more information.
Multiple mail accounts share one .authinfo.gpg
,
machine imap.gmail.com login [email protected] password my-secret-password port 993
machine smtp.gmail.com login [email protected] password my-secret-password port 587
machine imap-mail.outlook.com login [email protected] password my-secret-password port 993
Please note .authinfo.gpg
is encrypted by default. Emacs will do the encryption/description automatically if file extension is .gpg
. See http://emacswiki.org/emacs/EasyPG for details.
Copyright: This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.