How to fix Gnus 'Warning - invalid active [folder] [number] [number] y'? - emacs

Something I've done but not yet identified has hosed my working-for-years Gnus<->offlineimap<->GMail setup. Gnus gives me a bunch of errors like:
Warning - invalid active: [Gmail].Starred 26 2 y
for each of the 8 standard GMail folders being synced (Sent, Important, Trash, Spam, All Mail, Bin, Starred, and Drafts) and presents a *Group* buffer consisting of nothing but:
4: nndraft:drafts
instead of the dozens of subscribed groups (mail folders) I expect to see.
I find no relevant matches for 'invalid' in the Gnus manual, nor anything in multiple web searches.
One piece of context: after this first happened, I checked my offlineimap logs and found there were a lot of folder UID errors, so I completely rebuilt my offlineimap local repo from scratch, which took almost 48 hours.
Possibly relevant Gnus user options:
'(gnus-article-sort-functions
(quote
((not gnus-article-sort-by-number))))
'(gnus-check-new-newsgroups nil)
'(gnus-extract-address-components
(quote mail-extract-address-components))
'(gnus-home-directory "~/.emacs.d/gnus/")
'(gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
'(gnus-init-file "~/.emacs.d/.gnus.el")
'(gnus-large-newsgroup nil)
'(gnus-parameters
(quote
((".*"
(visible . t))
("INBOX"
(display . 75))
("All Mail"
(display . 75)))))
'(gnus-read-active-file nil)
'(gnus-read-newsrc-file nil)
'(gnus-save-killed-list nil)
'(gnus-save-newsrc-file nil)
'(gnus-select-method
(quote
(nnmaildir "GMail"
(directory "~/GMail/")
(directory-files nnheader-directory-files-safe)
(get-new-mail nil))))
'(gnus-started-hook
(quote
(ph/gnus-redisplay-groups ph/setup-bbdb)))
'(gnus-startup-hook
(quote
(bbdb-insinuate-gnus)))
'(gnus-subscribe-newsgroup-method
(quote gnus-subscribe-alphabetically))
'(gnus-thread-sort-functions
(quote
((not gnus-thread-sort-by-number)
(not gnus-thread-sort-by-date))))
'(gnus-use-scoring nil)
Edit: gnus-version is "Gnus v5.13" and emacs-version is "24.5.1"

Related

mu4e reply from the correct account

I have several accounts associated with mu4e and I can both receive and send - using smtpmail-multi - from all them without problems. I am not using contexts. The relevant parts in my configuration look like this:
(setq message-citation-line-function 'message-insert-formatted-citation-line)
(setq message-citation-line-format "On %a, %b %d %Y, %f wrote:\n")
(setq smtpmail-multi-accounts
(quote
((yahoo . ("xxxx#yahoo.com"
"smtp.mail.yahoo.com"
587
"xxxxx#yahoo.com"
nil nil nil nil))
(other . ("xxxxx#other.com"
"smtp.other.com"
465
"xxxx#other.com"
ssl nil nil nil))
(etc . ("xx#etc.com"
"smtp.etc.com"
465
"xx#etc.com"
ssl nil nil nil))
;; ...
)))
(setq smtpmail-multi-associations
(quote
(("xxxx#yahoo.com" yahoo)
("xxx#other.com" other)
("xx#etc.com" etc)
;; ....
)))
(setq smtpmail-multi-default-account (quote yahoo))
(setq message-send-mail-function 'smtpmail-multi-send-it)
(setq mu4e-compose-dont-reply-to-self t)
(setq mu4e-user-mail-address-list '("xxxx#yahoo.com"
"xxx#other.com"
"xx#etc.com"
;; ...
))
(setq user-full-name "XXXXXX")
(setq user-mail-address "xxx#other.com")
This way I can properly send emails from the right account just by typing the address of my email in the FROM: field.
When replying, I want mu4e to identify the account to which the message has been send and update FROM: field accordingly so that I don't have to type in the proper account all the time myself. I am looking for a way to do this without having to upgrade my entire configuration to using contexts.
After a lot of tweaking I came up with this:
(defun my-mu4e-set-account ()
"Set the account for composing a message."
(if mu4e-compose-parent-message
(let ((mail (cdr (car (mu4e-message-field mu4e-compose-parent-message :to)))))
(if (member mail mu4e-user-mail-address-list)
(setq user-mail-address mail)
(setq user-mail-address "my#default.account")))
(helm :sources
`((name . "Select account: ")
(candidates . mu4e-user-mail-address-list)
(action . (lambda (candidate) (setq user-mail-address candidate)))))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
where mu4e-user-mail-address-list is, obviously, a list with my mail accounts
This will reply with the proper account and, more, will open a helm mini menu asking me which account to use every time I compose a new message.
I know that this blog post has a multi account setup that automatically picks up the FROM field. Might want to take a look at it. Mu4e is on my todo list so I can't give you a direct answer.

Default Archive Group in Gnus

I am using the following code to archive replies to messages in the same group they come from; it works well.
;; Store sent messages in the same group they came from
(setq gnus-message-archive-method '(nnml ""))
(setq gnus-message-archive-group
'((lambda (x)
(cond
;; Store personal mail messages in the same group I started out in
((string-match ".*" group) group)
;; Store everything else in misc until I can sort it out
(t "mail.misc")))))
However, if I use C-x m from a non-GNUs buffer, or create a message without a group selected, there seems to be no archiving at all; the message is lost unless I manually fill in a GCC: mail.misc line. How can I make this happen automatically for all messages not made from within a group?
First you have to set gnus as mail handler.
(setq mail-user-agent 'gnus-user-agent)
Still this doesn't work, if gnus is not running when starting to
write a mail with C-x m. Here a advice helps.
(defadvice gnus-msg-mail (before start-gnus activate)
(require 'gnus-start)
(unless (gnus-alive-p)
(save-window-excursion
(let ((inhibit-redisplay t))
(gnus)))))

Gnus: How to force signature to be placed at the bottom/under quoted messages in replies?

I use Gnus 5.13 for emails (on Mac OS X 10.7.2 with emacs 24). I use the gnus-posting-styles entry (eval (set (make-local-variable 'message-cite-reply-position) 'above)) in order to place the point (cursor) on top of the message in replies. This allows me to either top-reply or to reply inline (between the message that I would like to reply to). Unfortunately, the above entry also puts my signature on top of the message I would like to reply to. That's okay if I want to top-reply, but it's wrong if I want to reply inline. How can I force the signature to be placed under the message I reply to?
Discarding the 'message-cite-reply-position' modification, I have added the following to my .gnus.el file, and now when replying to an e-mail or news post, first goes the yanked message, then my signature, and the point is placed at the beginning of the message.
(eval-after-load "gnus-msg"
'(defun gnus-inews-yank-articles (articles)
(let (beg article yank-string)
(message-goto-body)
(while (setq article (pop articles))
(when (listp article)
(setq yank-string (nth 1 article)
article (nth 0 article)))
(save-window-excursion
(set-buffer gnus-summary-buffer)
(gnus-summary-select-article nil nil nil article)
(gnus-summary-remove-process-mark article))
(gnus-copy-article-buffer nil yank-string)
(let ((message-reply-buffer gnus-article-copy)
(message-reply-headers
;; The headers are decoded.
(with-current-buffer gnus-article-copy
(save-restriction
(nnheader-narrow-to-headers)
(nnheader-parse-naked-head)))))
(message-yank-original)
(setq beg (or beg (mark t))))
(when articles
(insert "\n")))
(push-mark)
; (goto-char beg))) -- Original
(message-goto-body) ; -- Modified, so point will be moved to beginning of article
(insert "\n\n") ; -- and two empty lines will be added.
(message-goto-body)))) ; --

Gnus: How to save *all* attachments at once?

I would like to save all attachments to an email at once. I therefore set gnus-summary-save-parts-default-mime to ".* /.*". However, when using "X m", I not only get all attachments, but also a file named "nnimap+my.name#googlemail.com/INBOX.2393.1" (referring to the account I'm reading emails from) which contains the signature of the email I received. How can I exclude files of this "type" from being saved on "X m"? In other words: How can I specify the correct regexp for gnus-summary-save-parts-default-mime to prevent this file from being saved, too?
This defadvice will do what you want for the moment by excluding any parts that do not have filenames (in this case that is true of the article itself):
(defadvice gnus-summary-save-parts-1 (around gnus-summary-save-parts-exclude-self activate)
(let ((handle (ad-get-arg 2)))
(unless (and (not (stringp (car handle)))
(not (mm-handle-filename handle)))
ad-do-it)))
I am using Gnus v5.13; if you're also using the same or similar version, let me know if this modified version of gnus-summary-save-parts-1 works for you; you will want to set gnus-summary-save-parts-exclude-article to t. If it works for you, I will submit a patch for it to the Gnus projects.
Note, either use the above defadvice OR use the code below, but do not use both together. The defadvice is an easy quick fix that you can use for the moment. The code below I will submit as a patch to the Gnus project and I only included this here for you to test to see if it works on your system if you are also using Gnus v5.13. If they accept this patch and make it part of a future release then you will not need the defadvice above; instead you'll just be able to customize the gnus-summary-save-parts-exclude-article variable.
(require 'gnus)
(require 'gnus-sum)
(defcustom gnus-summary-save-parts-exclude-article nil
"If non-nil don't save article along with attachments."
:group 'gnus-article-mime
:type 'boolean)
(defun gnus-summary-save-parts-1 (type dir handle reverse)
(if (stringp (car handle))
(mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
(cdr handle))
(when (if reverse
(not (string-match type (mm-handle-media-type handle)))
(string-match type (mm-handle-media-type handle)))
(let* ((name (or
(mm-handle-filename handle)
(unless gnus-summary-save-parts-exclude-article
(format "%s.%d.%d" gnus-newsgroup-name
(cdr gnus-article-current)
gnus-summary-save-parts-counter))))
(file (when name
(expand-file-name
(gnus-map-function
mm-file-name-rewrite-functions
(file-name-nondirectory
name))
dir))))
(when file
(incf gnus-summary-save-parts-counter)
(unless (file-exists-p file)
(mm-save-part-to-file handle file)))))))

How to advise primitives in Emacs

I was trying to answer another SO question when I hit upon some very odd behavior. Here's my little test case:
(make-variable-buffer-local
(defvar my-override-mode-on-save nil
"Can be set to automatically ignore read-only mode of a file when saving."))
(defadvice file-writable-p (around my-overide-file-writeable-p act)
"override file-writable-p if `my-override-mode-on-save' is set."
(or
my-override-mode-on-save
ad-do-it))
(defun my-override-toggle-read-only ()
"Toggle buffer's read-only status, keeping `my-override-mode-on-save' in sync."
(interactive)
(setq my-override-mode-on-save (not my-override-mode-on-save))
(toggle-read-only))
(defun tester-fn ()
(interactive)
(let ((xxx (file-writable-p "/tmp/foofoo"))
(yyy (file-writable-p "/tmp/fooxxfoo")))
(message (concat "XXX: " (if xxx "yes" "no") " - YYY: " (if yyy "yes" "no")))))
where:
/tmp/foofoo is a read-only file that I've visited and run my-override-toggle-read-only in.
/tmp/fooxxfoo does not exist.
/tmp is writable by the user I'm logged in as.
If I run tester-fn in a buffer where my-override-mode-on-save is set to t then I get an unexpected result: XXX: no - YYY: no. If I run tester-fn while in some other buffer (e.g. scratch) I get the expected response in the minibuffer: XXX: no - YYY: yes. Tracing the advice through the debugger shows it to be doing exactly what I think it should be doing, executing the parts I expect it to, skipping the parts I expect it to, returning the value I expect it to. However, tracing tester-fn through the debugger shows very different values being returned (nil & t if the variable evaluates as nil, nil & nil if the variable evaluates as non-nil). The nil & nil return is really what I find bizarre.
I have no clue what's happening here. Anyone know why I'm not getting the results I expect?
Your code looks good, except the one missing key. You need to set the return value appropriately:
(defadvice file-writable-p (around my-overide-file-writeable-p act)
"override file-writable-p if `my-override-mode-on-save' is set."
(setq ad-return-value
(or
my-override-mode-on-save
ad-do-it)))
This is documented in the advice manual.