* guile: add format 'quoted' to contacts, use it in the example script

This commit is contained in:
djcb
2012-06-06 08:17:24 +03:00
parent 15d31f75c9
commit e87b5fd248
2 changed files with 15 additions and 2 deletions

View File

@ -41,7 +41,7 @@ exec guile -e main -s $0 $@
(options (getopt-long args optionspec)) (options (getopt-long args optionspec))
(msg (string-append (msg (string-append
"usage: contacts-export [--help] [--muhome=<muhome>] " "usage: contacts-export [--help] [--muhome=<muhome>] "
"--format=<org-contact|mutt-alias|mutt-ab|wanderlust|plain(*)> " "--format=<org-contact|mutt-alias|mutt-ab|wanderlust|quoted|plain(*)> "
"--sort-by=<frequency(*)|newness> [--revert] [--limit=<n>]\n")) "--sort-by=<frequency(*)|newness> [--revert] [--limit=<n>]\n"))
(help (option-ref options 'help #f)) (help (option-ref options 'help #f))
(muhome (option-ref options 'muhome #f)) (muhome (option-ref options 'muhome #f))
@ -65,6 +65,7 @@ exec guile -e main -s $0 $@
;; make a list of all contacts ;; make a list of all contacts
(mu:for-each-contact (mu:for-each-contact
(lambda (c) (set! contacts (cons c contacts)))) (lambda (c) (set! contacts (cons c contacts))))
;; should we sort it? ;; should we sort it?
(if sort-by (if sort-by
(set! contacts (sort! contacts (set! contacts (sort! contacts

View File

@ -22,6 +22,7 @@
(define-module (mu contact) (define-module (mu contact)
:use-module (oop goops) :use-module (oop goops)
:use-module (mu message) :use-module (mu message)
:use-module (texinfo string-utils)
:export ( :export (
<mu:contact> <mu:contact>
mu:name mu:name
@ -104,7 +105,7 @@ matching EXPR."
(define-method (mu:contact->string (contact <mu:contact>) (form <string>)) (define-method (mu:contact->string (contact <mu:contact>) (form <string>))
"Convert a contact to a string in format FORM, which is a string, "Convert a contact to a string in format FORM, which is a string,
either \"org-contact\", \"mutt-alias\", \"mutt-ab\", either \"org-contact\", \"mutt-alias\", \"mutt-ab\",
\"wanderlust\" \"plain\"." \"wanderlust\", \"quoted\" \"plain\"."
(let* ((name (mu:name contact)) (email (mu:email contact)) (let* ((name (mu:name contact)) (email (mu:email contact))
(nick ;; simplistic nick guessing... (nick ;; simplistic nick guessing...
(string-map (string-map
@ -126,4 +127,15 @@ either \"org-contact\", \"mutt-alias\", \"mutt-ab\",
((string= form "mutt-ab") ((string= form "mutt-ab")
(format #f "~a\t~a\t" (format #f "~a\t~a\t"
email (or name ""))) email (or name "")))
((string= form "quoted")
(string-append
"\""
(escape-special-chars
(string-append
(if name
(format #f "\"~a\" " name)
"")
(format #f "<~a>" email))
"\"" #\\)
"\""))
(else (error "Unsupported format"))))) (else (error "Unsupported format")))))