- "Parse FILE and return an list of all entries in the file."
- (when (file-exists-p file)
- (with-temp-buffer
- (let ((tokens '("machine" "default" "login"
- "password" "account" "macdef" "force"
- "port"))
- alist elem result pair)
- (if (and netrc-encrypting-method
- netrc-openssl-path)
- (let ((buffer-file-coding-system 'binary)
- (coding-system-for-read 'binary)
- (coding-system-for-write 'binary)
- (password
- (password-read
- (format "OpenSSL Password for cipher %s? "
- netrc-encrypting-method)
- (format "netrc-openssl-password-%s"
- netrc-encrypting-method))))
- (when password
- (insert-file-contents file)
- (setenv "NETRC_OPENSSL_PASSWORD" password)
- (shell-command-on-region
- (point-min)
- (point-max)
- (format "%s %s -pass env:NETRC_OPENSSL_PASSWORD -d"
- netrc-openssl-path
- netrc-encrypting-method)
- t
- t)))
- (insert-file-contents file))
- (goto-char (point-min))
- ;; Go through the file, line by line.
- (while (not (eobp))
- (narrow-to-region (point) (point-at-eol))
- ;; For each line, get the tokens and values.
+ "Parse FILE and return a list of all entries in the file."
+ (unless file
+ (setq file netrc-file))
+ (if (listp file)
+ ;; We got already parsed contents; just return it.
+ file
+ (when (file-exists-p file)
+ (with-temp-buffer
+ (let ((tokens '("machine" "default" "login"
+ "password" "account" "macdef" "force"
+ "port"))
+ alist elem result pair)
+ (if (and netrc-cache
+ (equal (car netrc-cache) (nth 5 (file-attributes file))))
+ (insert (base64-decode-string (rot13-string (cdr netrc-cache))))
+ (insert-file-contents file)
+ (when (string-match "\\.gpg\\'" file)
+ ;; Store the contents of the file heavily encrypted in memory.
+ (setq netrc-cache (cons (nth 5 (file-attributes file))
+ (rot13-string
+ (base64-encode-string
+ (buffer-string)))))))
+ (goto-char (point-min))
+ ;; Go through the file, line by line.