Skip to content

Commit e7da210

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Add option for mailer to override mail headers (go-gitea#27860) Move custom `tw-` helpers to tailwind plugin (go-gitea#31184) Remove unnecessary inline style for tab-size (go-gitea#31224) Document possible action types for the user activity feed API (go-gitea#31196) Remove sqlite-viewer and using database client (go-gitea#31223) Update golangci-lint to v1.59.0 (go-gitea#31221)
2 parents d0022eb + aace3bc commit e7da210

File tree

15 files changed

+196
-36
lines changed

15 files changed

+196
-36
lines changed

.devcontainer/devcontainer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"ghcr.io/devcontainers-contrib/features/poetry:2": {},
1111
"ghcr.io/devcontainers/features/python:1": {
1212
"version": "3.12"
13-
}
13+
},
14+
"ghcr.io/warrenbuckley/codespace-features/sqlite:1": {}
1415
},
1516
"customizations": {
1617
"vscode": {
@@ -25,7 +26,7 @@
2526
"Vue.volar",
2627
"ms-azuretools.vscode-docker",
2728
"vitest.explorer",
28-
"qwtel.sqlite-viewer",
29+
"cweijan.vscode-database-client2",
2930
"GitHub.vscode-pull-request-github",
3031
"Azurite.azurite"
3132
]

.gitpod.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ vscode:
4343
- Vue.volar
4444
- ms-azuretools.vscode-docker
4545
- vitest.explorer
46-
- qwtel.sqlite-viewer
46+
- cweijan.vscode-database-client2
4747
- GitHub.vscode-pull-request-github
4848

4949
ports:

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ XGO_VERSION := go-1.22.x
2828
AIR_PACKAGE ?= github.com/cosmtrek/air@v1
2929
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/[email protected]
3030
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
31-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2
31+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3333
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/[email protected]
3434
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@db51e79a0e37c572d8b59ae0c58bf2bbbbe53285

custom/conf/app.example.ini

+10
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,16 @@ LEVEL = Info
16871687
;; convert \r\n to \n for Sendmail
16881688
;SENDMAIL_CONVERT_CRLF = true
16891689

1690+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1691+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1692+
;[mailer.override_header]
1693+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1694+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1695+
;; This is empty by default, use it only if you know what you need it for.
1696+
1697+
;Content-Type = text/html; charset=utf-8
1698+
;In-Reply-To =
1699+
16901700
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16911701
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16921702
;[email.incoming]

docs/content/administration/config-cheat-sheet.en-us.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,13 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
724724

725725
## Mailer (`mailer`)
726726

727-
⚠️ This section is for Gitea 1.18 and later. If you are using Gitea 1.17 or older,
727+
:::warning
728+
This section is for Gitea 1.18 and later. If you are using Gitea 1.17 or older,
728729
please refer to
729730
[Gitea 1.17 app.ini example](https://github.com/go-gitea/gitea/blob/release/v1.17/custom/conf/app.example.ini)
730731
and
731732
[Gitea 1.17 configuration document](https://github.com/go-gitea/gitea/blob/release/v1.17/docs/content/doc/advanced/config-cheat-sheet.en-us.md)
733+
:::
732734

733735
- `ENABLED`: **false**: Enable to use a mail service.
734736
- `PROTOCOL`: **_empty_**: Mail server protocol. One of "smtp", "smtps", "smtp+starttls", "smtp+unix", "sendmail", "dummy". _Before 1.18, this was inferred from a combination of `MAILER_TYPE` and `IS_TLS_ENABLED`._
@@ -761,6 +763,21 @@ and
761763
- `SEND_BUFFER_LEN`: **100**: Buffer length of mailing queue. **DEPRECATED** use `LENGTH` in `[queue.mailer]`
762764
- `SEND_AS_PLAIN_TEXT`: **false**: Send mails only in plain text, without HTML alternative.
763765

766+
## Override Email Headers (`mailer.override_header`)
767+
768+
:::warning
769+
This is empty by default, use it only if you know what you need it for.
770+
:::
771+
772+
examples would be:
773+
774+
```ini
775+
[mailer.override_header]
776+
777+
Content-Type = text/html; charset=utf-8
778+
In-Reply-To =
779+
```
780+
764781
## Incoming Email (`email.incoming`)
765782

766783
- `ENABLED`: **false**: Enable handling of incoming emails.

modules/setting/mailer.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ import (
1818
// Mailer represents mail service.
1919
type Mailer struct {
2020
// Mailer
21-
Name string `ini:"NAME"`
22-
From string `ini:"FROM"`
23-
EnvelopeFrom string `ini:"ENVELOPE_FROM"`
24-
OverrideEnvelopeFrom bool `ini:"-"`
25-
FromName string `ini:"-"`
26-
FromEmail string `ini:"-"`
27-
SendAsPlainText bool `ini:"SEND_AS_PLAIN_TEXT"`
28-
SubjectPrefix string `ini:"SUBJECT_PREFIX"`
21+
Name string `ini:"NAME"`
22+
From string `ini:"FROM"`
23+
EnvelopeFrom string `ini:"ENVELOPE_FROM"`
24+
OverrideEnvelopeFrom bool `ini:"-"`
25+
FromName string `ini:"-"`
26+
FromEmail string `ini:"-"`
27+
SendAsPlainText bool `ini:"SEND_AS_PLAIN_TEXT"`
28+
SubjectPrefix string `ini:"SUBJECT_PREFIX"`
29+
OverrideHeader map[string][]string `ini:"-"`
2930

3031
// SMTP sender
3132
Protocol string `ini:"PROTOCOL"`
@@ -151,6 +152,12 @@ func loadMailerFrom(rootCfg ConfigProvider) {
151152
log.Fatal("Unable to map [mailer] section on to MailService. Error: %v", err)
152153
}
153154

155+
overrideHeader := rootCfg.Section("mailer.override_header").Keys()
156+
MailService.OverrideHeader = make(map[string][]string)
157+
for _, key := range overrideHeader {
158+
MailService.OverrideHeader[key.Name()] = key.Strings(",")
159+
}
160+
154161
// Infer SMTPPort if not set
155162
if MailService.SMTPPort == "" {
156163
switch MailService.Protocol {

modules/structs/activity.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ package structs
66
import "time"
77

88
type Activity struct {
9-
ID int64 `json:"id"`
10-
UserID int64 `json:"user_id"` // Receiver user
9+
ID int64 `json:"id"`
10+
UserID int64 `json:"user_id"` // Receiver user
11+
// the type of action
12+
//
13+
// enum: create_repo,rename_repo,star_repo,watch_repo,commit_repo,create_issue,create_pull_request,transfer_repo,push_tag,comment_issue,merge_pull_request,close_issue,reopen_issue,close_pull_request,reopen_pull_request,delete_tag,delete_branch,mirror_sync_push,mirror_sync_create,mirror_sync_delete,approve_pull_request,reject_pull_request,comment_pull,publish_release,pull_review_dismissed,pull_request_ready_for_review,auto_merge_pull_request
1114
OpType string `json:"op_type"`
1215
ActUserID int64 `json:"act_user_id"`
1316
ActUser *User `json:"act_user"`

routers/web/repo/issue_content_history.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
156156

157157
// use chroma to render the diff html
158158
diffHTMLBuf := bytes.Buffer{}
159-
diffHTMLBuf.WriteString("<pre class='chroma' style='tab-size: 4'>")
159+
diffHTMLBuf.WriteString("<pre class='chroma'>")
160160
for _, it := range diff {
161161
if it.Type == diffmatchpatch.DiffInsert {
162162
diffHTMLBuf.WriteString("<span class='gi'>")

services/gitdiff/gitdiff.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ func readFileName(rd *strings.Reader) (string, bool) {
10611061
char, _ := rd.ReadByte()
10621062
_ = rd.UnreadByte()
10631063
if char == '"' {
1064-
fmt.Fscanf(rd, "%q ", &name)
1064+
_, _ = fmt.Fscanf(rd, "%q ", &name)
10651065
if len(name) == 0 {
10661066
log.Error("Reader has no file name: reader=%+v", rd)
10671067
return "", true
@@ -1073,12 +1073,12 @@ func readFileName(rd *strings.Reader) (string, bool) {
10731073
} else {
10741074
// This technique is potentially ambiguous it may not be possible to uniquely identify the filenames from the diff line alone
10751075
ambiguity = true
1076-
fmt.Fscanf(rd, "%s ", &name)
1076+
_, _ = fmt.Fscanf(rd, "%s ", &name)
10771077
char, _ := rd.ReadByte()
10781078
_ = rd.UnreadByte()
10791079
for !(char == 0 || char == '"' || char == 'b') {
10801080
var suffix string
1081-
fmt.Fscanf(rd, "%s ", &suffix)
1081+
_, _ = fmt.Fscanf(rd, "%s ", &suffix)
10821082
name += " " + suffix
10831083
char, _ = rd.ReadByte()
10841084
_ = rd.UnreadByte()

services/mailer/mailer.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (m *Message) ToMessage() *gomail.Message {
5757
msg.SetHeader(header, m.Headers[header]...)
5858
}
5959

60-
if len(setting.MailService.SubjectPrefix) > 0 {
60+
if setting.MailService.SubjectPrefix != "" {
6161
msg.SetHeader("Subject", setting.MailService.SubjectPrefix+" "+m.Subject)
6262
} else {
6363
msg.SetHeader("Subject", m.Subject)
@@ -79,6 +79,14 @@ func (m *Message) ToMessage() *gomail.Message {
7979
if len(msg.GetHeader("Message-ID")) == 0 {
8080
msg.SetHeader("Message-ID", m.generateAutoMessageID())
8181
}
82+
83+
for k, v := range setting.MailService.OverrideHeader {
84+
if len(msg.GetHeader(k)) != 0 {
85+
log.Debug("Mailer override header '%s' as per config", k)
86+
}
87+
msg.SetHeader(k, v...)
88+
}
89+
8290
return msg
8391
}
8492

services/mailer/mailer_test.go

+76
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package mailer
55

66
import (
7+
"strings"
78
"testing"
89
"time"
910

@@ -36,3 +37,78 @@ func TestGenerateMessageID(t *testing.T) {
3637
gm = m.ToMessage()
3738
assert.Equal(t, "<[email protected]>", gm.GetHeader("Message-ID")[0])
3839
}
40+
41+
func TestToMessage(t *testing.T) {
42+
oldConf := *setting.MailService
43+
defer func() {
44+
setting.MailService = &oldConf
45+
}()
46+
setting.MailService.From = "[email protected]"
47+
48+
m1 := Message{
49+
Info: "info",
50+
FromAddress: "[email protected]",
51+
FromDisplayName: "Test Gitea",
52+
53+
Subject: "Issue X Closed",
54+
Body: "Some Issue got closed by Y-Man",
55+
}
56+
57+
buf := &strings.Builder{}
58+
_, err := m1.ToMessage().WriteTo(buf)
59+
assert.NoError(t, err)
60+
header, _ := extractMailHeaderAndContent(t, buf.String())
61+
assert.EqualValues(t, map[string]string{
62+
"Content-Type": "multipart/alternative;",
63+
"Date": "Mon, 01 Jan 0001 00:00:00 +0000",
64+
"From": "\"Test Gitea\" <[email protected]>",
65+
"Message-ID": "<autogen--6795364578871-69c000786adc60dc@localhost>",
66+
"Mime-Version": "1.0",
67+
"Subject": "Issue X Closed",
68+
69+
"X-Auto-Response-Suppress": "All",
70+
}, header)
71+
72+
setting.MailService.OverrideHeader = map[string][]string{
73+
"Message-ID": {""}, // delete message id
74+
"Auto-Submitted": {"auto-generated"}, // suppress auto replay
75+
}
76+
77+
buf = &strings.Builder{}
78+
_, err = m1.ToMessage().WriteTo(buf)
79+
assert.NoError(t, err)
80+
header, _ = extractMailHeaderAndContent(t, buf.String())
81+
assert.EqualValues(t, map[string]string{
82+
"Content-Type": "multipart/alternative;",
83+
"Date": "Mon, 01 Jan 0001 00:00:00 +0000",
84+
"From": "\"Test Gitea\" <[email protected]>",
85+
"Message-ID": "",
86+
"Mime-Version": "1.0",
87+
"Subject": "Issue X Closed",
88+
89+
"X-Auto-Response-Suppress": "All",
90+
"Auto-Submitted": "auto-generated",
91+
}, header)
92+
}
93+
94+
func extractMailHeaderAndContent(t *testing.T, mail string) (map[string]string, string) {
95+
header := make(map[string]string)
96+
97+
parts := strings.SplitN(mail, "boundary=", 2)
98+
if !assert.Len(t, parts, 2) {
99+
return nil, ""
100+
}
101+
content := strings.TrimSpace("boundary=" + parts[1])
102+
103+
hParts := strings.Split(parts[0], "\n")
104+
105+
for _, hPart := range hParts {
106+
parts := strings.SplitN(hPart, ":", 2)
107+
hk := strings.TrimSpace(parts[0])
108+
if hk != "" {
109+
header[hk] = strings.TrimSpace(parts[1])
110+
}
111+
}
112+
113+
return header, content
114+
}

tailwind.config.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {readFileSync} from 'node:fs';
22
import {env} from 'node:process';
33
import {parse} from 'postcss';
4+
import plugin from 'tailwindcss/plugin.js';
45

56
const isProduction = env.NODE_ENV !== 'development';
67

@@ -98,4 +99,26 @@ export default {
9899
})),
99100
},
100101
},
102+
plugins: [
103+
plugin(({addUtilities}) => {
104+
addUtilities({
105+
// tw-hidden must win all other "display: xxx !important" classes to get the chance to "hide" an element.
106+
// do not use:
107+
// * "[hidden]" attribute: it's too weak, can not be applied to an element with "display: flex"
108+
// * ".hidden" class: it has been polluted by Fomantic UI in many cases
109+
// * inline style="display: none": it's difficult to tweak
110+
// * jQuery's show/hide/toggle: it can not show/hide elements with "display: xxx !important"
111+
// only use:
112+
// * this ".tw-hidden" class
113+
// * showElem/hideElem/toggleElem functions in "utils/dom.js"
114+
'.hidden.hidden': {
115+
'display': 'none',
116+
},
117+
// proposed class from https://github.com/tailwindlabs/tailwindcss/pull/12128
118+
'.break-anywhere': {
119+
'overflow-wrap': 'anywhere',
120+
},
121+
});
122+
}),
123+
],
101124
};

templates/swagger/v1_json.tmpl

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web_src/css/helpers.css

-16
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@ Gitea's private styles use `g-` prefix.
3535
.interact-bg:hover { background: var(--color-hover) !important; }
3636
.interact-bg:active { background: var(--color-active) !important; }
3737

38-
/*
39-
tw-hidden must win all other "display: xxx !important" classes to get the chance to "hide" an element.
40-
do not use:
41-
* "[hidden]" attribute: it's too weak, can not be applied to an element with "display: flex"
42-
* ".hidden" class: it has been polluted by Fomantic UI in many cases
43-
* inline style="display: none": it's difficult to tweak
44-
* jQuery's show/hide/toggle: it can not show/hide elements with "display: xxx !important"
45-
only use:
46-
* this ".tw-hidden" class
47-
* showElem/hideElem/toggleElem functions in "utils/dom.js"
48-
*/
49-
.tw-hidden.tw-hidden { display: none !important; }
50-
51-
/* proposed class from https://github.com/tailwindlabs/tailwindcss/pull/12128 */
52-
.tw-break-anywhere { overflow-wrap: anywhere !important; }
53-
5438
@media (max-width: 767.98px) {
5539
/* double selector so it wins over .tw-flex (old .gt-df) etc */
5640
.not-mobile.not-mobile {

web_src/css/repo.css

+1
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,7 @@ tbody.commit-list {
23222322
min-height: 12em;
23232323
max-height: calc(100vh - 10.5rem);
23242324
overflow-y: auto;
2325+
tab-size: 4;
23252326
}
23262327

23272328
.comment-diff-data pre {

0 commit comments

Comments
 (0)