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

;; X-PGP-SIG

;; http://my.gnus.org/Docs/Contrib/x-pgp-sig-README
;; (add-to-list 'load-path (concat rs-elisp-dir "x-pgp-sig"))
;; (autoload 'x-pgp-sig-sign "x-pgp-sig" nil t)
;; (autoload 'x-pgp-sig-set-signer "x-pgp-sig" nil t)
;; (autoload 'x-pgp-sig-set-signer-maybe "x-pgp-sig" nil t)
;; (autoload 'x-pgp-sig-verify "x-pgp-sig" nil t)
;; (setq x-pgp-sig-sign-fields '("Subject" "Control" "Message-ID" "Date" "From"))
;; (setq x-pgp-sig-always-sign nil)
;; (add-hook 'message-header-hook 'x-pgp-sig-sign t)

;(setq x-pgp-sig-default-signer "F0311FD8")
;(setq x-pgp-sig-secring "/home/rscholz/.gnupg/secring.gpg")



;; automatisch Mail abholen / expiren
(gnus-demon-add-handler 'gnus-group-expire-all-groups 90 60)
;(gnus-demon-add-handler 'gnus-demon-scan-mail 90 60)

;; From:  Marcus Frings <iam-est-hora-surgere@fuckmicrosoft.com>
;; Subject: Re: gnus-demon-scan-mail problems
;; Newsgroups: gnu.emacs.gnus
;; Date: Mon Jun 16 21:24:38 2003 +0200
;; Organization: Schismatrix
;; X-Sent: 2 weeks, 5 days, 20 hours, 46 minutes ago
;; Message-ID: <vita-brevis-breviter-in-brevi-finietur-mors-venit-velociter-quae-neminem-veretur-87brwxn7ux.fsf@gothgoose.net>
;; Reply-To: protagonist@gmx.net
;; Mail-Copies-To: never
;; User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)

;; (setq gnus-use-demon t)

;; (defun gnus-demon-scan-news ()
;;   (when (gnus-alive-p)
;;     (save-excursion
;;       (set-buffer gnus-group-buffer)
;;       (gnus-group-get-new-news))
;;     )
;;   )

;; (defun gnus-demon-scan-mail ()
;;   (when (and (gnus-alive-p) mail-here)
;;     (save-excursion
;;       (set-buffer gnus-group-buffer)
;;       (gnus-group-get-new-news 3)
;;       )
;;     )
;;   )

;; (gnus-demon-add-handler 'gnus-demon-scan-news 5 10)

;; (gnus-demon-init)




(defun message-unique-id ()
  ;; Don't use microseconds from (current-time), they may be unsupported.
  ;; Instead we use this randomly inited counter.
  (setq message-unique-id-char
        (% (1+ (or message-unique-id-char (logand (random t) (1- (lsh 1 20)))))
           ;; (current-time) returns 16-bit ints,
           ;; and 2^16*25 just fits into 4 digits i base 36.
           (* 25 25)))
  (let ((tm (current-time)))
    (concat
     (if (memq system-type '(ms-dos emx vax-vms))
         (let ((user (downcase (user-login-name))))
           (while (string-match "[^a-z0-9_]" user)
             (aset user (match-beginning 0) ?_))
           user)
       (message-number-base36 (user-uid) -1))
     (message-number-base36 (+ (car tm)
                               (lsh (% message-unique-id-char 25) 16)) 4)
     (message-number-base36 (+ (nth 1 tm)
                               (lsh (/ message-unique-id-char 25) 16)) 4))))


;(setq nnmail-expiry-target 'nnmail-fancy-expiry-target
;      nnmail-fancy-expiry-targets
;      '(
;       ("" (eval (concat gnus-news-group-name ".%Y"))
;       ("" "nnfolder:Work")
;       ("subject" "IMPORTANT" "nnfolder:IMPORTANT.%Y.%b")
;       ("from" ".*" "nnfolder:Archive-%Y")))







;;;;;;;;;;;;;;;;;; START GNUS SUMMARY


; gnus-face-1 
(copy-face 'default 'mysubject)
;(set-face-font 'mysubject "Verdana:Regular:8") 
(setq gnus-face-1 'mysubject)
 
;gnus-face-2 
(copy-face 'default 'mytime)
;(set-face-font       'mytime "HE_Terminal:Regular:7") 
(set-face-foreground 'mytime "indianred4")
(setq gnus-face-2 'mytime) 
 
;gnus-face-3 
;(copy-face 'ct-face1 'mythreads)
(copy-face 'default 'mythreads)
(set-face-foreground 'mythreads "indianred4") 
(setq gnus-face-3 'mythreads) 
 
;gnus-face-4 
(copy-face 'default 'mygrey) 
(set-face-foreground 'mygrey "grey") 
;(set-face-font 'mygrey "HE_Terminal_Gnus:Regular:8") 
(setq gnus-face-4 'mygrey) 
 
;gnus-face-5 
(copy-face 'default 'myblack) 
(set-face-foreground 'myblack "grey60") 
(setq gnus-face-5 'myblack) 
 
;gnus-face-6 
(copy-face 'default 'mybiggernumbers) 
;(set-face-font       'mybiggernumbers "HE_Terminal:Regular:8") 
(set-face-foreground 'mybiggernumbers "indianred4") 
(setq gnus-face-6 'mybiggernumbers)

(setq gnus-group-line-format  
       "%*%6{%M%S%p    %}%(%2{%4y%}%4{|%}%-40,40G%3O%l %4{|%}%2{%4U.%}%4{|%}%2{%3T!%}%4{|%}%2{%3I?%}%4{|%}%2{%5t%} %)%4{| %}%1{%D%}\n")


;(add-hook 'gnus-group-mode-hook
;         (lambda ()
;           (setq header-line-format
;                 " C    Unread|Name                                        |New  |Tick|Dorm|Total |Description")))

;(setq gnus-topic-line-format "%4v            %2{%5A %} %(%2{ ==> %-31n%)%}\n")


;;;;;;;;;;;;;;;;;;



;;;;;;;;,


;(require 'gnus-propfont)
;(add-hook 'gnus-article-prepare-hook 'gpf-add-faces)
;(remove-hook 'gnus-article-prepare-hook 'gpf-add-faces)



(setq gpf-line-spacing nil)

;(set-face-font 'gpf-variable-width-face "lucidasans-14")



;; (defun my-orig-date-group (name)
;;   "Returns a string of the format `NAME-YYYY-MM'"
;;   (concat name "-"
;;        (format-time-string "%Y-%m" (date-to-time
;;                                     (mail-fetch-field "date")))))

;;   (setq nnmail-split-fancy
;;         '(| (any  "root@pille\\.fhaun\\.de" (: my-date-group "System"))
;;             (any "debian-\\b\\(\\w+\\)@lists.debian.org"
;;                  (: my-date-group "mail.debian.\\1"))
;;             "misc.misc"))


(setq
 mm-text-html-renderer 'w3m
 ;; Use wget instead of url.el (for nnweb-type google), seem to be more
 ;; reliable.
 mm-url-use-external t
 mm-url-program 'wget)


;; From:  Reiner Steib <4.uce.03.r.s@nurfuerspam.de> ;
;; Subject: Re: Leere Zeilen Quoten
;; Newsgroups: de.comm.software.gnus
;; Date: Fri Jun 20 18:18:46 2003 +0200
;; Organization: Dept. of Theoretical Physics, University of Ulm
;; Reply-To: reiner.steib@gmx.de
;; Mail-Copies-To: nobody
;; User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)
;; X-Sent: 1 week, 1 day, 2 hours, 38 minutes, 46 seconds ago
;; Message-ID: <v94r2k67tl.fsf@marauder.physik.uni-ulm.de>

(defun rs-message-remove-blank-cited-lines (&optional remove)
  "Remove cited lines containing only blanks.
If REMOVE is non-nil, remove newlines, too."
  ;; Idea by Karl Plästerer,
  ;; see <m3adiiup8o.fsf@hamster.pflaesterer.de> ff.
  (interactive "P")
  (let ((citexp
         (concat
          "^\\("
          (if (boundp 'message-yank-cited-prefix)
              (concat message-yank-cited-prefix "\\|"))
          message-yank-prefix
          "\\)+ *$"
          (if remove "\n" ""))))
    (gnus-message 8 "removing `%s'" citexp)
    (save-excursion
      (message-goto-body)
      (while (re-search-forward citexp nil t)
        (replace-match "")))))
;; To use this automatically:
;(add-hook 'gnus-message-setup-hook 'rs-message-remove-blank-cited-lines)




;; From:  Bill White <billw@wolfram.com>
;; Subject: Re: Getting message details from message-sent-hook
;; Newsgroups: gnus.ding
;; Cc: ding@gnus.org
;; Date: Thu May 29 05:22:35 2003 +0200
;; X-Sent: 4 weeks, 3 days, 11 hours, 55 minutes, 31 seconds ago
;; Message-ID: <ruo4r3ea138.fsf@billw2lx.wolfram.com>
;; User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

(defun message-to-diary ()
  (make-diary-entry (concat 
                     (format-time-string "%B %d, %Y %H:%M" (gnus-date-get-time (message-fetch-field "date")))
                     (if (message-fetch-field "newsgroups")
                         (concat " Sent news To: " (message-fetch-field "newsgroups"))
                       (concat " Sent mail To: " (message-fetch-field "to")))
                     " Subject: \"" (message-fetch-field "subject") "\""
                     " Message-ID: " (message-fetch-field "message-id")))
  (save-buffer "diary"))
;(add-hook 'message-sent-hook 'message-to-diary)

(setq mail-extr-ignore-single-names t)



;; From:  sigurd@12move.de (Karl Pflästerer)
;; Subject: Re: Spoilerspace entfernen
;; Newsgroups: de.comm.software.gnus
;; Date: Mon Jun 30 17:33:21 2003 +0200
;; Organization: Lemis World
;; X-Sent: 6 days, 1 hour, 25 minutes, 47 seconds ago
;; Message-ID: <m3ptkvlhar.fsf@hamster.pflaesterer.de>
;; User-Agent: Gnus/5.1003 (Gnus v5.10.3) Hamster/2.0.2.1

(defun* my-remove-spoilersigns-1 (&key reg mult phrase)
  "Remove in at least MULT lines similar matches for regexp REG.
Optionally insert phrase PHRASE as indication."
  (save-match-data
    (while (not (eobp)) 
      (re-search-forward reg nil t)
      (do ((line1 (match-string 0) (match-string 0))
           (line2 (match-string 0) line1)
           (beg (point-at-bol))
           (i 0 (1+ i)))
          ((not (equal line1 line2)) (and (>= i mult)
                                          (progn
                                            (delete-region beg (point))
                                            (if phrase
                                              (insert phrase))
                                            (return-from my-remove-spoilersigns-1))))
        (forward-line)
        (re-search-forward reg nil t)))))

(defun my-remove-spoilersigns (&optional mult)
  "Remove spoilerspace consisting of at least MULT similar signs.
The default for MULT is 10.

If you call the function with any prefix argument you can enter another
multiplier."

  (interactive)
  (gnus-with-article-buffer
   (when current-prefix-arg
     (setq mult (read-number "Mininum number of occurences: " 'integer)))
   (my-remove-spoilersigns-1 :mult (or mult 10)
                             :reg "^.*$"
                             :phrase "[Spoilerspace entfernt]\n")))
(defvar gnus-treat-strip-spoilersigns nil
  "Whether spoilerspace should be stripped")

(add-to-list 'gnus-treatment-function-alist
             (list 'gnus-treat-strip-spoilersigns 'my-remove-spoilersigns))
(defun gnus-summary-show-spoilersigns ()
  "Show article with spoilerspace."
  (interactive)
   (let (gnus-treat-strip-spoilersigns)
     (gnus-summary-show-article)))



;;;;;;;;;;;
;; (defvar my-gnus-summary-subject-overlay nil)
;; (setq gnus-summary-same-subject (propertize " " 'gnus-summary-same-subject t))

;; (defun my-gnus-summary-update-subject (&optional window start)
;;   (save-excursion
;;     (goto-char (or start (window-start)))
;;     (let ((end (line-end-position)))
;;       (if (not (text-property-any (point) end 'gnus-summary-same-subject t))
;;        (delete-overlay my-gnus-summary-subject-overlay)
;;      (move-overlay my-gnus-summary-subject-overlay (1- end) end)
;;      (overlay-put my-gnus-summary-subject-overlay
;;                   'before-string
;;                   (propertize (gnus-summary-subject-string
;;                                (gnus-summary-article-number))
;;                               'face gnus-face-1))))))

;; (defun my-gnus-summary-prepared-hook ()
;;   (add-hook 'window-scroll-functions 'my-gnus-summary-update-subject nil t)
;;   (set (make-local-variable 'my-gnus-summary-subject-overlay)
;;        (make-overlay 0 0)))
;; (add-hook 'gnus-summary-prepared-hook 'my-gnus-summary-prepared-hook)

;; (defadvice gnus-summary-recenter (after summary-update-subject activate)
;;   (my-gnus-summary-update-subject))
;; ;;;;;;;;;;


(require 'gnus-dynamic-subject)

(setq imap-log t)

(setq mm-inline-text-html-with-images t)


;(setq mml-base-boundary "=-=-=")
(setq mml-base-boundary "Multipart0o0o0o0o0o0o0o")





(setq message-dont-reply-to-names "rscholz\\|raymond")



;;     (defun gnus-user-format-function-thread (dummy)
;;       (propertize gnus-tmp-thread-tree-header-string 'gnus-face t))

;; ;    (dolist (c '((?\207 . ?q) (?\216 . ?x) (?\212 . ?t) (?\203 . ?m)))
;; ;      (aset standard-display-table (car c)
;; ;            (vector (create-glyph (concat "\e(0" "\e[35m" ; magenta
;; ;                                          (char-to-string (cdr c))
;; ;                                          "\e[0m" "\e(B")))))

;;    (setq gnus-sum-thread-tree-vertical "\216"
;;           gnus-sum-thread-tree-root ""
;;           gnus-sum-thread-tree-false-root ""
;;           gnus-sum-thread-tree-indent " "
;;           gnus-sum-thread-tree-single-indent ""
;;           gnus-sum-thread-tree-leaf-with-other "\212\207>"
;;           gnus-sum-thread-tree-single-leaf "\203\207>")


;;    (let ((val 129))
;;            (while (< val 160)
;;                   (aset standard-display-table val (vector (create-glyph val)))
;;                           (setq val (1+ val))))







(setq gnus-mime-recompute-hierarchical-structure t)

;; (require 'x-face-e21)
;; (require 'gnus-summary-x-face)


;;       (setq gnus-article-x-face-command 'x-face-decode-message-header
;;           ;; Use `gnus-treat-display-xface' instead of
;;           ;; `gnus-treat-display-x-face' if you are using Gnus versions
;;           ;; prior to 5.10.3.
;;           gnus-treat-display-x-face 'head
;;           gnus-treat-display-face nil)

;;       (autoload 'x-face-decode-message-header "x-face-e21")
;;       ;;
;;       (autoload 'x-face-insert "x-face-e21" nil t)
;;       (autoload 'x-face-save "x-face-e21" nil t)
;;       (autoload 'x-face-show "x-face-e21" nil t)
;;       (autoload 'x-face-ascii-view "x-face-e21" nil t)
;;       (autoload 'x-face-turn-off "x-face-e21")
;;       ;;
;;       ;; Show X-Face images when `x-face-insert' is done.
;;       (setq x-face-auto-image t)



(require 'cl)
(push "~/el/gmadmin" load-path)
(add-hook 'gnus-summary-mode-hook 'gmane-setup-summary)
(push '("gmane.conf" . gmane-mode) auto-mode-alist)
(autoload 'gmane-setup-summary "gmane")
(autoload 'gmane-mode "gmane")



(setq mml-insert-mime-headers-always t)


(defun gzp-interactively-enter-group (group)
    (interactive
        (list (completing-read "Group: " gnus-active-hashtb nil nil "nnimap")))
      (unless group
            (error "No group name given"))
        (gnus-group-read-group t t group))
(define-key gnus-group-mode-map "Gz" 'gzp-interactively-enter-group)


;; maybe this is better:
;; Message-ID: <iluwtudqzqa.fsf@latte.josefsson.org>





(setq uncompface-use-external t)




;; Reiner Steib in <v9brl1v1f7.fsf@marauder.physik.uni-ulm.de>
;; This allows you to save articles with `o':
;; (setq gnus-default-article-saver 'rs-gnus-summary-save-to-archive)
;; Alternatively you can add a different keybinding, e.g.:
;; (add-hook
;;  'gnus-summary-mode-hook
;;  '(lambda ()
;;     (local-set-key (kbd "%") 'rs-gnus-summary-save-to-archive)))
(require 'gnus-sum)

(defvar rs-gnus-archive-prefix "nnml+archive:"
  "Name of my prefered archive server.")

(defvar rs-gnus-query-archive-regex "drafts"
  "If value of `gnus-newsgroup-name' matches this regexp, query before
archiving the article.")

;;;###autoload
(defun rs-gnus-summary-save-to-archive (&optional n)
  "Copy article(s) to an archive group."
  (interactive "P")
  ;; Suggested by Josh Huber in <87d6v3b0io.fsf@alum.wpi.edu>
  ;; Added process/prefix stuff
  (let ((group-name (if (string-match ":" gnus-newsgroup-name)
                        (substring gnus-newsgroup-name (match-end 0))
                      gnus-newsgroup-name))
        (orig-mark (gnus-summary-article-mark n))
        archive-group)
    (if (and (string-match gnus-newsgroup-name rs-gnus-query-archive-regex)
             (not (y-or-n-p
                   (concat "Archive article to group `"
                           archive-group "? "))))
        (gnus-message 5 "Aborted.")
      (progn
        (setq archive-group (concat rs-gnus-archive-prefix group-name))
        (gnus-summary-mark-article n gnus-ancient-mark t)
        (gnus-summary-copy-article n archive-group)
        (gnus-summary-mark-article n orig-mark t)
        ;; for not fooling `rs-gnus-notify-mail':
        (when (fboundp 'rs-gnus-notify-no-new-mail)
          (rs-gnus-notify-no-new-mail))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,



;; Reiner Steib in <v93c0rrb16.fsf@marauder.physik.uni-ulm.de>
(defvar rs-message-to-from-addresses gnus-ignored-from-addresses
  "Regexp matching To headers.

When using entries like

  ((message-mail-p)
   (address (rs-message-to-from-address)))

or
  ((message-mail-p)
   (address (rs-message-to-from-address \"foo@example.invalid\")))

in `gnus-posting-styles', the address in the From header is taken
from the To header of the article you are replying to.")

;;;###autoload
(defun rs-message-to-from-address (&optional fallback)
  "Return a suitable address.

See `rs-message-to-from-addresses' for more."
  (let ((to (with-current-buffer
                (and (boundp 'gnus-article-buffer)
                     (gnus-buffer-live-p gnus-article-buffer)
                     ;; `gnus-buffer-live-p' already returns
                     ;; `gnus-article-buffer', but it's not documented.  So
                     ;; let's be careful.
                     gnus-article-buffer)
              (message-fetch-field "to"))))
    (cond ((and to
                (string-match rs-message-to-from-addresses to))
           (cadr (gnus-extract-address-components to)))
          (fallback fallback)
          (t user-mail-address))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,,


;; Reiner Steib in <v94qtz6n1a.fsf@marauder.physik.uni-ulm.de>

;;;###autoload
(defun rs-message-news-reply-p ()
  "Say whether the current buffer contains a mail-reply to a news message."
  ;; borrowed from Micha Wiedenmann <87smzfearu.fsf@ID-56226.news.dfncis.de>
  (and gnus-newsgroup-name
       (gnus-news-group-p gnus-newsgroup-name)
       (message-mail-p)))

;;;###autoload
(defvar rs-gnus-message-archive-group-news-prefix "nnfolder+News:News-"
  "Back end \(and optional prefix\) for archiving postings.")
;;;###autoload
(defvar rs-gnus-message-archive-group-mail-prefix "nnml:"
  "Back end \(and optional prefix\) for archiving mails.")

;;;###autoload
(defun rs-gnus-message-archive-group-mt (group-current)
  "Return preferred archive group."
  ;; See thread around the following MIDs for more info:
  ;; <news:v9hefblk1y.fsf@marauder.physik.uni-ulm.de>
  ;; <news:dcsg.m365jcgfp4.fsf@beldin.gothgoose.net>
  (let* ((group-plain (gnus-replace-in-string group-current "^.*:" ""))
         (gcc-suffix
          ;; some examples...
          (cond ((string-match "\\.tex$" group-plain) "LaTeX")
                ((string-match "\\.gnus$\\|\\.ding$" group-plain) "Gnus")
                ((string-match "\\.emacs\\." group-plain) "Emacs")
                ((string-match "\\..+\\..+\\..+$" group-plain)
                 ;; `de.comp.os.unix.shell' -> `unix-shell'
                 ;; (using only last would give too many `-misc' groups)
                 (gnus-replace-in-string
                  group-plain "^.*\\.\\([^.]+\\)+\\.\\([^.]+\\)$" "\\1-\\2"))
                ;; (replace `group-plain' by
                ;; `(gnus-replace-in-string group-plain "\\." "-")'
                ;; if you don't like dots in group names:)
                (t group-plain))))
    (cond
     ;; If group is writeable, gcc to this group:
     ((gnus-check-backend-function 'request-move-article group-current)
      group-current)
     ;; Reply to news article:
     ((rs-message-news-reply-p)
      (concat rs-gnus-message-archive-group-mail-prefix gcc-suffix))
     ;; Followup to news:
     ((message-news-p)
      (concat rs-gnus-message-archive-group-news-prefix gcc-suffix))
     ;; Starting a mail from a newsgroup (why?) / catch all:
     (t (concat rs-gnus-message-archive-group-mail-prefix gcc-suffix)))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Marcus Frings in
;; <vita-brevis-breviter-in-brevi-finietur-mors-venit-velociter-quae-neminem-veretur-87vfty3xwz.fsf@gothgoose.net>

(require 'gnus-fun)

(defvar faces-dir "~/.emacs.d/faces"
  "Directory for the face-files.")

(defun mf-insert-random-face ()
  "Insert a random face header from the files in `faces-dir'.
The files have to be in PNG format, being 48x48 and smaller
than or equal to 726 bytes."
  (when (file-exists-p faces-dir)
    (let* ((files (directory-files faces-dir t "\\.png$"))
           (file (nth (random (length files)) files)))
      (when file
        (mm-with-unibyte-buffer
          (insert-file-contents file)
          (when (> (buffer-size) 726)
            (error "The file is %d bytes long which is too long."
                   (buffer-size)))
          (gnus-face-encode))))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;,,,


;; From: Klaus Uhl <news@u-h-l.de>
;; Subject: Automatically sign/encrypt messages
;; Newsgroups: gnu.emacs.gnus
;; Date: Thu, 29 Jan 2004 18:31:07 +0100
;; Message-ID: <87n086ach0.fsf@ulm.my.lan>

;; (add-hook 'message-send-hook
;;        (lambda ()
;;          (let ((recipient (message-fetch-field "To")))
;;            (cond ((and (not (null recipient))
;;                        (or (pgg-lookup-key recipient)
;;                            (pgg-fetch-key pgg-default-keyserver-address recipient)))
;;                   (mml-secure-message-encrypt-pgpmime))
;;                  (t
;;                   (mml-secure-message-sign-pgpmime))))))


(setq nntp-marks-is-evil t)
(require 'idna)
(setq gnus-use-idna t)



;; Antworten auf signierte Mails immer signieren
(setq gnus-message-replysign t)
;; Antworten auf verschlüsselte Mails immer verschlüsseln
(setq gnus-message-replyencrypt t)


;(setq gnus-agent nil)



;(add-hook 'message-send-hook 'mml-secure-message-sign)

(setq pgg-gpg-use-agent t)

;; electric completion since 2006-04-16
;; <m33bgga1ul.fsf@quimbies.gnus.org>
(setq message-mail-alias-type 'ecomplete)


;; From: François Fleuret <francois.fleuret@epfl.ch>
;; Subject: Checking attachments are actually attached
;; Newsgroups: gnu.emacs.gnus
;; Date: Sat, 08 Apr 2006 12:34:21 +0200
;; X-Sent: 1 week, 1 day, 9 hours, 23 minutes, 48 seconds ago
;; Message-ID: <87fykoe4pe.fsf@fleuret.homeunix.org>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Checks that the mail contains an attached file if the body refers
;; to such an attachment. The idea comes from
;; http://home.cc.gatech.edu/eaganj/MailApp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom check-no-missing-attachment-regexp "attach\\|anhang\\|angehängt"
  "*A mail whose body matches this regular expression should contain
an attachment")

(defun contains-attachment (l)
  (and l (or (and
              (eq (car (car l)) 'part)
              (string= "attachment" (cdr (assoc 'disposition (cdr (car l))))))
             (contains-attachment (cdr l)))))
(defun check-no-missing-attachment ()
  "Checks the mail contains an attached file if the body refers to such an attachment"
  (message-goto-body)
  (and (re-search-forward check-no-missing-attachment-regexp nil t)
       (not (contains-attachment (mml-parse)))
       (not (y-or-n-p "An attachment seems to be missing, send message ? "))
       (error "You refer to an unexisting attachment.")))

(add-hook 'message-send-hook 'check-no-missing-attachment)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;; use agent
(if (string-match "verified" zonix-location)
    (add-to-list 'gnus-select-article-hook
                 (lambda ()
                   (if (string-match "^nnimap\\+localhost:.*"
                                     gnus-newsgroup-name)
                       (gnus-agent-fetch-selected-article)))))
(setq gnus-agent-synchronize-flags 'ask)
(setq gnus-agent-enable-expiration 'DISABLE)

;;* Nach neuen News gucken und danach direkt vom Agent holen
;;* lassen. (Entspricht 'g' + 'J s' im Group buffer.
(defun th-gnus-get-news-and-agent-fetch ()
  "First it looks for new news via gnus-group-get-new-news and
  then lets the agent fetch it via gnus-agent-fetch-session."
  (interactive)
  (gnus-group-get-new-news)
  (gnus-agent-fetch-session))

(define-key gnus-group-mode-map (kbd "C-c g")
  'th-gnus-get-news-and-agent-fetch)




(setq gnus-use-correct-string-widths t)

(setq message-generate-hashcash nil)


(defun zonix-gnus-summary-show-article-unsafe ()
  "Display article with unsafe settings."
  (interactive)
  (let ((mm-w3m-safe-url-regexp nil)
        (mm-discouraged-alternatives nil))
    (gnus-summary-show-article)))

(define-key gnus-summary-mode-map (kbd "C-c g")
  'zonix-gnus-summary-show-article-unsafe)


(add-hook 'gnus-article-mode-hook
          (lambda ()
            (set (make-local-variable 'w3m-goto-article-function)
                 'browse-url)))



;; epg req. gpg >= 1.4.3 only at home
(if (string-match "home" zonix-location)
    (progn
      (add-to-list 'load-path (concat zonix-elisp-dir "epg"))
      (setq mml2015-use 'epg)
      (require 'pgg-epg)
      (setq pgg-scheme 'epg)))