
;  -*- emacs-lisp -*-

;=============
; Your personal settings
(setq user-mail-address "insider@t-k.ru") 
(setq user-full-name "Igor Anikeev")
		  
			     
;=============
;; Your newsserver
(setq
        gnus-inhibit-startup-message t
        gnus-use-sc t
        gnus-use-trees nil
        gnus-select-method '(nntp "insider.home"))


;; Mail Configuration
(setq gnus-secondary-select-methods
	'((nnml "private")))
	
(setq nnmail-split-methods
    '(("personal" "^To:.*insider@t-k.ru")
      ("altlinux.community" "^List-Id: <community.altlinux.ru>")
      ("altlinux.talkroom"  "^List-Id: <talk-room.altlinux.ru>")
      ("altlinux.legal" "^List-Id: <legal.lrn.ru>")
      ("altlinux.ruby" "^List-Id: Ruby usage and development around it <ruby.altlinux.ru>")
      ("sf.net" "^From:.*SourceForge.net")
      ("netbeans.discuss-ru" "^From: nbdiscuss_ru-help@netbeans.org")
      ("netbeans.announce" "^list-post: <mailto:nbannounce@netbeans.org>")
      ("netbeans.openide" "^list-post: <mailto:dev@openide.netbeans.org>")
      ("netbeans.ui" "^list-post: <mailto:nbui@netbeans.org>")
      ("netbeans.users" "^list-post: <mailto:nbusers@netbeans.org>")
      ("other" "")))	
	

(setq send-mail-function 'smtpmail-send-it)
(setq message-send-mail-function 'smtpmail-send-it)
(setq smtpmail-default-smtp-server "127.0.0.1")

;; wrap messages at 72
(add-hook 'message-mode-hook
    (lambda()
	(setq fill-column 72)
	(turn-on-auto-fill)))
	
	
;; locally store sent mail and news
(setq gnus-message-archive-group
    '((if (message-news-p)
	"nnml:Send-News"
       "nnml:Send-Mail")))	
       
       
(add-hook 'message-send-hook 'my-message-add-content)
(defun my-message-add-content ()
    (message-add-header "Keywords: 5525434"))
    

(add-hook
 'message-setup-hook
 '(lambda ()
    ;; Add X-Comment-To: field. We need From: field from original
    ;; letter. How to get right?
    (if message-reply-buffer
        (let ((cur-buffer (current-buffer)) from-field)
          (save-excursion
            (set-buffer message-reply-buffer)
            (if (string-match "^From:" (buffer-string))
                (progn
                  (setq from-start (+ (match-end 0) 1))
                  (goto-char from-start)
                  (end-of-line)
                  (setq from-field (buffer-substring from-start (point))))))
          (if from-field
              (save-excursion
                (goto-char (point-min))
                (insert "X-Comment-To: " (Make-Comment-To from-field) "\n"))))
      )))

(defun Make-Comment-To (from)
  (if (string-match " *<.*> *" from)
      (concat (substring from 0 (match-beginning 0)) (substring from
                                                                (match-end 0)))


   (if (string-match "\(.*\)" from)
       (substring from (+ (match-beginning 0) 1) (- (match-end 0) 1))
     from
     )
   )
 )
   

;
;From: Ivan Crivoruchko <Ivan_Crivoruchko@f470.n5030.z2.fidonet.org>
;========================<CUT>========================

(defun sc-break-cited-line ()
  "Break cited line. Do it correctly."
  (interactive)
  (delete-horizontal-space)
  (newline)
  (forward-line -1)
  (let ((cited (looking-at (sc-cite-regexp))))
    (forward-line)
    (if cited (progn (sc-cite-line) (just-one-space)))))

(defun sc-header-hello-attributed-writes ()
  "Insert Hi, sc-firstneme, then sc-header-attributed-writes"
  (insert
   (concat "\nHi, " (sc-mail-field "sc-firstname") "!\n\n"))
  (my-header-line-generator)
;  (sc-header-attributed-writes)
  )

(defun sc-install-rewrite-header-fn (new-fn)
  "Install new header rewrite function and make it preffered"
  (setq sc-preferred-header-style (length sc-rewrite-header-list))
  (setq sc-rewrite-header-list
        (append sc-rewrite-header-list `((,new-fn)))))

(defun ic-cite-message ()
  (sc-cite-original)
  (local-set-key "\C-m" 'sc-break-cited-line))

(setq message-cite-function 'ic-cite-message)

(setq mail-citation-hook 'ic-cite-message)
;(add-hook 'mail-citation-hook 'ic-cite-message)

(add-hook 'sc-load-hook (lambda ()
                          (sc-install-rewrite-header-fn
                           'sc-header-hello-attributed-writes)
                          (setq sc-confirm-always-p nil)))

(setq news-reply-header-hook nil)

;========================<CUT>========================

(setq sc-preferred-attribution-list
      '( "initials" "x-attribution" "firstname" "sc-lastchoice" ))

;;; sc hack by Bor.
(defun sc-add-citation-level-m ()
  "Add citation level to cited string"
  (interactive)
  (if (looking-at (sc-cite-regexp))
      (if (re-search-forward
           (concat sc-citation-leader-regexp sc-citation-root-regexp)
           )
          (insert sc-citation-delimiter)
        )
    (sc-cite-line)
    )
  )

; Cool mailcrypting stuff
(load-library "mailcrypt")
(mc-setversion "gpg")
(autoload 'mc-install-write-mode "mailcrypt" nil t)
(autoload 'mc-install-read-mode "mailcrypt" nil t)
(add-hook 'gnus-summary-mode-hook 'mc-install-read-mode)
(add-hook 'message-mode-hook 'mc-install-write-mode)
(add-hook 'news-reply-mode-hook 'mc-install-write-mode)
;; If you have more than one key, specify the one to use
(setq mc-gpg-user-id "Igor Anikeev")
;; Always sign encrypted messages
(setq mc-pgp-always-sign t)
;; How long should mailcrypt remember your passphrase
(setq mc-passwd-timeout 600)
;; Automagically sign all messages
(add-hook 'message-send-hook 'will-you-sign)
(defun will-you-sign ()
        (load-library "mc-toplev")
        (interactive)
        (if (y-or-n-p "Do you want to sign this message? ")
                (mc-sign-message)))



;; Gnus Demon
(gnus-demon-add-rescan)

;;
;; News auto rescan
;;

(setq gnus-use-demon t)
(gnus-demon-init)
(gnus-demon-add-rescan)

(defun avk-scan-new-messages ()
  "Scan for new mail and news every 15 minutes."
  (when (gnus-alive-p)
    (save-excursion
      (set-buffer gnus-group-buffer)
      (gnus-group-get-new-news))))

(gnus-demon-add-handler 'avk-scan-new-messages 5 2)
(gnus-demon-add-handler 'gnus-group-save-newsrc 10 1)

