- (goto-char (point-min))
- (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
- (let ((fromstring (buffer-substring (match-beginning 1) (match-end 1))))
- (cond
-
- ;; Try first to match addresses that look like
- ;; thompson@wg2.waii.com (Jim Thompson)
- ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
- (substring fromstring (match-beginning 1) (match-end 1)))
-
- ;; Next try to match addresses that look like
- ;; Jim Thompson <thompson@wg2.waii.com> or
- ;; "Jim Thompson" <thompson@wg2.waii.com>
- ((string-match "\\(\"?\\)\\(.*\\)\\1[ \t]+<.*>" fromstring)
- (substring fromstring (match-beginning 2) (match-end 2)))
-
- ;; Couldn't find a real name -- show the address instead.
- (t fromstring)))
- "From ???")))
-
-;; A hook to bind to `gnus-article-prepare-hook'. This will set the
-;; `ps-left-headers' specially for gnus articles. Unfortunately,
+ (save-restriction
+ (narrow-to-region (point-min) (progn (rfc822-goto-eoh) (point)))
+ (let ((fromstring (mail-fetch-field "From")))
+ (cond
+ ;; Try first to match addresses that look like
+ ;; thompson@wg2.waii.com (Jim Thompson)
+ ((and fromstring (string-match ".*[ \t]+(\\(.*\\))" fromstring))
+ (match-string 1 fromstring))
+ ;; Next try to match addresses that look like
+ ;; Jim Thompson <thompson@wg2.waii.com> or
+ ;; "Jim Thompson" <thompson@wg2.waii.com>
+ ((and fromstring
+ (string-match "\\(\"?\\)\\(.*\\)\\1[ \t]+<.*>" fromstring))
+ (match-string 2 fromstring))
+ ;; Couldn't find a real name -- show the address instead.
+ (fromstring)
+ (t "From ???"))))))
+
+;; A hook to bind to `gnus-article-prepare-hook'. This will set
+;; `ps-left-header' specially for gnus articles. Unfortunately,