- (let ((styles gnus-posting-styles)
- (gnus-newsgroup-name (or gnus-newsgroup-name ""))
- style match variable attribute value value-value)
- ;; Go through all styles and look for matches.
- (while styles
- (setq style (pop styles)
- match (pop style))
- (when (cond ((stringp match)
- ;; Regexp string match on the group name.
- (string-match match gnus-newsgroup-name))
- ((or (symbolp match)
- (gnus-functionp match))
- (cond ((gnus-functionp match)
- ;; Function to be called.
- (funcall match))
- ((boundp match)
- ;; Variable to be checked.
- (symbol-value match))))
- ((listp match)
- ;; This is a form to be evaled.
- (eval match)))
- ;; We have a match, so we set the variables.
- (while style
- (setq attribute (pop style)
- value (cadr attribute)
- variable nil)
- ;; We find the variable that is to be modified.
- (if (and (not (stringp (car attribute)))
- (not (setq variable (cdr (assq (car attribute)
- gnus-posting-style-alist)))))
- (message "Couldn't find attribute %s" (car attribute))
- ;; We get the value.
- (setq value-value
- (cond ((stringp value)
- value)
- ((or (symbolp value)
- (gnus-functionp value))
- (cond ((gnus-functionp value)
- (funcall value))
- ((boundp value)
- (symbol-value value))))
- ((listp value)
- (eval value))))
- (if variable
- (progn
- ;; This is an ordinary variable.
- (make-local-variable variable)
- (set variable value-value))
- ;; This is a header to be added to the headers when
- ;; posting.
- (when value-value
- (make-local-variable message-required-mail-headers)
- (make-local-variable message-required-news-headers)
- (push (cons (car attribute) value-value)
- message-required-mail-headers)
- (push (cons (car attribute) value-value)
- message-required-news-headers)))))))))
+ (unless gnus-inhibit-posting-styles
+ (let ((group (or group-name gnus-newsgroup-name ""))
+ (styles gnus-posting-styles)
+ style match attribute results
+ name address)
+ ;; If the group has a posting-style parameter, add it at the end with a
+ ;; regexp matching everything, to be sure it takes precedence over all
+ ;; the others.
+ (when gnus-newsgroup-name
+ (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
+ (when tmp-style
+ (setq styles (append styles (list (cons ".*" tmp-style)))))))
+ ;; Go through all styles and look for matches.
+ (dolist (style styles)
+ (setq match (pop style))
+ (goto-char (point-min))
+ (when (cond
+ ((stringp match)
+ ;; Regexp string match on the group name.
+ (string-match match group))
+ ((eq match 'header)
+ ;; Obsolete format of header match.
+ (and (gnus-buffer-live-p gnus-article-copy)
+ (with-current-buffer gnus-article-copy
+ (save-restriction
+ (nnheader-narrow-to-headers)
+ (let ((header (message-fetch-field (pop style))))
+ (and header
+ (string-match (pop style) header)))))))
+ ((or (symbolp match)
+ (functionp match))
+ (cond
+ ((functionp match)
+ ;; Function to be called.
+ (funcall match))
+ ((boundp match)
+ ;; Variable to be checked.
+ (symbol-value match))))
+ ((listp match)
+ (cond
+ ((eq (car match) 'header)
+ ;; New format of header match.
+ (and (gnus-buffer-live-p gnus-article-copy)
+ (with-current-buffer gnus-article-copy
+ (save-restriction
+ (nnheader-narrow-to-headers)
+ (let ((header (message-fetch-field (nth 1 match))))
+ (and header
+ (string-match (nth 2 match) header)))))))
+ (t
+ ;; This is a form to be evaled.
+ (eval match)))))
+ ;; We have a match, so we set the variables.
+ (setq style (gnus-configure-posting-style style nil))
+ (dolist (attribute style)
+ (setq results (delq (assoc (car attribute) results) results))
+ (push attribute results))))
+ ;; Now we have all the styles, so we insert them.
+ (setq name (assq 'name results)
+ address (assq 'address results))
+ (setq results (delq name (delq address results)))
+ (gnus-make-local-hook 'message-setup-hook)
+ (setq results (sort results (lambda (x y)
+ (string-lessp (car x) (car y)))))
+ (dolist (result results)
+ (add-hook 'message-setup-hook
+ (cond
+ ((eq 'eval (car result))
+ 'ignore)
+ ((eq 'body (car result))
+ `(lambda ()
+ (save-excursion
+ (message-goto-body)
+ (insert ,(cdr result)))))
+ ((eq 'signature (car result))
+ (set (make-local-variable 'message-signature) nil)
+ (set (make-local-variable 'message-signature-file) nil)
+ (if (not (cdr result))
+ 'ignore
+ `(lambda ()
+ (save-excursion
+ (let ((message-signature ,(cdr result)))
+ (when message-signature
+ (message-insert-signature)))))))
+ (t
+ (let ((header
+ (if (symbolp (car result))
+ (capitalize (symbol-name (car result)))
+ (car result))))
+ `(lambda ()
+ (save-excursion
+ (message-remove-header ,header)
+ (let ((value ,(cdr result)))
+ (when value
+ (message-goto-eoh)
+ (insert ,header ": " value)
+ (unless (bolp)
+ (insert "\n")))))))))
+ nil 'local))
+ (when (or name address)
+ (add-hook 'message-setup-hook
+ `(lambda ()
+ (set (make-local-variable 'user-mail-address)
+ ,(or (cdr address) user-mail-address))
+ (let ((user-full-name ,(or (cdr name) (user-full-name)))
+ (user-mail-address
+ ,(or (cdr address) user-mail-address)))
+ (save-excursion
+ (message-remove-header "From")
+ (message-goto-eoh)
+ (insert "From: " (message-make-from) "\n"))))
+ nil 'local)))))
+
+;; splitted from gnus-configure-posting-styles to allow recursive traversal.
+(defun gnus-configure-posting-style (style stack)
+ "Parse one posting style STYLE and returns the value as an alist."
+ (let (results element variable filep value v)
+ (dolist (attribute style)
+ (setq element (pop attribute)
+ variable nil
+ filep nil)
+ (setq value
+ (cond
+ ((eq (car attribute) ':file)
+ (setq filep t)
+ (cadr attribute))
+ ((eq (car attribute) :value)
+ (cadr attribute))
+ (t
+ (car attribute))))
+ ;; We get the value.
+ (setq v
+ (cond
+ ((stringp value)
+ value)
+ ((or (symbolp value)
+ (functionp value))
+ (cond ((functionp value)
+ (funcall value))
+ ((boundp value)
+ (symbol-value value))))
+ ((listp value)
+ (eval value))))
+ ;; Translate obsolescent value.
+ (cond
+ ((eq element 'signature-file)
+ (setq element 'signature
+ filep t))
+ ((eq element 'x-face-file)
+ (setq element 'x-face
+ filep t)))
+ ;; Get the contents of file elems.
+ (when (and filep v)
+ (setq v (with-temp-buffer
+ (insert-file-contents v)
+ (buffer-substring (point-min)
+ (progn
+ (goto-char (point-max))
+ (if (zerop (skip-chars-backward "\n"))
+ (point)
+ (1+ (point))))))))
+ (if (eq element 'import)
+ (progn
+ (if (member v stack)
+ (error "Circular import of \"%s\"" v))
+ (setq results
+ (nconc (nreverse (gnus-configure-posting-style
+ (cdr (assoc v gnus-named-posting-styles))
+ (cons v stack)))
+ results)))
+ (push (cons element v) results)))
+ (nreverse results)))
+
+(defun gnus-summary-execute-command-with-posting-style (style command)
+ "Temporarily select a posting-style named STYLE and execute COMMAND."
+ (interactive
+ (let ((style (completing-read "Posting style: "
+ gnus-named-posting-styles nil t)))
+ (list style
+ (key-binding
+ (read-key-sequence
+ (format "Command to execute with %s: " style))))))
+ (let ((gnus-posting-styles (list (list ".*" (list 'import style)))))
+ (call-interactively command)))
+
+
+;;; @ for MIME Edit mode
+;;;
+
+(defun gnus-maybe-setup-default-charset ()
+ (let ((charset
+ (and (boundp 'gnus-summary-buffer)
+ (buffer-live-p gnus-summary-buffer)
+ (save-excursion
+ (set-buffer gnus-summary-buffer)
+ default-mime-charset))))
+ (if charset
+ (progn
+ (make-local-variable 'default-mime-charset)
+ (setq default-mime-charset charset)
+ ))))
+
+
+;;; @ for MIME view mode
+;;;
+
+(defun gnus-following-method (buf)
+ (gnus-setup-message 'reply-yank
+ (set-buffer buf)
+ (if (message-news-p)
+ (message-followup)
+ (message-reply nil 'wide))
+ (let ((message-reply-buffer buf))
+ (message-yank-original))
+ (message-goto-body))
+ (kill-buffer buf))
+