update
[poppyer.git] / .gnus.el
blob413db75311ebd2860b9ba46b81885e0b936e3c5d
1 (setq gnus-use-dribble-file nil)
2 ;; (setq gnus-invalid-group-regexp "[:`'\"]\\|^$")
4 (setq gnus-select-method
6 ;; ; a ssl server on a non-standard port:
7 ;; '(nnimap "herald"
8 ;; (nnimap-authenticator login)
9 ;; (nnimap-address "ball2148.herald.ox.ac.uk")
10 ;; (nnimap-server-port 993)
11 ;; ; (nnimap-list-pattern ("INBOX" "mail/*" "Mail/*" "INBOX.*"))
12 ;; (nnimap-list-pattern ("*"))
13 ;; (nnimap-expunge-on-close ask)
14 ;; (nnimap-stream ssl)
15 ;; )
17 '(nnimap "gmail"
18 ; (nnimap-authenticator login)
19 (nnimap-address "imap.gmail.com")
20 (nnimap-server-port 993)
21 (nnimap-list-pattern ("*"))
22 (nnimap-expunge-on-close ask)
23 (nnimap-stream ssl))
26 ;; Filtering
27 (setq nnimap-split-inbox '("INBOX"))
28 ;this is slow, coz it need to get all active files
29 (setq nnimap-split-predicate "UNDELETED")
30 (setq nnimap-split-predicate "UNSEEN UNDELETED")
31 (setq nnimap-split-crosspost nil)
32 (setq nnimap-split-rule
34 ("Junk" "^To:.*OxfordFreecycle@yahoogroups.com")
35 ("Junk" "^To:.*balliolmcr@maillist.ox.ac.uk")
36 ("Junk" "^CC:.*balliolmcr@maillist.ox.ac.uk")
37 ("Junk" "^To:.*ambassadors@Sun.COM")
38 ("Junk" "^CC:.*ambassadors@Sun.COM")
39 ("Junk" "^To:.*kwiat@well.ox.ac.uk")
40 ("Junk" "^X-Oxmail-Spam-Level: \\*\\*\\*\\*")
45 (setq message-cite-prefix-regexp
46 "\\([ \t]*[-_.[:word:]]+>+\\|[ \t]*[]>|}+:]\\)+")
50 ;; layout
51 (gnus-add-configuration
52 '(article (vertical 1.0
53 ;; (group 4)
54 (summary .4 point)
55 (article 1.0)
60 ;; show only text from html?
61 (eval-after-load "mm-decode"
62 '(progn
63 (add-to-list 'mm-discouraged-alternatives "text/html")
64 (add-to-list 'mm-discouraged-alternatives "text/richtext")))
65 (setq gnus-mime-display-multipart-as-mixed t)
66 (setq mm-inline-override-types '("text/html"))
68 (add-hook 'gnus-article-mode-hook '(lambda ()
69 (setq truncate-lines nil)
70 ));;also can use W w each time
72 (defun jump-skip-citation ()
73 (interactive)
74 (gnus-summary-select-article-buffer)
75 (search-forward-regexp "^[^>\:][^\n:@]+$")
76 (beginning-of-line)
77 (recenter)
78 (gnus-article-show-summary)
81 ;; (add-hook 'gnus-select-article-hook '(lambda() ;; seems nor working!!
82 ;; (jump-skip-citation)
83 ;; ));
86 (require 'ansi-color)
87 (defun article-treat-ansi-sequences ()
88 "Translate ANSI SGR control sequences into overlays or extents."
89 (interactive)
90 (save-excursion
91 (set-buffer gnus-article-buffer)
92 (when (article-goto-body)
93 (let ((buffer-read-only nil))
94 (ansi-color-apply-on-region (point) (point-max))
95 (fix-screen-encoding-bug)
96 ))))
98 (defun fix-screen-encoding-bug()
99 (interactive)
100 (replace-string "¡°"
101 " \"" nil (point-min) (point-max))
102 (replace-string "¡±"
103 "\" " nil (point-min) (point-max))
104 (replace-string "¡¤"
105 "£®" nil (point-min) (point-max))
106 (replace-string "¡¶"
107 "<<" nil (point-min) (point-max))
108 (replace-string "¡·"
109 ">>" nil (point-min) (point-max))
110 (replace-string "¡Ã"
111 ": " nil (point-min) (point-max))
112 (replace-string "¡­"
113 "..." nil (point-min) (point-max))
116 (add-hook 'gnus-article-prepare-hook 'article-treat-ansi-sequences)
117 ;;(add-hook 'gnus-summary-prepare-hook 'fix-screen-encoding-bug)
119 ;; using decode-hook but no color, using display-hook is good
120 ;;(set 'gnus-article-decode-hook (cdr gnus-article-decode-hook))
122 (add-hook 'gnus-summary-mode-hook
123 '(lambda ()
124 (local-set-key "\M-j" 'jump-skip-citation)
125 (local-set-key "\M-c" 'article-treat-ansi-sequences)
126 (local-set-key [up] '(lambda ()
127 (interactive)
128 (when (> (count-windows) 1)
129 (delete-other-windows))
130 (previous-line 1)))
131 (local-set-key [down] '(lambda ()
132 (interactive)
133 (when (> (count-windows) 1)
134 (delete-other-windows))
135 (next-line 1)))
136 (local-set-key [\C-return] '(lambda ()
137 (interactive)
138 (gnus-summary-next-page)))))
142 (defun bounce-server ()
143 (interactive)
144 (let ((server (gnus-group-server (gnus-group-group-name))))
145 (progn
146 (gnus-server-close-server server)
147 (message "server closed, now reopen it...")
148 (gnus-server-open-server server)
149 (message "server reopened"))))
151 (add-hook 'gnus-group-mode-hook
152 '(lambda()
153 (local-set-key "O" 'bounce-server)
154 (local-set-key "\M-c" 'calculator)
158 ;; Hook to turn on autofill
159 (defun my-message-mode-setup ()
160 (setq fill-column 72)
161 (turn-on-auto-fill)
162 (flyspell-mode t))
163 (add-hook 'message-mode-hook 'my-message-mode-setup)
165 ;; Expire days
166 (setq nnmail-expiry-wait 2)
168 (load-library "gnus-group") ;; Needed for gnus-group-list-all-groups :P
169 (gnus-group-list-all-groups) ;; Show all the groups, even empty ones
172 (setq gnus-read-active-file 'some)
173 ;;(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
174 ;; fetch old headers when a new follow-up arrives ;; but t is slow, poppyer say
175 (setq gnus-fetch-old-headers nil)
176 (setq gnus-asynchronous t)
177 (setq gnus-use-article-prefetch nil)
178 (setq gnus-save-newsrc-file nil)
180 (setq gnus-extract-address-components
181 'mail-extract-address-components)
183 (defsubst gnus-user-format-function-S (header)
184 "Returns message size in kB for `gnus-summary-line-format', if greater than
185 `gnus-summary-line-show-size-threshold'."
186 (let* ((c (or (mail-header-chars header) 0)))
187 (if (> c gnus-summary-line-show-size-threshold)
188 (format "%3dk " (/ c 1024.0))
189 "")))
190 (defvar gnus-summary-line-show-size-threshold 10000
191 "(juhp) Value above which message size is shown in my summary line.")
192 (setq gnus-summary-line-format "%U%R%z%6uS %I%d %(%-20,20f:%) %s\n")
193 (setq gnus-group-line-format "%M%S%P%3L%3y: %(%-40g%)%O %2{%d%} %l \n")
194 (setq gnus-article-mode-line-format "Gnus: %g [%w] %m") ;; some subjects are too long
200 (require 'gnus-demon)
202 (setq level 2)
204 (defun sk-demon-notify-message ()
205 (if (> number-of-unread last-time-number-of-unread)
206 (progn
207 (if (> number-of-unread 0)
208 (beep))
209 (message (let ((number-of-new (- number-of-unread last-time-number-of-unread)))
210 (concat
211 "***** "
212 (int-to-string number-of-new)
213 " new mail"
214 (if (> number-of-new 1)
215 "s" "")
216 " received *****"
217 (if (> number-of-unread last-time-number-of-unread)
218 (concat " ("
219 (int-to-string (- number-of-unread number-of-new))
220 " old)"))
225 (if (= number-of-unread 0)
226 (message "No mail")
227 (message
228 (concat
229 (int-to-string number-of-unread)
230 " old unread mail"
231 (if (> number-of-unread 1)
232 "s" "")
238 (defun sk-gnus-demon-handler ()
239 (message "Checking new mail ...")
240 (save-window-excursion
241 (save-excursion
242 (when (gnus-alive-p)
243 (set-buffer gnus-group-buffer)
244 (gnus-group-get-new-news level))))
245 (setq last-time-number-of-unread number-of-unread)
246 (setq number-of-unread (gnus-group-number-of-unread-mail level))
247 (sk-demon-notify-message)
250 ;(setq gnus-demon-timestep 10)
252 ;(gnus-demon-add-handler 'sk-gnus-demon-handler 5 nil)
253 (gnus-demon-add-handler 'gnus-group-get-new-news 15 nil)
254 ;(gnus-demon-add-handler 'gnus-demon-scan-news 5 10)
255 ;(gnus-demon-init)
258 (require 'gnus-notify)
260 (setq gnus-thread-sort-functions
261 '((lambda (t1 t2)
262 (not (gnus-thread-sort-by-date t1 t2)))
263 gnus-thread-sort-by-score))
268 (require 'gnushush)
269 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SMTP
270 (setq message-send-mail-function 'smtpmail-send-it) ; for message/Gnus
271 (setq send-mail-function 'smtpmail-send-it) ; for C-x m, etc.
272 (setq smtpmail-debug-info t)
275 (setq message-cite-function
276 'message-cite-original-without-signature)
277 (setq message-citation-line-function '(lambda()
278 (newline-and-indent)
279 (message-insert-citation-line)
280 (message-goto-body)
284 ;;The message buffer will be killed after sending a message.
285 (setq message-kill-buffer-on-exit t)
287 (setq gnus-gcc-mark-as-read t) ;;automatically mark sent as read
290 ;;(setq gnus-message-archive-group "Sent") ;; Save sent mail, but for nnfolder
291 (setq gnus-posting-styles
292 '((".*"
293 ;; seems smtp internal "return-to/evelop-from" address
294 (name (setq user-full-name "Gaofeng Huang"))
295 (address (setq user-mail-address "Gaofeng.Huang@balliol.ox.ac.uk"))
296 (gcc "Sent") ;; local copy, good for later forward
297 (bcc "")
298 ; (bcc "gfhuang@gmail.com")
300 ("^nntp.*"
301 ;; seems smtp internal "return-to/evelop-from" address
302 (name (setq user-full-name "poppyer"))
303 (address (setq user-mail-address "poppyer@gmail.com"))
304 (gcc "")
305 (bcc "")
307 ((header "Delivered-To" "poppyer@gmail.com")
308 (name (setq user-full-name "poppyer"))
309 (address (setq user-mail-address "poppyer@gmail.com"))
310 (gcc "")
311 (bcc "")
317 ;; CRITICAL for using starttls
318 ;; SMTP is not related to NNTP (newsgroups posting)
319 (setq starttls-use-gnutls nil)
322 ;; (setq smtpmail-default-smtp-server "smtp.ox.ac.uk"
323 ;; smtpmail-smtp-server "smtp.ox.ac.uk"
324 ;; smtpmail-smtp-service 25
325 ;; )
327 (setq smtpmail-starttls-credentials '(("smtp.gmail.com" 25 nil nil))
328 smtpmail-auth-credentials '(("smtp.gmail.com" 25 "poppyer@gmail.com" nil))
329 smtpmail-default-smtp-server "smtp.gmail.com"
330 smtpmail-smtp-server "smtp.gmail.com"
331 smtpmail-smtp-service 25
332 smtpmail-local-domain "yourcompany.com")
334 ;; FOR GMAIL SMTP
336 ;; (setq smtpmail-smtp-server "smtp.gmail.com")
337 ;; (setq smtpmail-smtp-service 587)
338 ;; (setq smtpmail-auth-credentials '(("smtp.gmail.com" 587 "poppyerfs@gmail.com" nil)))
339 ;; (setq smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil)))
342 ;; (defun fs-change-smtp ()
343 ;; "Change the SMTP server according to the current from line."
344 ;; (save-excursion
345 ;; (let ((from
346 ;; (save-restriction
347 ;; (message-narrow-to-headers)
348 ;; (message-fetch-field "from"))))
349 ;; (message "From is `%s', setting `smtpmail-smtp-server' to `%s'"
350 ;; from
351 ;; (cond
352 ;; ((string-match "poppyer" from)
353 ;; (message "Using gmail")
354 ;; (setq user-mail-address "poppyer@gmail.com"
355 ;; user-full-name "poppyer")
356 ;; ;; (setq smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
357 ;; ;; smtpmail-auth-credentials '(("smtp.gmail.com" 587 "poppyer@gmail.com" nil))
358 ;; ;; smtpmail-default-smtp-server "smtp.gmail.com"
359 ;; ;; smtpmail-smtp-server "smtp.gmail.com"
360 ;; ;; smtpmail-smtp-service 587
361 ;; ;; )
362 ;; )
363 ;; (t
364 ;; (setq user-full-name "Gaofeng Huang"
365 ;; user-mail-address "Gaofeng.Huang@balliol.ox.ac.uk")
366 ;; )
367 ;; )
368 ;; )
369 ;; )))
371 ;; (add-hook 'message-send-hook 'fs-change-smtp)
374 ;; The following two aren't completely necessary but may help.
375 ;(setq smtpmail-local-domain "666.com")
376 ;(setq smtpmail-sendto-domain "666.com")
377 ;; If your SMTP server requires a username/password to authenticate, as
378 ;; many do nowadays, set them like this:
379 ;(setq smtpmail-auth-credentials ; or use ~/.authinfo
380 ;;'(("smtp.myserver.myisp.com" 25 "USER@SOMEWHERE" "PASSWORD")))
382 ;; Other possibilities for getting smtpmail to work:
384 ;; If for some reason you need to authenticate using the STARTTLS protocol
385 ;; (don't look into this unless you know what it is), use
386 ;; (setq smtpmail-starttls-credentials
387 ;; '(("YOUR SMTP HOST" 25 "~/.my_smtp_tls.key" "~/.my_smtp_tls.cert")))
388 ;; Requires external program
389 ;; ftp://ftp.opaopa.org/pub/elisp/starttls-*.tar.gz.
390 ;; See http://www.ietf.org/rfc/rfc2246.txt,
391 ;; http://www.ietf.org/rfc/rfc2487.txt
392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;nntp news group;;;;;;;;;;;;;;
396 ;;(add-to-list 'gnus-secondary-select-methods
397 ;; '(nntp "news.cn99.com")) ;; no posting allowed
398 ;; '(nntp "freenews.netfront.net")) ;; to slow
400 ;; (defun set-timeout-5()
401 ;; (setq nntp-connection-timeout nil)
402 ;; )
403 ;; ;; (add-hook 'nntp-server-opened-hook 'set-timeout-5) ;; seems no use, even the hook it self will be reset???
404 ;; ;; (add-hook 'gnus-after-getting-new-news-hook 'set-timeout-5)
405 ;; ;;(add-hook 'gnus-after-getting-new-news-hook 'nntp-close-server)
406 ;; ;;(add-hook 'gnus-started-hook 'nntp-close-server)
408 (set 'gnus-secondary-select-methods
410 (nntp "freenews.netfront.net") ;; missing cn.bbs.comp.emacs
411 (nntp "news.cnusenet.org") ;; sync very slow
412 ;; (nntp "news.mixmin.net") ;; no posting
414 ;; (add-to-list 'gnus-secondary-select-methods '(nntp ))
418 ;; (add-to-list 'gnus-secondary-select-methods
419 ;; ;; '(nntp "freenews.netfront.net"
420 ;; ;; '(nntp "news.yakoo.com"
421 ;; '(nntp "happynet"
422 ;; (nntp-address "news.happynet.org")
423 ;; (nntp-via-user-name "poppyer")
424 ;; (nntp-via-address "fedora.unix-center.net")
425 ;; (nntp-via-rlogin-command "ssh")
426 ;; (nntp-end-of-line "\n")
427 ;; (nntp-via-rlogin-command-switches ("-C" "-t" "-e" "none"))
428 ;; (nntp-open-connection-function nntp-open-via-rlogin-and-telnet)
429 ;; ))
431 ;;freenews.maxbaud.net can search for groups
432 ;; use ^ (server) to list a server
435 ;; no need, put it in ~/News/all.SCORE
436 ;;(setq gnus-global-score-files '("~/all.SCORE"))
439 ;; show To rather than From when it is from myself
440 (setq gnus-extra-headers '(To Newsgroups X-Oxmail-Spam-Level))
441 (setq nnmail-extra-headers gnus-extra-headers)
442 (setq gnus-ignored-from-addresses "poppyer\\|Gaofeng")
444 ;; show its encoding such that use 1 g to manually set encoding
445 (require 'gnus-art)
446 (add-hook 'gnus-startup-hook
447 '(lambda ()
448 (setq gnus-visible-headers
449 (concat "^User-Agent:\\|^Content-Type:\\|"
450 "^X-mailer:\\|^X-Newsreader:\\|^X-Sender:\\|"
451 "^Disposition-Notification-To:\\|"
452 gnus-visible-headers))))
455 ;; encoding related
456 ;;(setq gnus-default-charset 'gb2312) ;; each group has its own default
457 (setq gnus-group-charset-alist
458 '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" big5)
459 ("^cn\\>\\|\\<chinese\\>" gb2312)
460 ("^fj\\>\\|^japan\\>" iso-2022-jp-2)
461 ("^tnn\\>\\|^pin\\>\\|^sci.lang.japan" iso-2022-7bit)
462 ("^relcom\\>" koi8-r)
463 ("^fido7\\>" koi8-r)
464 ("^\\(cz\\|hun\\|pl\\|sk\\|hr\\)\\>" iso-8859-2)
465 ("^israel\\>" iso-8859-1)
466 ("^han\\>" euc-kr)
467 ("^alt.chinese.text.big5\\>" chinese-big5)
468 ("^soc.culture.vietnamese\\>" vietnamese-viqr)
469 ("^\\(comp\\|rec\\|alt\\|sci\\|soc\\|news\\|gnu\\|bofh\\)\\>" iso-8859-1)
470 (".*" gb2312)))
472 ;;(setq gnus-default-posting-charset 'utf-8)
473 (setq gnus-newsgroup-ignored-charsets
474 '(unknown-8bit x-unknown x-gbk gb18030 gbk big5)) ;; ignore big5 for cn.bbs.soc.taiwan
475 ;; send mail encoding priorities; alias not work, use decscribe-coding-system to check
476 (setq mm-coding-system-priorities '(iso-8859-1 chinese-iso-8bit chinese-big5 utf-8))
477 (setq gnus-summary-show-article-charset-alist
478 '((1 . gb2312)
479 (2 . big5)
480 (3 . gbk))
481 ;; '((1 . utf-8)
482 ;; (2 . big5)
483 ;; (3 . gbk)
484 ;; (4 . utf-7))
488 (defalias 'mail-header-encode-parameter 'rfc2047-encode-parameter) ;; for chinese name attachment