Browse Source

Better documentation and a bit of debug logging

master
Stephen Starkey 2 years ago
parent
commit
66eb7ec087
  1. 2
      env/test/resources/logback.xml
  2. 13
      src/clj/email_counter/emails.clj

2
env/test/resources/logback.xml

@ -26,7 +26,7 @@
</appender>
<logger name="org.apache.http" level="warn" />
<logger name="org.xnio.nio" level="warn" />
<root level="DEBUG">
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>

13
src/clj/email_counter/emails.clj

@ -1,19 +1,22 @@
(ns email-counter.emails
(:require [clojure.string :as str]
[schema.core :as s])
[schema.core :as s]
[clojure.tools.logging :as log])
(:import (javax.mail.internet AddressException InternetAddress)))
(s/defn parse-email :- (s/maybe s/Str)
"Attempt to get the address portion of an assumed rfc822-compliant email
address. If we can't, we return nil."
address. If we can't, return nil"
[email :- (s/maybe s/Str)]
(try
(when email (-> email InternetAddress. .getAddress))
(catch AddressException _)))
(catch AddressException e
(log/debug e "Invalid email address"))))
(s/defn parse-for-gmail :- (s/maybe s/Str)
"Given a valid email address, strip any periods and any content after a +
from the name portion. If the email is nil, we will simply return nil"
from the name portion. If there is anything left from the name portion,
return that concatenated onto the domain. Otherwise, return nil"
[email :- (s/maybe s/Str)]
(let [email (parse-email email)
[_ n d] (when email (re-matches #"^(.*?)(@[^@]+$)" email))
@ -32,6 +35,6 @@
(s/defn count-unique :- s/Int
"Given a bunch of email addresses, count the number of unique ones, given
Gmail's special parsing rules."
Gmail's special parsing rules"
[emails :- [(s/maybe s/Str)]]
(count (unique-gmail-parsed-set emails)))
Loading…
Cancel
Save