;;
;; dot-gnus-articles.el --- Single-article stuff for Gnus.
;;

;; Article buffer options

; Don't let me be stupid.

(setq gnus-confirm-mail-reply-to-news t)

; Make the articles flashy.

(setq gnus-treat-buttonize 100000                ; Buttonize short-enough articles
      gnus-treat-buttonize-head 'head            ; Always buttonize the header
      gnus-treat-body-boundary nil
      gnus-treat-capitalize-sentences nil
      gnus-treat-date-local 'head                ; Date in the local timezone
      gnus-treat-from-picon 'head                ; Little piccies, locally stored
      gnus-treat-mail-picon 'head
      gnus-treat-newsgroups-picon 'head
      gnus-treat-display-smileys nil
      gnus-treat-display-x-face 'head            ; A remotely stored picon
      gnus-treat-display-face 'head              ; Likewise
      gnus-treat-emphasize 100000                ; Bold text &c
      gnus-treat-fill-article nil
      gnus-treat-fill-long-lines nil             ; Great idea, but... no.
      gnus-treat-hide-boring-headers 'head       ; Ignore tautologous headers
      gnus-treat-hide-headers 'head
      gnus-treat-strip-headers-in-body t
      gnus-treat-strip-list-identifiers t
      gnus-treat-strip-trailing-blank-lines t
      gnus-treat-x-pgp-sig t
      browse-url-browser-function 'w3m-browse-url  ; Use a decent web browser
      gnus-article-prepare-hook '(gnus-article-hide-list-identifiers)
      gnus-part-display-hook nil ; '(gnus-article-outlook-deuglify-article) when it works, which isn't yet
      gnus-article-skip-boring t                 ; don't show us pages of quoted context and signature
      gnus-list-identifiers "\\[airstrike\\] ")

;; Mess with headers; hide the really boring crap, cater for automoderated
;; groups like adn and the Monastery.

(setq gnus-visible-headers nil                 ; I *like* headers
      gnus-ignored-headers (concat "^Path: \\|^Expires: \\|^Date-Received: \\|^References: \\|"
                                   "^Xref: \\|^Lines: \\|^Message-ID: \\|^Sender: \\|"
                                   "^Received: \\|^X-Gateway-Received: \\|"
                                   "^X-Habeas-Swe-[0-9]*: \\|^X-Envelope-Sender: \\|"
                                   "^Return-Path: \\|"
                                   "^X-Spam-Checker-Version: \\|^X-Face: \\|^Face: \\|"
                                   "^List-[A-Z][a-z]*: \\|^X-Spam-Report: \\|"
                                   "^Received-SPF: \\|^X-Virus-\\(Scanned\\|Status\\): \\|"
                                   "^Mailing-List: \\|^Delivered-To: \\|"
                                   "^In-Reply-To: \\|^X-Spam-Check-By: \\|"
                                   "^X-ASF-Spam-Status: \\|^X-VirusScan: \\|"
                                   "^X-Virus-Checked: \\|MIME-Version: \\|"
                                   "^X-AntiAbuse: \\|X-O-.*: \\|^Precedence: \\|"
                                   "^X-Bugzilla-.*: \\|^DomainKey-Signature: \\|^DKIM-Signature: ")
      gnus-ignored-from-addresses (regexp-opt '("Nix <$}xinix{$@esperi.org.uk>"
                                                "Nix <nix@esperi.org.uk>"
                                                "Nick Alcock <nick.alcock@esperi.org.uk>"
                                                "Nick Alcock <nick.alcock@oracle.com>"
                                                "$}xinix{$@esperi.org.uk"
                                                "nix@esperi.org.uk"
                                                "nick.alcock@esperi.org.uk"))
      gnus-posting-styles '(((or (string= "alt.sysadmin.recovery" gnus-newsgroup-name)
                                 (string= "alt.dev.null" gnus-newsgroup-name))
                             ("Approved" "foo"))

;; Use a different email address for news, as an anti-spam hack, and a different
;; reply-to (likewise).

                            ((message-news-p)
                             (address "nix-razor-pit@esperi.org.uk")
                             (Reply-To "Nix <$}xinix{$@esperi.org.uk>"))
                            ((nix-at-work-p)
                             (name "Nick Alcock")
                             (address "nick.alcock@esperi.org.uk")))) ;; TODO: change to @oracle.com when that works and is forwarded appropriately
;                           ("nnml:.*"
;                            (From (concat "Nix <"
;                                          (save-excursion
;                                            (set-buffer gnus-article-buffer)
;                                            (message-fetch-field "to"))
;                                          ">")))))

;; Sort the headers into order.

(setq gnus-sorted-header-list (quote ("^From: " "^Subject: " "^Summary: " "^Keywords: " "^Newsgroups: " "^Followup-To: "
                                      "^Approved: " "^To: " "^Cc: " "^Date: " "^Organization: " "^Approved: ")))

;; Cite properly, using TrivialCite.

(setq message-cite-function 'trivial-cite
      tc-normal-citemarks ">|:"
      tc-fill-column nil
      tc-make-attribution 'tc-fancy-attribution
      tc-normalize-cite-marks nil
      tc-groups-functions '(("alt.sysadmin.recovery" . nix-tc-bofh-group-attributor)
                            ("bofh." . nix-tc-bofh-group-attributor)))

(defvar tc-generic-attributions
  '("stated" "spake" "uttered the following" "moaned" "said" "stipulated" "yowled" "mused" "wrote"
    "suggested tentatively" "murmured woefully" "prattled cheerily" "whispered secretively"
    "announced authoritatively" "gibbered uncontrollably")
  "Generic attribution tails; see `tc-generate-attribution'.
An attribution tail may be a string, or a function to call
to generate the attribution: the function is called with
two arguments, a date and a name.")

(defvar tc-bofh-attributions
  (append tc-generic-attributions '("spread salacious rumours"
                                    "muttered drunkenly"
                                    "mumbled shiftily"
                                    "cackled terrifyingly"
                                    "pondered drearily"
                                    "warbled tunelessly"
                                    (lambda (date name)
                                      (concat "Chewing on a haunch of luser, " name " stated:"))))
  "Attribution tails for BOFH newsgroups; see `tc-generate-attribution'.
An attribution tail may be a string, or a function to call
to generate the attribution: the function is called with
two arguments, a date and a name.")

(defvar tc-at-work-attributions '("said")
  "Boring attribution tail used while at work.")

(defun tc-generate-attributor (date name &optional attributions)
  "Generate random attribution for NAME on DATE with the ATTRIBUTIONS list.
If ATTRIBUTIONS is nil, `tc-generic-attributions' is used."
  (let* ((attributions (or attributions tc-generic-attributions))
         (att (nth (random (length attributions)) attributions)))
    (if (functionp att)
        (funcall att date name)
      (concat "On " date ", " name " " att ":"))))

(defun tc-generic-attributor (date name)
  "Generate a attribution suitable for any context."
  (if (not (nix-at-work-p))
      (tc-generate-attributor date name)
    (tc-generate-attributor date name tc-at-work-attributions)))

(defun nix-tc-bofh-group-attributor (date name)
  "Generate a attribution suitable for a bunch of bastards."
  (tc-generate-attribution date name tc-bofh-attributions))

(provide 'dot-gnus-articles)