Skip to content

Commit

Permalink
Merge pull request #3 from DavidVujic/wrap
Browse files Browse the repository at this point in the history
Wrap querying features to be accessible from the email namespace
  • Loading branch information
DavidVujic authored Feb 12, 2021
2 parents 7b7df5b + 4a3ff3f commit e1449e2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## [1.2.1] - 2021-02-12
Wrap querying features from the `query` namespace in the `email` namespace.

## [1.2.0] - 2021-02-12
Add `query` namespace, that can be used to extract file names or find an attachment by name.

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ email/pdf?
email/xml?
```

There is also a `query` namespace that can be used to extract file names or find an attachment by name:
There are also querying helpers, that can be used to extract file names or find an attachment by name:

``` clojure
(query/filenames content-types) ;; pass in the result from the email/content-types function
(query/filename content-type) ;; pass in one item from the seq of email/content-types result
(email/filenames content-types) ;; pass in the result from the email/content-types function
(email/filename content-type) ;; pass in one item from the seq of email/content-types result

(query/find-in content-types "my-filename.csv")
(email/find-in content-types "my-filename.csv")
```

Example output from the `email/content-types` function:
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject email-attachments "1.2.0"
(defproject email-attachments "1.2.1"
:description "makes extracting email attachments simple"
:url "https://github.com/DavidVujic/email-attachments"
:license {:name "The MIT License (MIT)"
Expand Down
12 changes: 11 additions & 1 deletion src/email_attachments/email.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns email-attachments.email
(:require [clojure.string :as str]
[email-attachments.message :as message]))
[email-attachments.message :as message]
[email-attachments.query :as query]))

(defn- content-type? [m type]
(-> m
Expand Down Expand Up @@ -38,3 +39,12 @@
(->> email-input-stream
message/stream->mime-message
message/body))

(defn filename [message-map]
(query/filename message-map))

(defn filenames [content-types]
(query/filenames content-types))

(defn find-in [content-types filename]
(query/find-in content-types filename))
9 changes: 4 additions & 5 deletions test/email_attachments/email_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns email-attachments.email-test
(:require [clojure.java.io :as io]
[email-attachments.email :as email]
[email-attachments.query :as query]))
[email-attachments.email :as email]))

(comment
(->> "emails/example2.eml"
Expand All @@ -20,18 +19,18 @@
io/input-stream
email/content-types
first
query/filename))
email/filename))

(comment
(->> "emails/example2.eml"
io/input-stream
email/content-types
query/filenames))
email/filenames))

(comment
(def content-types (->> "emails/example4.eml"
io/input-stream
email/content-types))

(def filename "email-exempel.csv")
(query/find-in content-types filename))
(email/find-in content-types filename))

0 comments on commit e1449e2

Please sign in to comment.