[bug#63802,1/3] client: Separate serialize-email-address into a function.
Commit Message
* mumi/client.scm (serialize-email-address): New function.
(reply-email-headers): Use serialize-email-address.
* tests/client.scm (serialize-email-address): New variable.
("serialize email address", "serialize email address with comma in
name"): New tests.
---
mumi/client.scm | 14 ++++++++++----
tests/client.scm | 11 +++++++++++
2 files changed, 21 insertions(+), 4 deletions(-)
Comments
Hi Arun!
Arun Isaac <arunisaac@systemreboot.net> writes:
> * mumi/client.scm (serialize-email-address): New function.
> (reply-email-headers): Use serialize-email-address.
> * tests/client.scm (serialize-email-address): New variable.
> ("serialize email address", "serialize email address with comma in
> name"): New tests.
LGTM!
@@ -221,6 +221,14 @@ arguments."
(unless (zero? (close-pipe port))
(error "Command invocation failed" command))))))))
+(define (serialize-email-address name address)
+ "Combine NAME and ADDRESS into a complete email address of the form
+\"NAME <ADDRESS>\". Double quote NAME if necessary."
+ (string-append (if (string-contains name ",")
+ (string-append "\"" name "\"")
+ name)
+ " <" address ">"))
+
(define* (git-send-email to patches #:optional (options '()))
"Send PATCHES using git send-email to the TO address with
@@ -269,10 +277,8 @@ ISSUE-NUMBER."
,@(match (delete-duplicates
(map (lambda (message)
(let ((from (assoc-ref message "from")))
- (string-append (if (string-contains (assoc-ref from "name") ",")
- (string-append "\"" (assoc-ref from "name") "\"")
- (assoc-ref from "name"))
- " <" (assoc-ref from "address") ">")))
+ (serialize-email-address (assoc-ref from "name")
+ (assoc-ref from "address"))))
(vector->list (assoc-ref issue "messages"))))
(() (list))
(cc (list (cons 'cc (string-join cc ", "))))))))
@@ -65,8 +65,19 @@ called with."
(lambda _
(error "Do not poll server for issue number"))))
+(define serialize-email-address
+ (@@ (mumi client) serialize-email-address))
+
(test-begin "client")
+(test-equal "serialize email address"
+ "Foo <foo@example.com>"
+ (serialize-email-address "Foo" "foo@example.com"))
+
+(test-equal "serialize email address with comma in name"
+ "\"Bar, Foo\" <foobar@example.com>"
+ (serialize-email-address "Bar, Foo" "foobar@example.com"))
+
(test-equal "send patches to new issue"
'(("git" "send-email" "--to=foo@patches.com" "foo.patch")
("git" "send-email" "--to=12345@example.com" "bar.patch" "foobar.patch"))