aboutsummaryrefslogtreecommitdiff
path: root/lib/email
AgeCommit message (Collapse)Author
10 daysall: apply go fixShulhan
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-02-04all: remove the nolint tagsShulhan
The "nolint" tag is used to ignore lines from being processed by golangci-lint. Since we are not using golangci-lint anymore, now and in the future, those lines can be removed.
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-09-04all: fix various linter warningsShulhan
While at it, temporary disable gosec due to excessive report for G115, which may be true, but may also break the current working program. We should alter and fix once we can test and make sure that it does not breaks.
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-08-03lib/email: allow message that end lines with LF onlyShulhan
Although, a message from network must end with CRLF, a message from (another) client may have been sanitized and end with LF only.
2024-03-06all: conform with linter gosec, ineffasign, and makezeroShulhan
Some of warnings from those linter are false positives, so we just annotated them.
2024-03-05all: comply with linter recommendations #3Shulhan
For HTTP server that use TLS, set the minimum TLS version and ReadHeaderTimeout to mitigate slowloris attack. For HTTP client or server that parameterize the use of InsecureSkipVerify, annotate the line with "nolint:gosec" to allow the code pass the check. Library that still use sha1, in example in DKIM and TOTP, skip the warnings by annotating the line with "nolint:gosec". A pointer variable now allocated their address before assigning its value. Any error that returned now wrapped using "%w". Also, replace error checking using [errors.Is] or [errors.As] instead of using equal or not-equal operators. In "lib/http", replace any usage of "math/rand" with "crypto/rand". Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec" since its false positive, the issue has been fixed in Go >= 1.17.7. Any switch case that does not cover the rest of the possible values now handled by adding the cases or by replacing the "default" case with the rest of values.
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-11-07email/dkim: set ExpiredAtto MaxInt64 if value is greater than 12 digitsShulhan
According to RFC 6376, To avoid denial-of-service attacks, implementations MAY consider any value longer than 12 digits to be infinite. Since ExpiredAt type is uint64, we cannot set it to infinite, so set it to maximum value int64 (not maximum of uint64).
2023-09-13lib/ascii: replace package "math/rand" with "crypto/rand"Shulhan
Since Go 1.20 the "math/rand.Seed" is considered deprecated (the initial value of rand is seeded automatically, not zero). Now, it is the time to replace "math/rand" with more secure random number generator, from "crypto/rand". This changes affect tests in package "lib/email", "lib/http", and "lib/stmp".
2023-09-13lib/email: add method ID to HeaderShulhan
The ID method return the Message-ID or empty if its not exist.
2023-09-11lib: fix method signature for WriteToShulhan
The WriteTo should return int64 not int.
2023-09-11email/maildir: quote period in error to fix linter warningShulhan
2023-09-11lib/email: rewrite for-loop with empty body to fix linter warningShulhan
2023-09-11lib/email: add comment to exported constant and methodsShulhan
2023-09-11email/dkim: realign struct for better size allocationShulhan
The realignment reduce the cost of the following struct, * struct in TestNewDNSClientPool: from 64 to 56 bytes (-8 bytes) * Key: from 160 to 144 bytes (-16 bytes) * struct in TestKeyParseTXT: from 48 to 40 bytes (-8 bytes) * KeyPool: from 16 to 8 bytes (-8 bytes) * Signature: from 256 to 240 bytes (-16 bytes) * struct in TestSignatureHash: from 48 to 40 bytes (-8 bytes) * struct in TestSignatureSign: from 80 to 64 bytes (-16 bytes) * struct in TestSignatureVerify: from 72 to 64 bytes (-8 bytes) * Status: from 48 to 24 bytes (-24 bytes) * tag: from 16 to 8 bytes (-8 bytes)
2023-07-21email/maildir: fix tests on darwinShulhan
On Linux, if one try to write to directory without permission its return an error: "permission denied", while on Darwin its return "read-only file system".
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.
2023-06-18all: move internal/asciiset to asciiShulhan
The asciiset.Set type is exported as ascii.Set.
2023-06-06internal: add package asciisetWu Tingfeng
The package asciiset add new type ASCIISet, a bitmap to represent list of ASCII characters for faster lookup. ASCIISet is a 36-byte value, where each bit in the first 32-bytes represents the presence of a given ASCII character in the set. The remaining 4-bytes is a counter for the number of ASCII characters in the set. The 128-bits of the first 16 bytes, starting with the least-significant bit of the lowest word to the most-significant bit of the highest word, map to the full range of all 128 ASCII characters. The 128-bits of the next 16 bytes will be zeroed, ensuring that any non-ASCII character will be reported as not in the set.
2023-06-04lib/email: set the Field Type and unpack its value on ParseFieldShulhan
Once the field Name has detected and its Value is valid, we can unpack the Value based to type that it represent, for example to Date or Mailbox. This changes remove calling to unpack directly in some tests and check an error when testing ParseHeader.
2023-06-04lib/email: handle obsolete white spaces and comment when unpacking dateShulhan
In the obsolete syntax, white space and comments can appear between many more element, for example the folloing Date value are valid Date : Fri, 21 Nov 1997 09(comment): 55 : 06 -0600 This changes handle this by sanitizing the Field value, removing comment and merge multiple spaces into one, before parsing it.
2023-06-04lib/email: add benchmark for IsValidLocalShulhan
2023-06-04lib/email: remove spaces when parsing domain in parseMailboxShulhan
In obsolete syntax for mailbox in Field value, a domain can have space. For example, the following message-id is valid according to RFC 5322 Section A.6.3: message-id:<1234 @ local(blah) .machine .example>\r\n This changes handle this by removing all spaces before validating the domain name.
2023-06-03lib/email: refactoring Field parsingShulhan
Split the parsing into two methods: parseName and parseValue. The error returned from those methods are prefixed by its name.
2023-06-01lib/email: unexport the field ContentType in the fieldShulhan
The field ContentType will be set only when the field Name is "Content-Type" so it's not always exist on each field. To get the field ContentType, use Header.ContentType().
2023-05-30lib/email: update the package documentationShulhan
Add an overview of all types as building blocks from top to bottom so we can see the relation in each of them.
2023-05-30lib/email: make the ContentType match case insensitiveShulhan
The GetParamValue and SetBoundary should match any parameter key in case insensitive matter. While at it, add examples for ParseContentType and SetBoundary, and move test for GetParamValue to Example.
2023-05-30lib/email: fix parsing multiple parameters in ContentTypeShulhan
While at it, also fix the ContentType String method to prefix ';' before appending parameter key and value.
2023-05-24email/maildir: embed Folder inside ManagerShulhan
Since Folder and main maildir actually has the same directory structure, except the file "maildirfolder", we can use and embed them in Manager. This is to minimize duplicate functions in the future.
2023-05-24email/maildir: does not add suffix ":2" to file in newShulhan
The suffix ":2" is added when message file is moved from directory "new" to "cur".
2023-05-24email/maildir: scan folders during startupShulhan
Any directory under maildir that begin with dot and contains file "maildirfolder" will be included as folders.
2023-05-24email/maildir: implement FolderShulhan
Folder is a directory under maildir that store messages per file. A folder contains three directories: tmp, new, and cur; and an empty file "maildirfolder".
2023-05-22email/maildir: major refactoring plus adding unit testsShulhan
This changes remove all unneeded methods from Manager leave it with four methods: Delete, FetchNew, Incoming, OutgoingQueue. Also, we add the type filename to generate file name for tmp and new directory.
2023-05-20all: remove any usage of debug.Value in all packagesShulhan
Using global debug value for all packages turns out is not a good idea.
2023-04-09lib/bytes: return the number of skipped chars on Skip(Horizontal)SpacesShulhan
2023-04-08lib/io: refactoring ParseContentType using lib/bytes#ParserShulhan
The libio.Reader will be deprecated and replaced with libbytes.Parser in the future.
2023-04-08lib/email: refactoring ParseBodyPart using libbytes.ParserShulhan
The libio.Reader will be deprecated and replaced with libbytes.Parser in the future.
2023-04-08lib/email: refactoring ParseMailboxes using lib/bytes#ParserShulhan
The libio.Reader will be deprecated and replaced with libbytes.Parser in the future.
2023-04-08lib/email: replace lib/io#Reader with lib/bytes#ParserShulhan
The libio.Reader will be deprecated and replaced with libbytes.Parser in the future.
2023-04-08email/dkim: replace lib/io#Reader with lib/bytes#ParserShulhan
The libio.Reader will be deprecated and replaced with libbytes.Parser in the future.
2023-03-26lib/email: remove unused variables in example of Header FilterShulhan
2023-02-25lib/email: add an example for Filter method on HeaderShulhan