Commit graph

65 commits

Author SHA1 Message Date
9724a2b523
Introducing Msg part deletion
This PR introduces a new struct field for the message parts: `del`

If the del flag is set to `true`, the msgWriter will ignore this part during the writing process.

Additionally, the `part` has now a `Delete` method that lets the user mark the part as deleted

This allows middleware to take further control of the Msg and is part of #107
2023-01-28 14:39:14 +01:00
3922d3f195
Switched copyright header from me to "The go-mail Authors" 2023-01-15 16:14:19 +01:00
5897bddd11
Update msg.go
Co-authored-by: iwittkau <iwittkau@users.noreply.github.com>
2023-01-02 22:29:10 +01:00
dbb596893d
Update msg.go
Co-authored-by: iwittkau <iwittkau@users.noreply.github.com>
2023-01-02 22:28:39 +01:00
f6709e90cd
Make golangci-lint happy by using errors.As instead of using type assertion on error (which can fail on wrapped errors) 2023-01-01 14:25:00 +01:00
78df991399
Proposal change for #90
Did a complete overhaul of the senderror.go.

- the list of `errors.New()` has been replaced with constant itoa error reasons as `SendErrReason`. Instead, the `Error()` method now reports the corresponding error message based on the reason.
- The `SendError` received a `Is()` method so that we can use `errors.Is()` for very specific error checking. I.e. we can check for `&SendErrors{Reason: ErrSMTPMailFrom, isTemp: true}`. This provides much more flexibility in the error checking capabilities
- A `isTemp` field has been added to the `SendError` type, indicating whether the received error is temporary and can be retried or not. Accordingly, the `*Msg` now has a `SendErrorIsTemp()` method indicating the same. The decision is based on the first 3 characters returned from the SMTP server. If the error code is within the 4xx range, the error is seen as temporary
- A test for the SendError type has been added
2023-01-01 14:20:13 +01:00
47bff15de9
Introduction of a Msg error type as proposal for #90
This PR introduces the `SendError` type which implements the error interface.

A new `senderror` field has been added to the `Msg` as well, so introduce this type to it.

I've also added different error variables that indicate the different things that can go wrong during mail delivery. These variables can be checked for, for each `Msg` using the `errors.As` method

The `Error()` method of `SendError` will return a detailed error string on why the `Msg` could not be delivered.

Additionally, `HasSendError()` and `SendError()` methods have been added to `Msg`. While `HasSendError()` simply returns a bool in case a `Msg` failed during delivery, the `SendError()` will return the full `SendError` error interface.
2022-12-31 12:40:42 +01:00
17b9d2ccf6
#80: GetAddrHeader and SetGenHeader
This PR introduces two major changes:

* SetHeader and SetHeaderPreformatted have been deprecated in favour of SetGenHeader and SetGenHeaderPreformatted
  As pointed out in #80 the naming was pretty confusing, given that we already have SetAddrHeader. With the new naming convention it should be more clear. For compatibility reasons the old methods have been kept for now but in reality they are just aliases to the new methods
* GetAddrHeader and GetAddrHeaderString have been introduced
  As requested in #80 analogous to GetGenHeader we also need a similar method for the address headers. Since address headers are *mail.Address pointer, we've also added a *String method that will extract the address string and return a string slice instead
  Additionally we're introducing methods for the actual address headers: GetTo, GetFrom, GetCc and GetBcc (with a *String counterpart as well). This way the user has full flexibility. Either they use the more "low-level" GetAddrHeader method or the higher level methods for the corresponding address type
2022-11-19 11:22:20 +01:00
d327ca73e4
The new messageID generated with #76 is a bit too long by default. This patch reduces the length 2022-10-26 15:48:48 +02:00
2e60d070a6
Add SetHeaderPreformatted() method
With the SetHeaderPreformatted() method we have the ability to set headers that are already preformatted by the user and will not be altered in the mail message output
2022-10-26 15:33:03 +02:00
8484e557d0
Replace math/rand with crypto/rand
Since the Windows tests were still failing, we are replacing the random number generation with math/rand with random string generation via crypto/rand
2022-10-26 14:05:25 +02:00
5bf0c10525
Randomness apparently not good enough for windows. Tests were failing. This fix improves it 2022-10-26 13:43:51 +02:00
021e003e78
Closes #74
This fix makes sure that generated message IDs via SetMessageID() are truly random and unique
2022-10-26 11:59:03 +02:00
2bd6851c78
Fix in the storage of the original Middleware 2022-10-25 16:56:40 +02:00
6f93e5835e
Introducing MiddlewareType and WriteToSkipMiddleware
For middlewares to be able to access the fully written mail message, we need a way to execute WriteTo without the calling middleware to be handled, otherwise we end up in an infinite loop

Therefore, this PR introduces the MiddlewareType and the corresponding change of the Middleware interface. We now require to return the MiddlewareType when the Type() method on the interface is called

This way we can also introduce the WriteToSkipMiddleware method which takes a MiddlewareType as argument. This will allow us to use a WriteTo call with the initiating Middleware to be skipped
2022-10-25 16:42:18 +02:00
b6beeb5cae
Finalized the Reader type and removed the broken Read() method 2022-10-20 18:26:51 +02:00
183fb347d6
Fix create header maps in case SetHeader or SetAddrHeader is called on an empty Msg type 2022-10-20 18:06:26 +02:00
5faa6dfbd6
We now return a Reader instead of the io.Reader interface 2022-10-20 18:03:57 +02:00
966615584d
Implement a proper io.Reader interface since the current implementation is flawed 2022-10-20 15:52:53 +02:00
Dhia Gharsallaoui
b94a42ebe8
Expose Msg attachments fields 2022-10-12 13:36:52 +02:00
dbe58745be
#60 Working on Get/Set methods to access the Msg part slice
Still some tests needed
2022-10-11 17:05:44 +02:00
cd2ee86846
Added GetGenHeader to the Msg to grant read access to set generic headers (e g. to use in Middlewares) 2022-10-02 12:25:49 +02:00
dhia gharsallaoui
a4733f0618 Implement middleware concept and their test 2022-09-22 18:05:47 +02:00
c1d4dbedee
Remove not needed loop from RequestMDNAddTo 2022-09-09 11:39:08 +02:00
46001dc691
Added support for requesting MDNs as described in RFC 8098 2022-09-09 11:35:45 +02:00
192627f6a5
Closes #29: Allow attaching/embedding from embed.FS
- Added `EmbedFromEmbedFS()` to allow embedding from embed.FS
- Added `AttachFromEmbedFS()` to allow attaching from embed.FS
- Added `fileFromEmbedFS()` as internal method for both other m
  methods to attach/embed the embed.FS file
2022-07-07 10:46:57 +02:00
31001e87b2
#24: Add SPDX license IDs for REUSE compliance
# SUMMARY

* Bad licenses:
* Deprecated licenses:
* Licenses without file extension:
* Missing licenses:
* Unused licenses:
* Used licenses: CC0-1.0, MIT
* Read errors: 0
* Files with copyright information: 45 / 45
* Files with license information: 45 / 45

Congratulations! Your project is compliant with version 3.0 of the REUSE Specification :-)
2022-06-17 15:05:54 +02:00
a50910b943
#21: Add possbility to set dedicated envelope from address
- Added `EnvelopeFrom()` and `EnvelopeFromFormat()` methods analogous to the `From()` `FromFormat()` methods
- Changed MsgWriter logic for envelope from addresses
- Adjusted `Msg.GetSender()` to return the envelope from first and only mail body from if the envelope is not set
2022-06-13 10:18:35 +02:00
95100545d6
#18: Added Msg.WriteToFile which allows storing the Msg in a file 2022-06-06 16:43:04 +02:00
97e1386e36
Code smell fix for #13
SonarQube identified two code smells for duplicate string usage
2022-06-03 12:27:26 +02:00
08cf367772
#13: Avoid nil pointer references in template handling 2022-06-03 11:08:33 +02:00
8919d64ca1
#13: Both html/template and text/template support added
- Switched the previous implementation to support text/template as well as html/template
- Added SetBody*Template() methods to use a template directly as message body
- Added AddAlternative*Template() methods to use a template directly as alternative message part
2022-06-03 10:40:54 +02:00
f24a86a4c6
Fix spelling 2022-06-02 16:22:48 +02:00
645ad2ce93
#13 Allow attaching/embedding templates
Implemented the AttachTemplate and EmbedTemplate methods.
Test coverage and documentation is still to be done
2022-06-01 16:49:34 +02:00
dd02ac229b
Closes #11
This PR adds a `Msg.Read()` method which satisfies the `io.Reader` interface
2022-05-28 10:58:19 +02:00
ebef1fe476
Fixes #8
We were using `io.Copy` to write to the body string/alternative string to the io.Writer. This placed the byte position of the buffer to be at the EOF after the first `WriteTo()` call leaving the output of a 2nd call to `WriteTo()` empty.
2022-05-27 12:47:33 +02:00
inliquid
4fe503d142 - Stderr should be read after closing Stdin
- Fix reading of Stderr contents
- Remove redundand calls to `Close`
2022-05-26 14:37:23 +03:00
fa7066c9cf
Update path to sendmail binary
On most systems sendmail is located in /usr/sbin not /usr/bin
2022-05-25 10:53:37 +02:00
070eb39132
Address #5
For the WriteToSendmail* methods the STDIN pipe should be closed so that a forced EOF is sent to the sending program
2022-05-25 10:46:50 +02:00
894ff7128c
Rename Write() to WriteTo() so it satisfies the io.WriteTo interface 2022-05-24 15:46:59 +02:00
030eba8cfd
Default header and sorting
- Default headers are set in its own method now
- Generic headers are now sorted before being written
2022-03-20 19:11:58 +01:00
b852a5281a
v0.1.6: Fix in writeHeader() and User-Agent
- The writeHeader() method wasn't producing good output for long headers. This has been fixed
- Added a VERSION string to the library
- If both no User-Agent and no X-Mailer header are set, the lib adds a default UA-header
2022-03-20 17:38:46 +01:00
b6d90eac6a
*Reader() methods don't need to check for nil, as the underlying fileFromReader does never return nil 2022-03-19 16:55:30 +01:00
e379128c83
Still trying to fix the GH issues with MacOS' broken pipe 2022-03-18 23:28:11 +01:00
0e00b165f9
WriteToSendmailWithContext tests revealed a race condition which has been fixed 2022-03-18 22:23:03 +01:00
3c642be4eb
Added WriteToSendmailWithCommand which is more generic and takes a command to sendmail
The code of WriteToSendmail has been refactored to return the new WriteToSendmailWithCommand using SendmailPath
2022-03-18 21:07:07 +01:00
709b4e6b91
Switched write functions to return the number of bytes. Due to failing tests in Msg.Write() 2022-03-18 17:08:05 +01:00
f8a9512462
More tests for msg.go 2022-03-18 11:47:50 +01:00
a87577d388
Attachment names should probably be encoded 2022-03-15 12:12:45 +01:00
ce1c37bd16
Check if Attachments/Embeds can be read. If an error occurs don't add them to the mail parts 2022-03-15 11:56:21 +01:00