;; -*- emacs-lisp -*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; $Id: gnus_styles.el,v 1.28 2006-11-06 21:02:42 rscholz Exp $
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Posting Styles
;;
;; Die offizielle Quelle dieser Datei ist
;;   <http://www.zonix.de/projects/emacs/config>
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Abhängig von der Newsgroup oder der Mailingliste lassen sich
;; Eigenschaften einstellen, die ein Newsposting oder eine Mail haben
;; soll.  Dies können z.B. die Absenderadresse, die Signatur etc. sein.

;; Ich habe mir einige eigene Variablen und Funktionen definiert, die
;; ich in den Posting-Styles verwende.

(defvar zonix-trusted-groups
  "^\\(nn.*:\\(INBOX\\.\\)?list\\.\\(uni\\|jahrgang\\|heimat123\\|gnus\\|toh\\|dafhs\\)\\)\\|fb3\\.\\|stuga\\."

  "Vertrauenswürdige Gruppen, in denen ich mit meiner richtigen
  Emailadresse poste.")

(defvar zonix-german-groups
  "^\\(nn.*:\\(INBOX\\.\\)?list\\.\\(uni\\|dafhs\\|jahrgang\\|heimat123\\.de\\)\\|de\\.\\|fb3\\.\\|stuga\\.\\)"
  
  "Deutschsprachige Gruppen.")

(defvar zonix-spoiler-groups
  "^nntp:de\\.rec\\.\\(film\\|tv\\)\\.\\(misc\\|serien\\)"

  "Gruppen, in denen Spoiler verwendet werden." )

;; gibt X-Face als String zurueck (Dank an Kai G.), ab Gnus 5.10 nicht mehr benötigt, s.u.
(defun zonix-insert-x-face ()
  (with-temp-buffer
    (insert-file-contents "~/el/xfaces/default")
    (buffer-string)))

;; von Dirk Meyer, leicht abgeändert
(defun dischi/gnus-message-rot-on-spoiler ()
  (if (and (string-match zonix-spoiler-groups gnus-newsgroup-name)
           (string-match "\\[[Ss]poiler\\]" (message-fetch-field "subject")))
      (gnus-summary-caesar-message)))

(add-hook 'gnus-article-prepare-hook 'dischi/gnus-message-rot-on-spoiler)

;; Default-Mailadresse
(setq user-mail-address (concat "rscholz@" ;; spam trap
                                "zonix.de"))



;; Oliver Scholz in <usmszj3y8.fsf@ID-87814.user.dfncis.de>
;; From-Adresse aus To-Header ableiten

;; erlaubte Adressen
(setq egoge-mail-addresses
      (list "rscholz@...." 
            "r@..."
            "rscholz@...."))

(defun egoge-message-get-from-address ()
  (save-excursion
    (set-buffer gnus-article-buffer)
    (let ((address (message-fetch-field "to")))
      (if (and address (string-match (regexp-opt egoge-mail-addresses)
                                     address))
          (concat user-full-name " <" 
                  (match-string 0 address)
                  ">")
        (concat user-full-name " <" user-mail-address ">")))))

;; dann in posting styles: (from (egoge-message-get-from-address))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Posting Styles                (Info-goto-node "(Gnus)Posting Styles")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq gnus-posting-styles
      '(

        ;; Default
        (".*"
         (address (concat "rscholz@" ;;; spam trap
                          "zonix.de"))

         ;; guess what...
;        (organization "=?UTF-8?Q?/=CB=8C=C9=94=CB=90=C9=A1=C9=99na=C9=AA=CB=88ze=C9=AA=CA=83n/?=")
         (organization (rfc2047-decode-string "=?UTF-8?Q?/=CB=8C=C9=94=CB=90=C9=A1=C9=99na=C9=AA=CB=88ze=C9=AA=CA=83n/?="))

         ;; Face-Header ab Gnus 5.10 <http://quimby.gnus.org/circus/face/>
;        ("Face" (gnus-face-from-file (expand-file-name "~/reitz1.jpg")))
         
         (eval (ispell-change-dictionary zonix-german-ispell-dictionary))
;        (eval (setq message-citation-line-function 'message-insert-citation-line-de))
         (eval (setq mw/rs-tc-verb "schrieb"))
         (eval (setq mw/rs-tc-anon "Ein anonymer Feigling"))
         (body "\nGrüße, Ray")

;;       (body (with-temp-buffer 
;;               (insert-file-contents "foo.txt")
;;               (buffer-string)))

         (eval (setq randomsig-static-string nil))
         (eval (setq randomsig-files 'randomsig-search-sigfiles))
         (eval (setq randomsig-dir "~/el/sigs/")))

        ;; Sprache
        ((or
          
          ;; nicht deutschsprachige Gruppen
          (and (message-news-p)
               (not (string-match zonix-german-groups (zonix-get-group-name))))

          ;; nicht deutschsprachige Listen
          (and (message-mail-p)
               (or (string-match "^nn.*:\\(INBOX\\.\\)?list\\." (zonix-get-group-name))
                   (string-match "^\\(nn.*\\)?gmane\\." (zonix-get-group-name))
                   (string-match "^nnvirtual:" (zonix-get-group-name)))
               (not (string-match zonix-german-groups (zonix-get-group-name)))))

         (eval (ispell-change-dictionary "british"))
;        (eval (setq message-citation-line-function 'message-insert-citation-line))
         (eval (setq mw/rs-tc-verb "writes"))
         (eval (setq mw/rs-tc-anon "Anonymous coward"))
         (body "\nCheers, Ray")

         )

        ;; Standard-Signaturen
        ((message-mail-p)
         (signature (randomsig-signature "mail/zonix")))

        ;; Mail und aus Mail-Gruppe aber keiner Liste
        ((and (message-mail-p)
              (string-match "^nn" (zonix-get-group-name))
              (not (string-match "^nn.*:\\(INBOX\\.\\)?list\\." (zonix-get-group-name))))
         ("X-Message-Source" (concat "hostname " (gnus-group-real-name (zonix-get-group-name)))))

        ((message-news-p)
         (signature (randomsig-signature "news/zonix")))

        ;; Reiner Steib in <v9wun8ghwx.fsf@marauder.physik.uni-ulm.de>
        ;; X-No-Archive setzen, wenn in Original-Posting gesetzt.
        ((and (message-news-p)
              (save-excursion
                (set-buffer gnus-article-buffer)
                (let ((case-fold-search t))
                  (string-match "yes"
                                (or (message-fetch-field "X-No-Archive") "")))))
         (X-No-Archive "Yes"))
        
        ;; News-Postings (außer Uni) und Mailing-Listen
        ((or
          
          ;; News in nicht vertrauenswürdigen Gruppen
          (and (message-news-p) (boundp 'post)
               (not (string-match zonix-trusted-groups (zonix-get-group-name))))
          
          ;; Mails in nicht vertrauenswürdigen Gruppen

          ;; Reiner Steib in <v9vg4nih6a.fsf@marauder.physik.uni-ulm.de>
          ;; Gruppen mit to-address (normalerweise MLs)
          ;; (gnus-parameter-to-address gnus-newsgroup-name)
          
          (and (message-mail-p) (boundp 'post)
               (or (string-match "^nn.*:\\(INBOX\\.\\)?list\\." (zonix-get-group-name))
                   (string-match "^\\(nn.*\\)?gmane\\." (zonix-get-group-name))
                   (string-match "^nnvirtual:" (zonix-get-group-name)))
               (not (string-match zonix-trusted-groups (zonix-get-group-name)))))

         (address (format-time-string "ray-%Y@zonix.de"))
         ("Reply-To" (concat user-full-name " <rscholz@" ;; spam trap
                                "zonix.de>"))
         ("X-Now-Playing" zonix-now-playing)
         ("Mail-Copies-To" "nobody"))

        ;; versucht, einen MFT-Header auf die Liste zu setzen (ab Gnus 5.10)
;       ((and (message-mail-p)
;             (string-match "^nn.*:\\(INBOX\\.\\)?list\\." (zonix-get-group-name)))
;        ("Mail-Followup-To" (gnus-mailing-list-followup-to)))
        
        ;;;;;;;;;;; spezielle Funktionen

        ;; nndiary arbeitet mit speziellen Headern, die mit Vorgaben
        ;; gefüllt werden.
        ("^nndiary:"
         ("X-Diary-Minute" (format-time-string "%M" (current-time)))
         ("X-Diary-Hour" (format-time-string "%H" (current-time)))
         ("X-Diary-Dom" (format-time-string "%e" (current-time)))
         ("X-Diary-Month" (format-time-string "%m" (current-time)))
         ("X-Diary-Year"  (format-time-string "%Y" (current-time)))
         ("X-Diary-Dow" (format-time-string "%u" (current-time)))
         ("X-Diary-Time-Zone" "*"))
        
        ;; vertrauenswürdige Listen
        ((not (string-match zonix-trusted-groups (zonix-get-group-name)))
         ("X-Now-Playing" zonix-now-playing))
        
        ;; private Mails
        ("^nn.+:\\(INBOX\\.\\)?mail\\.personal\\."
         ("X-Now-Playing" zonix-now-playing))

        ;; englischsprachig
        ("^nn.+:\\(INBOX\\.\\)?mail\\.personal\\.heimat"
         (eval (ispell-change-dictionary "british")))

        ;; Uni
        ("^\\(fb3\\|stuga\\)\\|\\(^nn.+:\\(INBOX\\.\\)?\\(mail\\.personal\\|list\\)\\.uni\\.\\)"
;        (body "<#part sign=pgpmime>\n")
         ("X-Now-Playing" zonix-now-playing)
         (signature (randomsig-signature "mail/ex-uni")))

        ;; gmane
        ("^nn.+:gmane\\.\\(config\\.admin\\|discuss\\.subscribe\\)"
         (signature (randomsig-signature "news/gmane"))) 
        
        ;; Spamcop
        ("^nn.+:\\(INBOX\\.\\)?mail\\.news\\.spam"
         (signature nil)
         (body "")
         (address (concat "rscholz@" ;; spam trap
                          "gmx.de")))
        
        ;; Verified
        ((or
          ;; INBOX 
          (and (string-match "^nn.+:INBOX$" (zonix-get-group-name))
               (string= "verified" zonix-location))

          ;; Verified-Ordner
          (string-match "^nn.+:\\(INBOX\\.\\)?\\(mail\\.verified\\.\\)\\|\\(list\\.uni\\.agbs\\)" (zonix-get-group-name)))
         
         (address (concat "rscholz@" ;; spam trap
                          "verified.de"))
         (organization "Verified Systems International GmbH")
         (body "\nMit freundlichen Grüßen,\n  Raymond Scholz")
         (signature (randomsig-signature "mail/verified")))

        ;; Verified intern
        ("^nn.+:\\(INBOX\\.\\)?mail\\.verified\\.intern"
         (body "\nGrüße, Ray"))
        
        ;; Leute, die mich noch Raymond nennen
        ("^nn.+:\\(INBOX\\.\\)?mail\\.personal\\.\\(bekannte\\|familie\\|ttsg\\|schule\\)"
         (body "\nGrüße, Raymond"))

        ;; Leute, die mich nicht kennen
        ("^nn.+:\\(INBOX\\.\\)?mail\\.\\(personal\\.website\\|provider\\.\\(spamcop\\|ebay\\)\\)"
         (body "\nGrüße, Raymond Scholz"))
        
        ;; Schule
        ("^nn.+:\\(INBOX\\.\\)?\\(mail\\.personal\\.schule\\|list\\.jahrgang\\)"
         (address (concat "raymond.scholz@" ;; spam trap
                          "gaw94.de"))
         (signature (randomsig-signature "mail/schule")))

        ;; Kai jammert sonst rum...
        ("^nn.+:\\(INBOX\\.\\)?list\\.toh\\.hosting"
         (organization "Stuemperhosting"))
        
        ;;;;; spezielle Newsgroups

        ;; toh
        ("^toh\\."
         (signature (randomsig-signature "toh-fortunes")))
        
        ;; gmane.org (encrypt, expire=<days>)
;       ("^gmane\\."
;        ("X-Archive" "encrypt"))
        
        ;; bloede Listen...
        ("^gmane\\.\\(network\\.leafnode\\|comp\\.video\\.freevo\\.user\\|comp\\.web\\.wiki\\.dokuwiki\\.general\\)"
         (address (concat "rscholz@" ;; spam trap
                          "gmx.de")))

        ("^nn.+:\\(INBOX\\.\\)?list\\.ivtv-.*"
         (address (concat "rscholz@" ;; spam trap
                          "gmx.de")))
        ;; Emacs-Gruppen
        ((and (boundp 'post)
              (string-match 
               "\\(gnus\\|emacs\\)" (zonix-get-group-name)))

         (eval (setq randomsig-dir "~/el/sigs/comp/"))
         (eval (setq randomsig-files 'randomsig-search-sigfiles))
         (signature (randomsig-signature))
         
         ;("X-Face" zonix-insert-x-face)
         
         ;; ab Gnus 5.10
         (x-face-file "~/el/xfaces/default"))

        ;; Computer
        ((and (boundp 'post)
              (string-match "^\\(de\\.com[mp]\\.\\|stuga\\.ml\\)" (zonix-get-group-name)))
         
;        (organization "[Esc][Meta][Alt][Ctrl][Shift].org")

         (eval (setq randomsig-dir "~/el/sigs/comp/"))
         (eval (setq randomsig-files 'randomsig-search-sigfiles))
;        (eval (setq randomsig-static-string "Fuck M$!\n"))
         (signature (randomsig-signature)))

        ;; Fun
        ((and (boundp 'post)
              (string-match "^\\(de\\.\\)?\\(alt\\|rec\\)\\." (zonix-get-group-name)))

         (eval (setq randomsig-dir "~/el/sigs/news/"))
         (eval (setq randomsig-files 'randomsig-search-sigfiles))
         (signature (randomsig-signature)))

        ;; dafhs
        ("^nn.+:\\(INBOX\\.\\)?list\\.dafhs"
         (address (concat "gelber@" ;; spam trap
                          "plastikball.de")))

        ("^de\\.alt\\.fan\\.haraldschmidt"
         ("Reply-To" (concat user-full-name " <rscholz@" ;; spam trap
                                "dafhs.org>")))

        ("^de\\.rec\\."
         ("Reply-To" (concat user-full-name " <dummes@" ;; spam trap
                                "gerede.org>")))
        
        ;; mgo
        ("^nn.+:\\(INBOX\\.\\)?\\(list\\.gnus\\.mgo\\|mail\\.personal\\.toh\\)"
         (eval (setq randomsig-dir "~/el/sigs/comp/")))
        
        ;; Musik
        ("^de\\.\\(alt\\|comp\\|rec\\)\\.\\(musi[ck]\\|fan\\.konsumterror\\|audio\\)"
         (body   (lambda ()
                   (with-temp-buffer
                     (insert "Grüße, Ray\n")
                     (insert "np: " (zonix-now-playing) "\n")
                     (buffer-string)))))
        
        ))