From: Ted Zlatanov <tzz@lifelogs.com>
To: ding@gnus.org
Subject: netrc parser revamp (was: gmail and pop3)
Date: Mon, 10 Jun 2013 02:26:42 -0400 [thread overview]
Message-ID: <m27gi2eb19.fsf_-_@lifelogs.com> (raw)
In-Reply-To: <87li6nru50.fsf@lifelogs.com>
On Thu, 06 Jun 2013 14:06:35 -0400 Ted Zlatanov <tzz@lifelogs.com> wrote:
TZ> After sending this, I saw bug#12097 which has some background on this.
TZ> So definitely a TODO for me is to rewrite that parser. Sorry for the
TZ> trouble.
Take a look at the following. It implements a parser that will go
through the current buffer and extract all the netrc entries, respecting
multiline entries and other weird things. Also, netrc used single
quotes (double quotes are a Gnusism apparently), so this supports both
single and double quotes. Entries must start with "machine" which is
required in the netrc format.
It doesn't treat "macdef" entries especially because I have never seen
them used by anyone and didn't want the extra complexity. If you feel
they must be supported, speak up.
e.g. try it on this netrc content:
#+begin_src text
machine A login tzz@lifelogs.com password "A lovely A"
# test again
machine B login tzz@lifelogs.com
password 'B single quotes B'
default other info goes here
#+end_src
If this works as expected I'll put it into auth-source.el. So please
try it on your weird wacky netrc files :)
Thanks
Ted
#+begin_src lisp
(defun auth-source-netrc-parse-next-interesting ()
"Advance to the next interesting position in the current buffer."
;; If we're looking at a comment or are at the end of the line, move forward
(while (or (looking-at "#")
(and (eolp)
(not (eobp))))
(forward-line 1))
(skip-chars-forward "\t "))
(defun auth-source-netrc-parse-one ()
"Read one thing from the current buffer."
(auth-source-netrc-parse-next-interesting)
(when (or (looking-at "'\\([^']+\\)'")
(looking-at "\"\\([^\"]+\\)\"")
(looking-at "\\([^ \t\n]+\\)"))
(forward-char (length (match-string 0)))
(auth-source-netrc-parse-next-interesting)
(match-string-no-properties 1)))
(defun auth-source-netrc-parse-entries ()
"Parse all the netrc entries from the current buffer."
(let (item item2 all alist default)
(while (setq item (auth-source-netrc-parse-one))
(setq default (equal item "default"))
;; We're starting a new machine. Save the old one.
(when (or default
(equal item "machine"))
(when alist
(push alist all))
(setq alist nil))
;; In default entries, we don't have a next token.
;; We store them as ("machine" . t)
(if default
(push (cons "machine" t) alist)
;; Not a default entry. Grab the next item.
(when (setq item2 (auth-source-netrc-parse-one))
(push (cons item item2) alist))))
(when alist
(push alist all))
(nreverse all)))
#+end_src
next prev parent reply other threads:[~2013-06-10 6:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-01 18:57 gmail and pop3 Alex Romosan
2013-03-01 20:33 ` John Wiegley
2013-03-01 23:29 ` Alex Romosan
2013-06-06 15:43 ` Ted Zlatanov
2013-06-06 18:06 ` Ted Zlatanov
2013-06-10 6:26 ` Ted Zlatanov [this message]
2013-06-15 8:04 ` netrc parser revamp Ted Zlatanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m27gi2eb19.fsf_-_@lifelogs.com \
--to=tzz@lifelogs.com \
--cc=ding@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).