about summary refs log tree commit diff stats
path: root/worker/imap
diff options
context:
space:
mode:
authorGalen Abell <galen@galenabell.com>2020-03-03 08:45:06 -0500
committerReto Brunner <reto@labrat.space>2020-03-03 20:08:37 +0100
commit6ff3c7a1ba680506d77fc1fe8dfbf5b804a3fea7 (patch)
tree093c49f4dc7fbc80adedb5f6c05a76bc697e44b6 /worker/imap
parent68f179021d304d6edf939ecf5fc7d0d073b16152 (diff)
downloadaerc-6ff3c7a1ba680506d77fc1fe8dfbf5b804a3fea7.tar.gz
Mark sent messages as "seen" in maildir
- Add maildir flags to complement a messages imap flags
- Set the "seen" flag on sent messages when using the maildir backend
- Cleanup AppendMessage interface to use models.Flag for both IMAP and
  maildir
Diffstat (limited to 'worker/imap')
-rw-r--r--worker/imap/fetch.go6
-rw-r--r--worker/imap/imap.go24
-rw-r--r--worker/imap/movecopy.go2
-rw-r--r--worker/imap/worker.go2
4 files changed, 26 insertions, 8 deletions
diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go
index bf60aa9..f131117 100644
--- a/worker/imap/fetch.go
+++ b/worker/imap/fetch.go
@@ -91,7 +91,7 @@ func (imapw *IMAPWorker) handleFetchMessages(
 					Info: &models.MessageInfo{
 						BodyStructure: translateBodyStructure(_msg.BodyStructure),
 						Envelope:      translateEnvelope(_msg.Envelope),
-						Flags:         translateFlags(_msg.Flags),
+						Flags:         translateImapFlags(_msg.Flags),
 						InternalDate:  _msg.InternalDate,
 						RFC822Headers: header,
 						Uid:           _msg.Uid,
@@ -115,7 +115,7 @@ func (imapw *IMAPWorker) handleFetchMessages(
 				imapw.worker.PostMessage(&types.MessageInfo{
 					Message: types.RespondTo(msg),
 					Info: &models.MessageInfo{
-						Flags: translateFlags(_msg.Flags),
+						Flags: translateImapFlags(_msg.Flags),
 						Uid:   _msg.Uid,
 					},
 				}, nil)
@@ -136,7 +136,7 @@ func (imapw *IMAPWorker) handleFetchMessages(
 				imapw.worker.PostMessage(&types.MessageInfo{
 					Message: types.RespondTo(msg),
 					Info: &models.MessageInfo{
-						Flags: translateFlags(_msg.Flags),
+						Flags: translateImapFlags(_msg.Flags),
 						Uid:   _msg.Uid,
 					},
 				}, nil)
diff --git a/worker/imap/imap.go b/worker/imap/imap.go
index b0aacf6..fdcbc38 100644
--- a/worker/imap/imap.go
+++ b/worker/imap/imap.go
@@ -89,7 +89,7 @@ func translateAddresses(addrs []*imap.Address) []*models.Address {
 	return converted
 }
 
-var flagMap = map[string]models.Flag{
+var imapToFlag = map[string]models.Flag{
 	imap.SeenFlag:     models.SeenFlag,
 	imap.RecentFlag:   models.RecentFlag,
 	imap.AnsweredFlag: models.AnsweredFlag,
@@ -97,12 +97,30 @@ var flagMap = map[string]models.Flag{
 	imap.FlaggedFlag:  models.FlaggedFlag,
 }
 
-func translateFlags(imapFlags []string) []models.Flag {
+var flagToImap = map[models.Flag]string{
+	models.SeenFlag:     imap.SeenFlag,
+	models.RecentFlag:   imap.RecentFlag,
+	models.AnsweredFlag: imap.AnsweredFlag,
+	models.DeletedFlag:  imap.DeletedFlag,
+	models.FlaggedFlag:  imap.FlaggedFlag,
+}
+
+func translateImapFlags(imapFlags []string) []models.Flag {
 	var flags []models.Flag
 	for _, imapFlag := range imapFlags {
-		if flag, ok := flagMap[imapFlag]; ok {
+		if flag, ok := imapToFlag[imapFlag]; ok {
 			flags = append(flags, flag)
 		}
 	}
 	return flags
 }
+
+func translateFlags(flags []models.Flag) []string {
+	var imapFlags []string
+	for _, flag := range flags {
+		if imapFlag, ok := flagToImap[flag]; ok {
+			imapFlags = append(imapFlags, imapFlag)
+		}
+	}
+	return imapFlags
+}
diff --git a/worker/imap/movecopy.go b/worker/imap/movecopy.go
index b01dab7..a53c7d4 100644
--- a/worker/imap/movecopy.go
+++ b/worker/imap/movecopy.go
@@ -28,7 +28,7 @@ func (m appendLiteral) Len() int {
 }
 
 func (imapw *IMAPWorker) handleAppendMessage(msg *types.AppendMessage) {
-	if err := imapw.client.Append(msg.Destination, msg.Flags, msg.Date,
+	if err := imapw.client.Append(msg.Destination, translateFlags(msg.Flags), msg.Date,
 		&appendLiteral{
 			Reader: msg.Reader,
 			Length: msg.Length,
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index ddd95b6..45a2269 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -222,7 +222,7 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) {
 			Info: &models.MessageInfo{
 				BodyStructure: translateBodyStructure(msg.BodyStructure),
 				Envelope:      translateEnvelope(msg.Envelope),
-				Flags:         translateFlags(msg.Flags),
+				Flags:         translateImapFlags(msg.Flags),
 				InternalDate:  msg.InternalDate,
 				Uid:           msg.Uid,
 			},
1-29 21:25:58 -0500 committer Thomas E. Dickey <dickey@invisible-island.net> 1997-01-29 21:25:58 -0500 snapshot of project "lynx", label v2_6fm_970129' href='/ingrix/lynx-snapshots/commit/src/LYexit.c?id=c3ec4181d988501e4d7116f32c669d5ca69e7060'>c3ec4181 ^
e087f6d4
c3ec4181 ^



e4409c40 ^
b6d1143c ^
e4409c40 ^
c3ec4181 ^


b6d1143c ^
e4409c40 ^
b6d1143c ^
e4409c40 ^
c3ec4181 ^


e4409c40 ^
c3ec4181 ^
e4409c40 ^
c3ec4181 ^



b6d1143c ^
c3ec4181 ^



e087f6d4

c3ec4181 ^
e087f6d4
c3ec4181 ^




e4409c40 ^
c3ec4181 ^
e4409c40 ^
c3ec4181 ^









e087f6d4


c3ec4181 ^

e087f6d4



c3ec4181 ^

e087f6d4


c3ec4181 ^
b63d287c ^
c3ec4181 ^




d3f9d547 ^
c3ec4181 ^

e087f6d4

d3f9d547 ^







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174