aboutsummaryrefslogtreecommitdiff
path: root/lib/email/message.go
AgeCommit message (Collapse)Author
2025-01-23all: use for-range with numericShulhan
Go 1.22 now support for-range on numeric value.
2025-01-22lib/bytes: replace Copy and Concat with standard libraryShulhan
Since Go 1.20, the standard bytes package have the Copy function. Since Go 1.22, the standard slices package have the Concat function.
2024-08-04lib/email: export the field Fields in HeaderShulhan
By exporting the field, this allow the caller to filter or manage the Header Fields manually.
2024-08-03lib/email: decode the message body based on content-transfer-encodingShulhan
After the header and body has been parsed, if the header contains Content-Transfer-Encoding, we decode the body into its local formats. Currently supported encoding is "quoted-printable" and "base64".
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-07-14lib/email: refactoring, replace field with type []byte to stringShulhan
Using string provide safety, guaranteed that if we pass it as parameter the receiver will not be able to modify its content.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-04-06all: replace any usage of ioutil package with os or ioShulhan
Since Go 1.16, the ioutil package has been deprecated. This changes replace any usage that use functions from ioutil package with their replacement from package os or package io.
2022-02-28lib/email: set the Date and Message-ID on Message PackShulhan
Calling Pack now set the Date header if its not exist, using the local time; and the message-id header if its not exist using the following format: <epoch>.<random-8-chars>@<local-hostname> The random-8-chars is Seed-ed from Epoch(), so does the boundary.
2022-02-27lib/email: make Message Pack works with single text or HTML partShulhan
Previouly, the Pack method generate multipart/alternative message only. Since the Message now can set the body text and HTML, without using NewMultipart, the Pack method need to be able to accomodate this.
2022-02-27lib/email: make the NewMultipart test working by mocking EpochShulhan
Previously, we skip the test on NewMultipart because it use a random number generator to generate boundary. This changes make the test predictable by setting the Epoch and date to always in UTC, so anyone who run test on the package run without fail.
2022-02-27lib/email: add methods to modify MessageShulhan
Previously, a Message can be created only using NewMultipart, which generate message with text and HTML. This changes add methods to compose a Message: AddCC, AddTo, SetBodyHtml, SetBodyText, SetCC, SetFrom, SetSubject, and SetTo.
2022-02-25lib/email: change the Header and Body fields on Message to non-pointerShulhan
The idea is to minimize GC pressure on system with many messages, minimize checking for nil value, and make an empty Message ready to use without any initialization.
2022-02-24lib/email: set the header Date field on NewMultipartShulhan
The Date field value is set to current time on the system that generated the message. The date format is set to "Mon, 2 Jan 2006 15:04:05 -0700" according to RFC 5322 section 3.3.
2020-05-14email: add function to create multipart text and HTML messageShulhan
The NewMultipart() function create new email message using primary fields "from", "to", "subject" with content-type is set to "multipart/alternative".
2019-10-21all: fix and add missing commentsShulhan
2019-03-05bytes: change the Copy return type to non pointerShulhan
Non pointer slice is less confusing than with pointer.
2019-02-15email: implement signing message with DKIM methodShulhan
Everything seems like works in order, we need more test will real life message.
2019-02-14email: remove header.String() in favor of Simple() or Relaxed()Shulhan
2019-02-14email: implement DKIM verify on messageShulhan
Each message will have DKIMSignature field and dkimStatus that contains the message signature, if available, and their status.
2019-02-06lib/email: add methods to canonicalize bodyShulhan
The two methods are simple or relaxed algorithm as defined in RFC 6376, section 3.4.3 and 3.4.4
2019-02-05lib/email: replace all occurrance if '\r' and '\n' with constantsShulhan
2019-02-05lib/email: move content of Message type to its own fileShulhan