aboutsummaryrefslogtreecommitdiff
path: root/lib/smtp
AgeCommit message (Collapse)Author
11 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.
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-09-20lib/crypto: add parameter passphrase to LoadPrivateKeyShulhan
The passphrase parameter is optional, it will be used only if the private key is encrypted.
2023-09-20lib/crypto: rewrite LoadPrivateKey as wrapper of ssh.ParseRawPrivateShulhan
Previously, the LoadPrivateKey function only able to load private key with PKCS#1 format. This changes make the function as a wrapper for ssh.ParseRawPrivate that can load RSA, DSA, ECDSA, and Ed25519 in PKCS#1, PKCS#8, OpenSSL, and OpenSSH formats.
2023-09-14all: fix variable shadowing as reported by shadow toolShulhan
The shadow tool [1] report a variable where its name is declared twice or more, in different scope. [1] https://pkg.go.dev/golang.org/x/tools@v0.13.0/go/analysis/passes/shadow
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-11lib/smtp: fix linter warning due to missing implementationsShulhan
2023-07-26lib/smtp: format the passed data in NewMailTxShulhan
The following rules are applied to the data, * all lines must end with CRLF * if the line start with period, additional period is inserted before the line. This recommendation based on RFC 5321 section 4.5.2 to prevent data that contains CRLF "." CRLF does not corrupt the message, causing the server terminate reading the message where it should not. [1] https://datatracker.ietf.org/doc/html/rfc5321#section-4.5.2
2023-07-21lib/smtp: set minimum Server TLS to v1.2Shulhan
Using the TLS v1.1 is considered insecure and should not be used in server anymore.
2023-07-09lib/stmp: split checking error and non-successful response codeShulhan
2023-05-30lib/smtp: implement Client SendEmailShulhan
Somehow in 3a1a2715b25f, we include this method without implementing it. The SendEmail method simplify sending email by automatically create [MailTx] for passing it to method Client.MailTx. The test right now use live connection since the Server is not ready yet.
2023-05-30lib/smtp: changes the field name for listener for clarityShulhan
This changes rename field, * listener to listenMta since this is the socket that responsible receiving message from other Mail Trasnfer Agent (MTA). * tlsListener to listenSubmission since this is the socket that responsible receiving message from Mail User Agent (MUA) for submiting new message.
2023-05-30lib/smtp: return pointer to the struct type instead of interfaceShulhan
Even if LocalHandler and LocalStorage is one of implementation of Handler and Storage, it is be better if its return the actual type, to minimize confusion.
2023-05-30lib/smtp: use WaitAlive instead of time.SleepShulhan
This cut the test time to 0.100 second, match with sleep duration.
2023-05-20lib/smtp: change the package name in Example to have _test suffixShulhan
Package name in test Example should be different with the actual package. This is to minimize leaking un-exported function or method in Example test.
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/smtp: replace lib/io#Reader with lib/bytes#ParserShulhan
The lib/io#Reader will be deprecated and replaced with lib/bytes#Parser in the future.
2022-10-05lib/stmp: fix tests with -count=X, where X>1Shulhan
This changes require all unit tests to use their own client.
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: reorder the MIME header to write the mime-version firstShulhan
Previously, the MIME header is generated in the following order: content-type: ... mime-version: ... content-transfer-encoding: ... This changes reorder the mime-version to the top.
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.
2022-02-18lib/smtp: refactoring NewClient to use struct instead of parametersShulhan
Previously, to create new client one must pass three parameters to NewClient function: localName, remoteURL, and insecure. If we want to add another parameters in the future, it will cause the function signature changes. This changes simplify creating NewClient by passing single struct with new parameters: AuthUser, AuthPass, and AuthMechanism. If both AuthUser and AuthPass is not empty, the NewClient will authenticate the connection, minimize number of step on the caller.
2022-02-18lib/smtp: add status codes from RFC 4954Shulhan
The following status codes are added, * 432: StatusPasswordTransitionNeeded, from section 4.7.12. * 454: StatusTemporaryAuthFailure, from section 4.7.0. * 534: StatusAuthMechanismTooWeak, from section 5.7.9.
2022-02-18lib/smtp: rename Mechanism to SaslMechanismShulhan
2022-02-18lib/smtp: realign all structsShulhan
The goal is to minimize memory consumed by struct instance. Changes, * Client: from 112 to 80 bytes (-32 bytes) * Command: from 48 to 32 bytes (-8 bytes) * Domain: from 32 to 24 bytes (-8 bytes) * LocalStorage: from 72 to 40 bytes (-32 bytes) * MailTx: from 128 to 112 bytes (-16 bytes) * receiver: from 152 to 104 bytes (-48 bytes) * Response: from 32 to 24 bytes (-8 bytes) * Server: from 144 to 128 bytes (-16 bytes) * ServerInfo: from 40 to 32 bytes (-8 bytes)
2022-02-18lib/smtp: provide an example of how to create MailTx from email packageShulhan
If one read the current documentation on how to use the Client.SendTx, there is a missing link on how to create and populate MailTx. This changes provide the example using the email package to generate the MailTx Data.
2022-02-17lib/smtp: rename mail.go to mail_tx.goShulhan
This is to indicate that the content of this file is a type named MailTx.
2021-10-06lib/smtp: implement method Noop on ClientShulhan
Noop send the NOOP command to server with optional message. On success, it will return response with Code 250, StatusOK. While at it fix double call to recv on Reset() method.
2021-10-06lib/smtp: implement method Reset on ClientShulhan
The Reset() method send the STMP RSET command to the server. This command clear the current buffer on MAIL, RCPT, and DATA, but not the EHLO/HELO buffer. On success, it will return response with Code 250, StatusOK.
2021-08-13all: set the error prefix for NewClient and connectShulhan
2021-08-13lib/smtp: return io.EOF if no data received from serverShulhan
This is to prevent the recv return nil on *Response without an error, which may cause panic on caller side.
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
2020-11-23smtp: update the expired test certificateShulhan
2020-08-16smtp: check for error when writing to buffer on Client.recv()Shulhan
2020-06-18smtp: check for error when closing client connectionShulhan
2020-06-18smtp: check for EOF when receiving data from serverShulhan
2020-06-06all: use default linter optionsShulhan
2020-02-13smtp: Disable test on lookupShulhan
The lookup test should use local DNS server instead of relying on external DNS response.
2020-02-13all: suppress false-positive linter warningsShulhan
2019-10-21all: fix and add missing commentsShulhan