123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- (require 'gnus-art)
- (require 'gnus-sum)
- (defconst gnus-outlook-deuglify-version "1.5 Gnus version"
- "Version of gnus-outlook-deuglify.")
- (defgroup gnus-outlook-deuglify nil
- "Deuglify articles generated by broken user agents like MS Outlook (Express)."
- :version "22.1"
- :group 'gnus)
- (defcustom gnus-outlook-deuglify-unwrap-min 45
- "Minimum length of the cited line above the (possibly) wrapped line."
- :version "22.1"
- :type 'integer
- :group 'gnus-outlook-deuglify)
- (defcustom gnus-outlook-deuglify-unwrap-max 95
- "Maximum length of the cited line after unwrapping."
- :version "22.1"
- :type 'integer
- :group 'gnus-outlook-deuglify)
- (defcustom gnus-outlook-deuglify-cite-marks ">|#%"
- "Characters that indicate cited lines."
- :version "22.1"
- :type 'string
- :group 'gnus-outlook-deuglify)
- (defcustom gnus-outlook-deuglify-unwrap-stop-chars nil
- "Characters that inhibit unwrapping if they are the last one on the cited line above the possible wrapped line."
- :version "22.1"
- :type '(radio (const :format "None " nil)
- (string :value ".?!"))
- :group 'gnus-outlook-deuglify)
- (defcustom gnus-outlook-deuglify-no-wrap-chars "`"
- "Characters that inhibit unwrapping if they are the first one in the possibly wrapped line."
- :version "22.1"
- :type 'string
- :group 'gnus-outlook-deuglify)
- (defcustom gnus-outlook-deuglify-attrib-cut-regexp
- "\\(On \\|Am \\)?\\(Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\|Sun\\),[^,]+, "
- "Regular expression matching the beginning of an attribution line that should be cut off."
- :version "22.1"
- :type 'string
- :group 'gnus-outlook-deuglify)
- (defcustom gnus-outlook-deuglify-attrib-verb-regexp
- "wrote\\|writes\\|says\\|schrieb\\|schreibt\\|meinte\\|skrev\\|a écrit\\|schreef\\|escribió"
- "Regular expression matching the verb used in an attribution line."
- :version "22.1"
- :type 'string
- :group 'gnus-outlook-deuglify)
- (defcustom gnus-outlook-deuglify-attrib-end-regexp
- ": *\\|\\.\\.\\."
- "Regular expression matching the end of an attribution line."
- :version "22.1"
- :type 'string
- :group 'gnus-outlook-deuglify)
- (defcustom gnus-outlook-display-hook nil
- "A hook called after an deuglified article has been prepared.
- It is run after `gnus-article-prepare-hook'."
- :version "22.1"
- :type 'hook
- :group 'gnus-outlook-deuglify)
- (defun gnus-outlook-display-article-buffer ()
- "Redisplay current buffer or article buffer."
- (with-current-buffer (or gnus-article-buffer (current-buffer))
-
-
-
-
- (gnus-article-highlight t)
- (gnus-treat-article nil)
- (gnus-run-hooks 'gnus-article-prepare-hook
- 'gnus-outlook-display-hook)))
- (defun gnus-article-outlook-unwrap-lines (&optional nodisplay)
- "Unwrap lines that appear to be wrapped citation lines.
- You can control what lines will be unwrapped by frobbing
- `gnus-outlook-deuglify-unwrap-min' and `gnus-outlook-deuglify-unwrap-max',
- indicating the minimum and maximum length of an unwrapped citation line. If
- NODISPLAY is non-nil, don't redisplay the article buffer."
- (interactive "P")
- (let ((case-fold-search nil)
- (inhibit-read-only t)
- (cite-marks gnus-outlook-deuglify-cite-marks)
- (no-wrap gnus-outlook-deuglify-no-wrap-chars)
- (stop-chars gnus-outlook-deuglify-unwrap-stop-chars))
- (gnus-with-article-buffer
- (article-goto-body)
- (while (re-search-forward
- (concat
- "^\\([ \t" cite-marks "]*\\)"
- "\\([" cite-marks "].*[^\n " stop-chars "]\\)[ \t]?\n"
- "\\1\\([^\n " cite-marks no-wrap "]+.*\\)$")
- nil t)
- (let ((len12 (- (match-end 2) (match-beginning 1)))
- (len3 (- (match-end 3) (match-beginning 3))))
- (when (and (> len12 gnus-outlook-deuglify-unwrap-min)
- (< (+ len12 len3) gnus-outlook-deuglify-unwrap-max))
- (replace-match "\\1\\2 \\3")
- (goto-char (match-beginning 0)))))))
- (unless nodisplay (gnus-outlook-display-article-buffer)))
- (defun gnus-outlook-rearrange-article (attr-start)
- "Put the text from ATTR-START to the end of buffer at the top of the article buffer."
-
- (let ((inhibit-read-only t)
- (cite-marks gnus-outlook-deuglify-cite-marks))
- (gnus-with-article-buffer
- (article-goto-body)
-
- (unless (= (point) attr-start)
- (gnus-kill-all-overlays)
- (let ((cur (point))
-
- (to (if (gnus-article-search-signature)
- (point)
- (point-max))))
-
-
- (when (< to attr-start)
- (setq to (point-max)))
- (save-excursion
- (narrow-to-region attr-start to)
- (goto-char attr-start)
- (forward-line)
- (unless (looking-at ">")
- (message-indent-citation (point) (point-max) 'yank-only)
- (goto-char (point-max))
- (newline)
- (setq to (point-max)))
- (widen))
- (transpose-regions cur attr-start attr-start to))))))
- (defun gnus-outlook-repair-attribution-outlook ()
- "Repair a broken attribution line (Outlook)."
- (let ((case-fold-search nil)
- (inhibit-read-only t)
- (cite-marks gnus-outlook-deuglify-cite-marks))
- (gnus-with-article-buffer
- (article-goto-body)
- (when (re-search-forward
- (concat "^\\([^" cite-marks "].+\\)"
- "\\(" gnus-outlook-deuglify-attrib-verb-regexp "\\)"
- "\\(.*\n?[^\n" cite-marks "].*\\)?"
- "\\(" gnus-outlook-deuglify-attrib-end-regexp "\\)$")
- nil t)
- (gnus-kill-all-overlays)
- (replace-match "\\1\\2\\4")
- (match-beginning 0)))))
- (defun gnus-outlook-repair-attribution-block ()
- "Repair a big broken attribution block."
- (let ((case-fold-search nil)
- (inhibit-read-only t)
- (cite-marks gnus-outlook-deuglify-cite-marks))
- (gnus-with-article-buffer
- (article-goto-body)
- (when (re-search-forward
- (concat "^[" cite-marks " \t]*--* ?[^-]+ [^-]+ ?--*\\s *\n"
- "[^\n:]+:[ \t]*\\([^\n]+\\)\n"
- "\\([^\n:]+:[ \t]*[^\n]+\n\\)+")
- nil t)
- (gnus-kill-all-overlays)
- (replace-match "\\1 wrote:\n")
- (match-beginning 0)))))
- (defun gnus-outlook-repair-attribution-other ()
- "Repair a broken attribution line (other user agents than Outlook)."
- (let ((case-fold-search nil)
- (inhibit-read-only t)
- (cite-marks gnus-outlook-deuglify-cite-marks))
- (gnus-with-article-buffer
- (article-goto-body)
- (when (re-search-forward
- (concat "^\\("gnus-outlook-deuglify-attrib-cut-regexp"\\)?"
- "\\([^" cite-marks "].+\\)\n\\([^\n" cite-marks "].*\\)?"
- "\\(" gnus-outlook-deuglify-attrib-verb-regexp "\\).*"
- "\\(" gnus-outlook-deuglify-attrib-end-regexp "\\)$")
- nil t)
- (gnus-kill-all-overlays)
- (replace-match "\\4 \\5\\6\\7")
- (match-beginning 0)))))
- (defun gnus-article-outlook-repair-attribution (&optional nodisplay)
- "Repair a broken attribution line.
- If NODISPLAY is non-nil, don't redisplay the article buffer."
- (interactive "P")
- (let ((attrib-start
- (or
- (gnus-outlook-repair-attribution-other)
- (gnus-outlook-repair-attribution-block)
- (gnus-outlook-repair-attribution-outlook))))
- (unless nodisplay (gnus-outlook-display-article-buffer))
- attrib-start))
- (defun gnus-article-outlook-rearrange-citation (&optional nodisplay)
- "Repair broken citations.
- If NODISPLAY is non-nil, don't redisplay the article buffer."
- (interactive "P")
- (let ((attrib-start (gnus-article-outlook-repair-attribution 'nodisplay)))
-
- (if attrib-start
- (gnus-outlook-rearrange-article attrib-start)))
- (unless nodisplay (gnus-outlook-display-article-buffer)))
- (defun gnus-outlook-deuglify-article (&optional nodisplay)
- "Full deuglify of broken Outlook (Express) articles.
- Treat dumbquotes, unwrap lines, repair attribution and rearrange citation. If
- NODISPLAY is non-nil, don't redisplay the article buffer."
- (interactive "P")
-
- (gnus-article-treat-dumbquotes)
-
- (gnus-article-outlook-unwrap-lines 'nodisplay)
-
- (gnus-article-outlook-rearrange-citation 'nodisplay)
- (unless nodisplay (gnus-outlook-display-article-buffer)))
- (defun gnus-article-outlook-deuglify-article ()
- "Deuglify broken Outlook (Express) articles and redisplay."
- (interactive)
- (gnus-outlook-deuglify-article nil))
- (provide 'deuglify)
|