1
- # Letters, an email parsing package for go
1
+ # Letters
2
+ an email parsing package for go
2
3
3
4
This is a fork of [ mnako/letters] ( https://github.com/mnako/letters ) , a
4
- minimalistic Golang library for parsing plaintext and MIME emails.
5
+ minimalistic Golang library for parsing plain and MIME emails. Thanks to
6
+ @mnako and contributors, letters has great support for languages other
7
+ than English, text and transfer encodings.
5
8
6
- Thanks to @mnako and contributors, letters has great support for
7
- languages other than English, text encodings and transfer-encodings.
9
+ This fork (forked at
10
+ [ "db1b793c8119d8ed3d575f44df4391262829d1a5"] ( https://github.com/mnako/letters/commit/db1b793c8119d8ed3d575f44df4391262829d1a5 )
11
+ version v0.2.3) focuses on extensibility through modularisation as set
12
+ out in [ PR #124 ] ( https://github.com/mnako/letters/pull/124 ) . This
13
+ library also provides improved performance and customisation through
14
+ user-defined funcs, for example for efficient attachment processing.
8
15
9
- This fork focuses on performance, memory efficiency and extensibility
10
- through modularisation.
16
+ Future plans include making parsing errors, such as for invalid email
17
+ addresses, optionally non-fatal.
18
+
19
+ github.com/rorycl/letters v0.1.1 10 February 2025
11
20
12
21
## Quickstart
13
22
@@ -132,19 +141,34 @@ parsedEmail, err := p.Parse(reader)
132
141
Various options are provided for customising the Parser, including:
133
142
134
143
``` go
144
+ // skip content types
145
+ func WithSkipContentTypes (skipContentTypes []string ) Opt
146
+ // provide a custom address processing function
135
147
func WithCustomAddressFunc(af func(string) (*mail.Address, error)) Opt
148
+ // provide a custom processing function for string lists of addresses
136
149
func WithCustomAddressesFunc(af func(list string) ([]*mail.Address, error)) Opt
150
+ // provide a custom date processing function
137
151
func WithCustomDateFunc(df func(string) (time.Time, error)) Opt
152
+ // provide a custom file processing function
138
153
func WithCustomFileFunc(ff func(*email.File) error) Opt
154
+ // save files to the stated directory (an example of WithCustomFileFunc)
139
155
func WithSaveFilesToDirectory(dir string) Opt
156
+ // only process headers
140
157
func WithHeadersOnly() Opt
158
+ // skip processing attachments
141
159
func WithoutAttachments() Opt
160
+ // show verbose processing info (currently a noop)
142
161
func WithVerbose() Opt
143
162
```
144
163
164
+ More than one option can be supplied.
165
+
145
166
The `WithoutAttachments` and `WithHeadersOnly` options determine if only part
146
167
of an email will be processed.
147
168
169
+ The `WithSkipContentTypes` allows the user to skip processing MIME
170
+ message parts with the supplied content-types.
171
+
148
172
The date and address "With" options allow the provision of custom funcs to
149
173
override the `net/mail` funcs normally used. For example it might be necessary
150
174
to extend the date parsing capabilities to deal with poorly formatted date
@@ -169,4 +193,3 @@ if err != nil {
169
193
return fmt.Errorf (" error while parsing email headers: %s " , err)
170
194
}
171
195
```
172
-
0 commit comments