aboutsummaryrefslogtreecommitdiffstats
path: root/services/mailer
Commit message (Collapse)AuthorAgeFilesLines
* remove context from mail struct (#33811)TheFox0x72025-03-064-99/+103
| | | it can be passed by argument instead
* Email option to embed images as base64 instead of link (#32061)sommerf-lf2025-03-053-14/+233
| | | | | | | | | | | | | | | | | | | | | | ref: #15081 ref: #14037 Documentation: https://gitea.com/gitea/docs/pulls/69 # Example Content: ![image](https://github.com/user-attachments/assets/e73ebfbe-e329-40f6-9c4a-f73832bbb181) Result in Email: ![image](https://github.com/user-attachments/assets/55b7019f-e17a-46c3-a374-3b4769d5c2d6) Result with source code: (first image is external image, 2nd is now embedded) ![image](https://github.com/user-attachments/assets/8e2804a1-580f-4a69-adcb-cc5d16f7da81) --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Refactor mail code (#33768)wxiaoguang2025-03-037-514/+536
| | | `mail.go` contains various different functions, it's time to split it.
* Use test context in tests and new loop system in benchmarks (#33648)TheFox0x72025-02-201-8/+8
| | | | | | | | Replace all contexts in tests with go1.24 t.Context() --------- Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Move commits signature and verify functions to service layers (#33605)Lunny Xiao2025-02-161-1/+2
| | | | No logic change, just move functions.
* chore: fix some trivial problems and TODOs (#33473)wxiaoguang2025-02-021-8/+8
| | | | | | | | | | | 1. Fix incorrect `MentionCount` (actually it seems to be deadcode, affects nothing) 2. Remove fallback sha1 support for time limit token 3. Use route middleware `reqRepoActionsWriter` for `ArtifactsDeleteView` 4. Use clearer message "Failed to authenticate user" instead of "Verify" when auth fails 5. `tests/integration/benchmarks_test.go` is not quite right, actually it is never used, so delete it. 6. Remove or update TODO comments
* Refactor user & avatar (#33433)wxiaoguang2025-01-302-3/+3
| | | | | 1. better GetPossibleUserByID logic 2. fix some function name & comment typos 3. do not re-generate avatar if one exists
* Refactor older tests to use testify (#33140)TheFox0x72025-01-091-3/+1
| | | | | Refactor checks to use assert/require Use require.Eventually for waiting in elastic and meilisearch tests Use require to exit early instead of assert
* Support for email addresses containing uppercase characters when activating ↵Zettat1232024-12-271-3/+6
| | | | | | | | | user account (#32998) Fix #32807 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Refactor "string truncate" (#32984)wxiaoguang2024-12-261-2/+2
|
* Refactor template & test related code (#32938)wxiaoguang2024-12-223-12/+12
| | | Move some legacy code from "base" package to proper packages.
* Use new mail package instead of an unmintained one (#32682)Lunny Xiao2024-12-058-60/+101
| | | Resolve #18664
* Split mail sender sub package from mailer service package (#32618)Lunny Xiao2024-11-3013-398/+491
| | | | | | | | Move all mail sender related codes into a sub package of services/mailer. Just move, no code change. Then we just have dependencies on go-mail package in the new sub package. We can use other package to replace it because it's unmaintainable. ref #18664
* Refactor markup render system (#32612)wxiaoguang2024-11-243-11/+7
| | | | | | | | | | This PR removes (almost) all path tricks, and introduces "renderhelper" package. Now we can clearly see the rendering behaviors for comment/file/wiki, more details are in "renderhelper" tests. Fix #31411 , fix #18592, fix #25632 and maybe more problems. (ps: fix #32608 by the way)
* Refactor markup render system (#32589)wxiaoguang2024-11-222-17/+10
| | | | This PR mainly moves some code and introduces `RenderContext.WithXxx` functions
* Add reviewers selection to new pull request (#32403)Calvin K2024-11-091-1/+1
| | | | | | | | | | Users could add reviewers when creating new PRs. --------- Co-authored-by: splitt3r <splitt3r@users.noreply.github.com> Co-authored-by: Sebastian Sauer <sauer.sebastian@gmail.com> Co-authored-by: bb-ben <70356237+bboerben@users.noreply.github.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Move AddCollabrator and CreateRepositoryByExample to service layer (#32419)Lunny Xiao2024-11-071-0/+1
| | | | | | - [x] Move `CreateRepositoryByExample` to service layer - [x] Move `AddCollabrator` to service layer - [x] Add a new parameter for `AddCollabrator` so that changing mode immediately after that will become unnecessary.
* Add missing comment reply handling (#32050)KN4CK3R2024-09-171-27/+29
| | | | | | | | | Fixes #31937 - Add missing comment reply handling - Use `onGiteaRun` in the test because the fixtures are not present otherwise (did this behaviour change?) Compare without whitespaces.
* Add option to change mail from user display name (#31528)65432024-07-144-3/+67
| | | | | | | | | | Make it posible to let mails show e.g.: `Max Musternam (via gitea.kithara.com) <gitea@kithara.com>` Docs: https://gitea.com/gitea/docs/pulls/23 --- *Sponsored by Kithara Software GmbH*
* Display app name in the registration email title (#31562)Sunny Wan2024-07-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | I changed the title of the registation email from "Welcome to Gitea" to "Welcome to (appname)". I did this by substituting 'Gitea' in register_notify to %s and formating the registration title in mail.go. I changed this for all the languages I could, but I struggled to changed the translation file for Farsi. I have attached the screenshots of before and after and the related issue below. Related issue: https://github.com/go-gitea/gitea/issues/31108 Before change: ![Screenshot from 2024-07-04 22-32-17](https://github.com/go-gitea/gitea/assets/94445569/4178b51c-1acc-45f4-9750-dff41564a709) After: ![Screenshot from 2024-07-04 22-32-01](https://github.com/go-gitea/gitea/assets/94445569/9cd7a58d-c0f5-4a3c-a66c-805c55411eaa) --------- Signed-off-by: Sunny Wan <Sunnywan2020@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
* Use FullName in Emails to address the recipient if possible (#31527)65432024-07-083-13/+13
| | | | | | | | Before we had just the plain mail address as recipient. But now we provide additional Information for the Mail clients. --- *Sponsored by Kithara Software GmbH*
* Add option for mailer to override mail headers (#27860)65432024-06-032-1/+85
| | | | | | Add option to override headers of mails, gitea send out --- *Sponsored by Kithara Software GmbH*
* Use repo as of renderctx's member rather than a repoPath on metas (#29222)Lunny Xiao2024-05-302-2/+4
| | | | Use a `gitrepo.Repository` in the markup's RenderContext but not store the repository's path.
* Fix incorrect message id for releaes email (#30825)wxiaoguang2024-05-023-8/+20
| | | | Make generateMessageIDForRelease outputs the same format as generateMessageIDForIssue (old `createReference`)
* Use relative links for commits, mentions, and issues in markdown (#29427)KN4CK3R2024-03-132-2/+27
| | | | | | | | | | | | Fixes #29404 Use relative links for - commits - mentions - issues --------- Co-authored-by: silverwind <me@silverwind.io>
* Move context from modules to services (#29440)Lunny Xiao2024-02-271-1/+1
| | | | | | | | | | | | | | | Since `modules/context` has to depend on `models` and many other packages, it should be moved from `modules/context` to `services/context` according to design principles. There is no logic code change on this PR, only move packages. - Move `code.gitea.io/gitea/modules/context` to `code.gitea.io/gitea/services/context` - Move `code.gitea.io/gitea/modules/contexttest` to `code.gitea.io/gitea/services/contexttest` because of depending on context - Move `code.gitea.io/gitea/modules/upload` to `code.gitea.io/gitea/services/context/upload` because of depending on context
* Use `crypto/sha256` (#29386)KN4CK3R2024-02-251-2/+1
| | | | | | | | Go 1.21 improved the performance of `crypto/sha256`. It's now similar to `minio/sha256-simd`, so we should just use the standard libs. https://go.dev/doc/go1.21#crypto/sha256 https://go-review.googlesource.com/c/go/+/408795 https://github.com/multiformats/go-multihash/pull/173
* Add attachment support for code review comments (#29220)Jimmy Praet2024-02-251-0/+1
| | | | | | | Fixes #27960, #24411, #12183 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Refactor locale&string&template related code (#29165)wxiaoguang2024-02-144-10/+10
| | | | | | Clarify when "string" should be used (and be escaped), and when "template.HTML" should be used (no need to escape) And help PRs like #29059 , to render the error messages correctly.
* Fix missing link on outgoing new release notifications (#29079)Wiktor Kwapisiewicz2024-02-081-0/+1
| | | | | | | | | | | | | Outgoing new release e-mail notifications were missing links to the actual release. An example from Codeberg.org e-mail: <a href=3D"">View it on Codeberg.org</a>.<br/> This PR adds `"Link"` context property pointing to the release on the web interface. The change was tested using `[mailer] PROTOCOL=dummy`. Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
* Unify user update methods (#28733)KN4CK3R2024-02-042-6/+6
| | | | | | | | | | | Fixes #28660 Fixes an admin api bug related to `user.LoginSource` Fixed `/user/emails` response not identical to GitHub api This PR unifies the user update methods. The goal is to keep the logic only at one place (having audit logs in mind). For example, do the password checks only in one method not everywhere a password is updated. After that PR is merged, the user creation should be next.
* Include username in email headers (#28981)Gwyneth Morgan2024-02-032-8/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Emails from Gitea comments do not contain the username of the commenter anywhere, only their display name, so it is not possible to verify who made a comment from the email itself: From: "Alice" <email@gitea> X-Gitea-Sender: Alice X-Gitea-Recipient: Bob X-GitHub-Sender: Alice X-GitHub-Recipient: Bob This comment looks like it's from @alice. The X-Gitea/X-GitHub headers also use display names, which is not very reliable for filtering, and inconsistent with GitHub's behavior: X-GitHub-Sender: lunny X-GitHub-Recipient: gwymor This change includes both the display name and username in the From header, and switches the other headers from display name to username: From: "Alice (@fakealice)" <email@gitea> X-Gitea-Sender: fakealice X-Gitea-Recipient: bob X-GitHub-Sender: fakealice X-GitHub-Recipient: bob This comment looks like it's from @alice.
* Rework markup link rendering (#26745)KN4CK3R2024-01-152-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #26548 This PR refactors the rendering of markup links. The old code uses `strings.Replace` to change some urls while the new code uses more context to decide which link should be generated. The added tests should ensure the same output for the old and new behaviour (besides the bug). We may need to refactor the rendering a bit more to make it clear how the different helper methods render the input string. There are lots of options (resolve links / images / mentions / git hashes / emojis / ...) but you don't really know what helper uses which options. For example, we currently support images in the user description which should not be allowed I think: <details> <summary>Profile</summary> https://try.gitea.io/KN4CK3R ![grafik](https://github.com/go-gitea/gitea/assets/1666336/109ae422-496d-4200-b52e-b3a528f553e5) </details> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Fix missing mail reply address (#27997)KN4CK3R2023-11-131-3/+5
| | | | | | | Fixes https://codeberg.org/forgejo/forgejo/issues/1458 Some mails such as issue creation mails are missing the reply-to-comment address. This PR fixes that and specifies which comment types should get a reply-possibility.
* Clean up template locale usage (#27856)wxiaoguang2023-10-316-46/+15
| | | | | | | | | | | | | | | | | After many refactoring PRs for the "locale" and "template context function", now the ".locale" is not needed for web templates any more. This PR does a clean up for: 1. Remove `ctx.Data["locale"]` for web context. 2. Use `ctx.Locale` in `500.tmpl`, for consistency. 3. Add a test check for `500 page` locale usage. 4. Remove the `Str2html` and `DotEscape` from mail template context data, they are copy&paste errors introduced by #19169 and #16200 . These functions are template functions (provided by the common renderer), but not template data variables. 5. Make email `SendAsync` function mockable (I was planning to add more tests but it would make this PR much too complex, so the tests could be done in another PR)
* Upgrade to golangci-lint@v1.55.0 (#27756)silverwind2023-10-241-2/+1
| | | https://github.com/golangci/golangci-lint/releases/tag/v1.55.0
* Penultimate round of `db.DefaultContext` refactor (#27414)JakobDev2023-10-114-4/+4
| | | | | | | Part of #27065 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Even more `db.DefaultContext` refactor (#27352)JakobDev2023-10-031-1/+1
| | | | | | | | Part of #27065 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
* make writing main test easier (#27270)Lunny Xiao2023-09-281-4/+1
| | | | | | | | | This PR removed `unittest.MainTest` the second parameter `TestOptions.GiteaRoot`. Now it detects the root directory by current working directory. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Next round of `db.DefaultContext` refactor (#27089)JakobDev2023-09-161-1/+1
| | | Part of #27065
* Load reviewer before sending notification (#27063)sebastian-sauer2023-09-131-0/+3
| | | | | | | | The [template](https://github.com/go-gitea/gitea/blob/main/templates/mail/issue/default.tmpl#L51) uses the Reviewer.Name property - this was not loaded. Fixes #27035
* move repository deletion to service layer (#26948)Lunny Xiao2023-09-081-0/+2
| | | Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Team invite url fix when registration disabled (#26950)Jack Hay2023-09-071-2/+2
| | | | | This is a follow-on to https://github.com/go-gitea/gitea/pull/26550 and fixes the case where the team invite links to the registration page if it is disabled in settings.
* Move notification interface to services layer (#26915)Lunny Xiao2023-09-052-22/+22
| | | Extract from #22266
* Move mail notification logic to service layer (#26905)Lunny Xiao2023-09-052-0/+206
| | | Extract from #22266
* Update team invitation email link (#26550)Jack Hay2023-08-311-0/+19
| | | | | Co-authored-by: Kyle D <kdumontnu@gmail.com> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
* Replace `interface{}` with `any` (#25686)silverwind2023-07-046-11/+11
| | | | | Result of running `perl -p -i -e 's#interface\{\}#any#g' **/*` and `make fmt`. Basically the same [as golang did](https://github.com/golang/go/commit/2580d0e08d5e9f979b943758d3c49877fb2324cb).
* Improve queue and logger context (#24924)wxiaoguang2023-05-261-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | Before there was a "graceful function": RunWithShutdownFns, it's mainly for some modules which doesn't support context. The old queue system doesn't work well with context, so the old queues need it. After the queue refactoring, the new queue works with context well, so, use Golang context as much as possible, the `RunWithShutdownFns` could be removed (replaced by RunWithCancel for context cancel mechanism), the related code could be simplified. This PR also fixes some legacy queue-init problems, eg: * typo : archiver: "unable to create codes indexer queue" => "unable to create repo-archive queue" * no nil check for failed queues, which causes unfriendly panic After this PR, many goroutines could have better display name: ![image](https://github.com/go-gitea/gitea/assets/2114189/701b2a9b-8065-4137-aeaa-0bda2b34604a) ![image](https://github.com/go-gitea/gitea/assets/2114189/f1d5f50f-0534-40f0-b0be-f2c9daa5fe92)
* Rewrite queue (#24505)wxiaoguang2023-05-081-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | # ⚠️ Breaking Many deprecated queue config options are removed (actually, they should have been removed in 1.18/1.19). If you see the fatal message when starting Gitea: "Please update your app.ini to remove deprecated config options", please follow the error messages to remove these options from your app.ini. Example: ``` 2023/05/06 19:39:22 [E] Removed queue option: `[indexer].ISSUE_INDEXER_QUEUE_TYPE`. Use new options in `[queue.issue_indexer]` 2023/05/06 19:39:22 [E] Removed queue option: `[indexer].UPDATE_BUFFER_LEN`. Use new options in `[queue.issue_indexer]` 2023/05/06 19:39:22 [F] Please update your app.ini to remove deprecated config options ``` Many options in `[queue]` are are dropped, including: `WRAP_IF_NECESSARY`, `MAX_ATTEMPTS`, `TIMEOUT`, `WORKERS`, `BLOCK_TIMEOUT`, `BOOST_TIMEOUT`, `BOOST_WORKERS`, they can be removed from app.ini. # The problem The old queue package has some legacy problems: * complexity: I doubt few people could tell how it works. * maintainability: Too many channels and mutex/cond are mixed together, too many different structs/interfaces depends each other. * stability: due to the complexity & maintainability, sometimes there are strange bugs and difficult to debug, and some code doesn't have test (indeed some code is difficult to test because a lot of things are mixed together). * general applicability: although it is called "queue", its behavior is not a well-known queue. * scalability: it doesn't seem easy to make it work with a cluster without breaking its behaviors. It came from some very old code to "avoid breaking", however, its technical debt is too heavy now. It's a good time to introduce a better "queue" package. # The new queue package It keeps using old config and concept as much as possible. * It only contains two major kinds of concepts: * The "base queue": channel, levelqueue, redis * They have the same abstraction, the same interface, and they are tested by the same testing code. * The "WokerPoolQueue", it uses the "base queue" to provide "worker pool" function, calls the "handler" to process the data in the base queue. * The new code doesn't do "PushBack" * Think about a queue with many workers, the "PushBack" can't guarantee the order for re-queued unhandled items, so in new code it just does "normal push" * The new code doesn't do "pause/resume" * The "pause/resume" was designed to handle some handler's failure: eg: document indexer (elasticsearch) is down * If a queue is paused for long time, either the producers blocks or the new items are dropped. * The new code doesn't do such "pause/resume" trick, it's not a common queue's behavior and it doesn't help much. * If there are unhandled items, the "push" function just blocks for a few seconds and then re-queue them and retry. * The new code doesn't do "worker booster" * Gitea's queue's handlers are light functions, the cost is only the go-routine, so it doesn't make sense to "boost" them. * The new code only use "max worker number" to limit the concurrent workers. * The new "Push" never blocks forever * Instead of creating more and more blocking goroutines, return an error is more friendly to the server and to the end user. There are more details in code comments: eg: the "Flush" problem, the strange "code.index" hanging problem, the "immediate" queue problem. Almost ready for review. TODO: * [x] add some necessary comments during review * [x] add some more tests if necessary * [x] update documents and config options * [x] test max worker / active worker * [x] re-run the CI tasks to see whether any test is flaky * [x] improve the `handleOldLengthConfiguration` to provide more friendly messages * [x] fine tune default config values (eg: length?) ## Code coverage: ![image](https://user-images.githubusercontent.com/2114189/236620635-55576955-f95d-4810-b12f-879026a3afdf.png)
* Add ntlm authentication support for mail (#23811)木木田2023-05-021-0/+32
| | | | | | | | | Add ntlm authentication support for mail use "github.com/Azure/go-ntlmssp" --------- Co-authored-by: yangtan_win <YangTan@Fitsco.com.cn> Co-authored-by: silverwind <me@silverwind.io>