Skip to content

Commit 8b6b664

Browse files
committed
Merge branch 'release/0.1.5'
2 parents 2ae51c3 + a8945bd commit 8b6b664

9 files changed

Lines changed: 96 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
Notable changes to Mailpit will be documented in this file.
44

55

6+
## 0.1.5
7+
8+
### Feature
9+
- Improved message search - any order & phrase quoting
10+
11+
### UI
12+
- Change breakpoints for mobile view of messages
13+
- Resize iframes with viewport resize
14+
15+
616
## 0.1.4
717

818
### Feature

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/jhillyerd/enmime v0.10.0
1010
github.com/k3a/html2text v1.0.8
1111
github.com/klauspost/compress v1.15.9
12+
github.com/mattn/go-shellwords v1.0.12
1213
github.com/mhale/smtpd v0.8.0
1314
github.com/ostafen/clover/v2 v2.0.0-alpha.2
1415
github.com/sirupsen/logrus v1.9.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
124124
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
125125
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
126126
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
127+
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
128+
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
127129
github.com/mhale/smtpd v0.8.0 h1:5JvdsehCg33PQrZBvFyDMMUDQmvbzVpZgKob7eYBJc0=
128130
github.com/mhale/smtpd v0.8.0/go.mod h1:MQl+y2hwIEQCXtNhe5+55n0GZOjSmeqORDIXbqUL3x4=
129131
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=

server/ui-src/App.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,33 +443,33 @@ export default {
443443
<div class="list-group" v-if="items.length">
444444
<a v-for="message in items" :href="'#'+message.ID" class="row message d-flex small list-group-item list-group-item-action"
445445
:class="message.Read ? 'read':''" XXXv-on:click="openMessage(message)">
446-
<div class="col-md-3">
447-
<div class="d-md-none float-end text-muted text-nowrap small">
446+
<div class="col-lg-3">
447+
<div class="d-lg-none float-end text-muted text-nowrap small">
448448
<i class="bi bi-paperclip h6 me-1" v-if="message.Attachments"></i>
449449
{{ getRelativeCreated(message) }}
450450
</div>
451451

452-
<div class="text-truncate d-md-none privacy">
452+
<div class="text-truncate d-lg-none privacy">
453453
<span v-if="message.From" :title="message.From.Address">{{ message.From.Name ? message.From.Name : message.From.Address }}</span>
454454
</div>
455-
<div class="text-truncate d-none d-md-block privacy">
455+
<div class="text-truncate d-none d-lg-block privacy">
456456
<b v-if="message.From" :title="message.From.Address">{{ message.From.Name ? message.From.Name : message.From.Address }}</b>
457457
</div>
458-
<div class="d-none d-md-block text-truncate text-muted small privacy">
458+
<div class="d-none d-lg-block text-truncate text-muted small privacy">
459459
{{ getPrimaryEmailTo(message) }}
460460
<span v-if="message.To && message.To.length > 1">
461461
[+{{message.To.length - 1}}]
462462
</span>
463463
</div>
464464
</div>
465-
<div class="col-md-6 mt-2 mt-md-0">
465+
<div class="col-lg-6 mt-2 mt-lg-0">
466466
<b>{{ message.Subject != "" ? message.Subject : "[ no subject ]" }}</b>
467467
</div>
468-
<div class="d-none d-md-block col-1 small text-end text-muted">
468+
<div class="d-none d-lg-block col-1 small text-end text-muted">
469469
<i class="bi bi-paperclip float-start h6" v-if="message.Attachments"></i>
470470
{{ getFileSize(message.Size) }}
471471
</div>
472-
<div class="d-none d-md-block col-2 small text-end text-muted">
472+
<div class="d-none d-lg-block col-2 small text-end text-muted">
473473
{{ getRelativeCreated(message) }}
474474
</div>
475475
</a>

server/ui-src/assets/styles.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
font-family: Courier New, Courier, System, fixed-width;
4545
font-size: 0.85em;
4646
}
47+
4748
#nav-plain-text {
4849
white-space: pre-wrap;
4950
}
@@ -52,7 +53,7 @@
5253
margin: 15px 0 0;
5354

5455
th {
55-
padding-right: 10px;
56+
padding-right: 1.5rem;
5657
font-weight: normal;
5758
vertical-align: top;
5859
}
@@ -62,6 +63,14 @@
6263
}
6364
}
6465

66+
#nav-html {
67+
padding-right: 1.5rem;
68+
}
69+
70+
#preview-html {
71+
min-height: 300px;
72+
}
73+
6574
.list-group-item:first-child {
6675
border-top: 0;
6776
}

server/ui-src/templates/Message.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default {
1515
iframes: [], // for resizing
1616
}
1717
},
18+
1819
mounted() {
1920
var self = this;
2021
@@ -46,11 +47,29 @@ export default {
4647
self.srcURI = 'api/' + self.mailbox + '/' + self.message.ID + '/source';
4748
});
4849
},
50+
51+
unmounted: function() {
52+
window.removeEventListener("resize", this.resizeIframes);
53+
},
54+
4955
methods: {
5056
resizeIframe: function(el) {
5157
let i = el.target;
5258
i.style.height = i.contentWindow.document.body.scrollHeight + 50 + 'px';
5359
},
60+
61+
resizeIframes: function() {
62+
let h = document.getElementById('preview-html');
63+
if (h) {
64+
h.style.height = h.contentWindow.document.body.scrollHeight + 50 + 'px';
65+
}
66+
67+
let s = document.getElementById('message-src');
68+
if (s) {
69+
s.style.height = s.contentWindow.document.body.scrollHeight + 50 + 'px';
70+
}
71+
},
72+
5473
allAttachments: function(message){
5574
let a = [];
5675
for (let i in message.Attachments) {

storage/database.go

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/axllent/mailpit/server/websockets"
1919
"github.com/jhillyerd/enmime"
2020
"github.com/klauspost/compress/zstd"
21+
"github.com/mattn/go-shellwords"
2122
"github.com/ostafen/clover/v2"
2223
)
2324

@@ -327,21 +328,58 @@ func List(mailbox string, start, limit int) ([]data.Summary, error) {
327328
}
328329

329330
// Search returns a summary of items mathing a search. It searched the SearchText field.
330-
func Search(mailbox, search string, start, limit int) ([]data.Summary, error) {
331+
func Search(mailbox, s string, start, limit int) ([]data.Summary, error) {
331332
mailbox = sanitizeMailboxName(mailbox)
332333

333-
sq := fmt.Sprintf("(?i)%s", cleanString(regexp.QuoteMeta(search)))
334+
s = strings.ToLower(s)
335+
s = strings.Replace(s, "'", `\'`, -1)
336+
s = strings.Replace(s, "(", ``, -1)
337+
s = strings.Replace(s, ")", ``, -1)
338+
// add another quote if quotes are odd
339+
quotes := strings.Count(s, `"`)
340+
if quotes%2 != 0 {
341+
s += `"`
342+
}
343+
344+
p := shellwords.NewParser()
345+
args, err := p.Parse(s)
346+
if err != nil {
347+
return nil, errors.New("Your search contains invalid characters")
348+
}
349+
350+
results := []data.Summary{}
351+
include := []string{}
352+
353+
for _, w := range args {
354+
word := cleanString(w)
355+
if word != "" {
356+
include = append(include, fmt.Sprintf("%s", regexp.QuoteMeta(word)))
357+
}
358+
}
359+
360+
if len(include) == 0 {
361+
return results, nil
362+
}
363+
364+
var where clover.Criteria
365+
366+
for i, w := range include {
367+
if i == 0 {
368+
where = clover.Field("SearchText").Like(w)
369+
} else {
370+
where = where.And(clover.Field("SearchText").Like(w))
371+
}
372+
}
373+
334374
q, err := db.FindAll(clover.NewQuery(mailbox).
335375
Skip(start).
336376
Limit(limit).
337377
Sort(clover.SortOption{Field: "Created", Direction: -1}).
338-
Where(clover.Field("SearchText").Like(sq)))
378+
Where(where))
339379
if err != nil {
340380
return nil, err
341381
}
342382

343-
results := []data.Summary{}
344-
345383
for _, d := range q {
346384
cs := &data.Summary{}
347385
if err := d.Unmarshal(cs); err != nil {

storage/database_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ RepeatTest:
259259
case 2:
260260
search = fmt.Sprintf("to-%d@example.com", i)
261261
case 3:
262-
search = fmt.Sprintf("Subject line %d end", i)
262+
search = fmt.Sprintf("\"Subject line %d end\"", i)
263263
default:
264-
search = fmt.Sprintf("the email body %d jdsauk dwqmdqw", i)
264+
search = fmt.Sprintf("\"the email body %d jdsauk dwqmdqw\"", i)
265265
}
266266

267267
summaries, err := Search(DefaultMailbox, search, 0, 10)

updater/updater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func GithubUpdate(repo, appName, currentVersion string) (string, error) {
178178
// get the running binary
179179
oldExec, err := os.Executable()
180180
if err != nil {
181-
panic(err)
181+
return "", err
182182
}
183183

184184
if err = replaceFile(oldExec, newExec); err != nil {

0 commit comments

Comments
 (0)