about summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-25 14:52:57 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-25 14:52:57 -0400
commit38e71659ff5b386450248c0e56b8797498e2c298 (patch)
tree773f88485ab1823f063b5cca623e7605fa0ef485 /commands
parentcef784bf520470315e93835e9c2828d69de0d5c9 (diff)
downloadaerc-38e71659ff5b386450248c0e56b8797498e2c298.tar.gz
Implement :forward
Diffstat (limited to 'commands')
-rw-r--r--commands/account/reply.go112
1 files changed, 81 insertions, 31 deletions
diff --git a/commands/account/reply.go b/commands/account/reply.go
index 579d671..0e43b88 100644
--- a/commands/account/reply.go
+++ b/commands/account/reply.go
@@ -20,6 +20,7 @@ import (
 
 func init() {
 	register("reply", Reply)
+	register("forward", Reply)
 }
 
 var (
@@ -74,38 +75,44 @@ func Reply(aerc *widgets.Aerc, args []string) error {
 		cc     []string
 		toList []*imap.Address
 	)
-	if len(msg.Envelope.ReplyTo) != 0 {
-		toList = msg.Envelope.ReplyTo
-	} else {
-		toList = msg.Envelope.From
-	}
-	for _, addr := range toList {
-		if addr.PersonalName != "" {
-			to = append(to, fmt.Sprintf("%s <%s@%s>",
-				addr.PersonalName, addr.MailboxName, addr.HostName))
+	if args[0] == "reply" {
+		if len(msg.Envelope.ReplyTo) != 0 {
+			toList = msg.Envelope.ReplyTo
 		} else {
-			to = append(to, fmt.Sprintf("<%s@%s>",
-				addr.MailboxName, addr.HostName))
+			toList = msg.Envelope.From
 		}
-	}
-	if replyAll {
-		for _, addr := range msg.Envelope.Cc {
-			cc = append(cc, formatAddress(addr))
+		for _, addr := range toList {
+			if addr.PersonalName != "" {
+				to = append(to, fmt.Sprintf("%s <%s@%s>",
+					addr.PersonalName, addr.MailboxName, addr.HostName))
+			} else {
+				to = append(to, fmt.Sprintf("<%s@%s>",
+					addr.MailboxName, addr.HostName))
+			}
 		}
-		for _, addr := range msg.Envelope.To {
-			address := fmt.Sprintf("%s@%s", addr.MailboxName, addr.HostName)
-			if address == us.Address {
-				continue
+		if replyAll {
+			for _, addr := range msg.Envelope.Cc {
+				cc = append(cc, formatAddress(addr))
+			}
+			for _, addr := range msg.Envelope.To {
+				address := fmt.Sprintf("%s@%s", addr.MailboxName, addr.HostName)
+				if address == us.Address {
+					continue
+				}
+				to = append(to, formatAddress(addr))
 			}
-			to = append(to, formatAddress(addr))
 		}
 	}
 
 	var subject string
-	if !strings.HasPrefix(msg.Envelope.Subject, "Re: ") {
-		subject = "Re: " + msg.Envelope.Subject
+	if args[0] == "forward" {
+		subject = "Fwd: " + msg.Envelope.Subject
 	} else {
-		subject = msg.Envelope.Subject
+		if !strings.HasPrefix(msg.Envelope.Subject, "Re: ") {
+			subject = "Re: " + msg.Envelope.Subject
+		} else {
+			subject = msg.Envelope.Subject
+		}
 	}
 
 	composer := widgets.NewComposer(
@@ -115,8 +122,11 @@ func Reply(aerc *widgets.Aerc, args []string) error {
 			"Cc":          strings.Join(cc, ", "),
 			"Subject":     subject,
 			"In-Reply-To": msg.Envelope.MessageId,
-		}).
-		FocusTerminal()
+		})
+
+	if args[0] == "reply" {
+		composer.FocusTerminal()
+	}
 
 	addTab := func() {
 		tab := aerc.NewTab(composer, subject)
@@ -130,8 +140,9 @@ func Reply(aerc *widgets.Aerc, args []string) error {
 		})
 	}
 
-	if quote {
+	if args[0] == "forward" {
 		// TODO: something more intelligent than fetching the 1st part
+		// TODO: add attachments!
 		store.FetchBodyPart(msg.Uid, []int{1}, func(reader io.Reader) {
 			header := message.Header{}
 			header.SetText(
@@ -157,18 +168,57 @@ func Reply(aerc *widgets.Aerc, args []string) error {
 			scanner := bufio.NewScanner(part.Body)
 			go composer.SetContents(pipeout)
 			// TODO: Let user customize the date format used here
-			io.WriteString(pipein, fmt.Sprintf("On %s %s wrote:\n",
-				msg.Envelope.Date.Format("Mon Jan 2, 2006 at 3:04 PM"),
-				msg.Envelope.From[0].PersonalName))
+			io.WriteString(pipein, fmt.Sprintf("Forwarded message from %s on %s:\n\n",
+				msg.Envelope.From[0].PersonalName,
+				msg.Envelope.Date.Format("Mon Jan 2, 2006 at 3:04 PM")))
 			for scanner.Scan() {
-				io.WriteString(pipein, fmt.Sprintf("> %s\n", scanner.Text()))
+				io.WriteString(pipein, fmt.Sprintf("%s\n", scanner.Text()))
 			}
 			pipein.Close()
 			pipeout.Close()
 			addTab()
 		})
 	} else {
-		addTab()
+		if quote {
+			// TODO: something more intelligent than fetching the 1st part
+			store.FetchBodyPart(msg.Uid, []int{1}, func(reader io.Reader) {
+				header := message.Header{}
+				header.SetText(
+					"Content-Transfer-Encoding", msg.BodyStructure.Encoding)
+				header.SetContentType(
+					msg.BodyStructure.MIMEType, msg.BodyStructure.Params)
+				header.SetText("Content-Description", msg.BodyStructure.Description)
+				entity, err := message.New(header, reader)
+				if err != nil {
+					// TODO: Do something with the error
+					addTab()
+					return
+				}
+				mreader := mail.NewReader(entity)
+				part, err := mreader.NextPart()
+				if err != nil {
+					// TODO: Do something with the error
+					addTab()
+					return
+				}
+
+				pipeout, pipein := io.Pipe()
+				scanner := bufio.NewScanner(part.Body)
+				go composer.SetContents(pipeout)
+				// TODO: Let user customize the date format used here
+				io.WriteString(pipein, fmt.Sprintf("On %s %s wrote:\n",
+					msg.Envelope.Date.Format("Mon Jan 2, 2006 at 3:04 PM"),
+					msg.Envelope.From[0].PersonalName))
+				for scanner.Scan() {
+					io.WriteString(pipein, fmt.Sprintf("> %s\n", scanner.Text()))
+				}
+				pipein.Close()
+				pipeout.Close()
+				addTab()
+			})
+		} else {
+			addTab()
+		}
 	}
 
 	return nil
on' href='/acidbong/suckless/dwm/blame/draw.c?h=1.4&id=5b44976a2d8bdd1397727663ce019374d6b2730a'>^
650a1fb ^
975b459 ^












0025572 ^
39677ec ^
8a34fa5 ^

4250c26 ^
4d67199 ^
8a34fa5 ^

39677ec ^
8a34fa5 ^

650a1fb ^


8a34fa5 ^

9e8b325 ^
8a34fa5 ^
4d67199 ^
28a5219 ^



4d67199 ^
28a5219 ^
4d67199 ^
8a34fa5 ^
650a1fb ^
8a34fa5 ^

e7fa504 ^

650a1fb ^


8a34fa5 ^


650a1fb ^


8a34fa5 ^


bf35794 ^
c09bf8d ^





937cabf ^
c09bf8d ^






4688ad1 ^
c09bf8d ^



4250c26 ^
c09bf8d ^

b355755 ^
c09bf8d ^


292ccc4 ^
c09bf8d ^
292ccc4 ^
c09bf8d ^
4688ad1 ^
c09bf8d ^

4250c26 ^
4688ad1 ^

4250c26 ^
4688ad1 ^
c09bf8d ^
e6cbe9c ^
c09bf8d ^

adaa28a ^





fde45eb ^
adaa28a ^











b355755 ^
adaa28a ^

8cc7f3b ^
4250c26 ^
adaa28a ^


28a5219 ^
4250c26 ^
e6cbe9c ^

adaa28a ^

9e8b325 ^
c0705ee ^
8a34fa5 ^
9e8b325 ^
dc5d967 ^
9e8b325 ^
8a34fa5 ^



8a34fa5 ^
c0705ee ^
8a34fa5 ^

d7e1708 ^
8a34fa5 ^
8a8b795 ^
8a34fa5 ^
9e8b325 ^


8a34fa5 ^



9e8b325 ^


8a34fa5 ^

9e8b325 ^
8a34fa5 ^


8a34fa5 ^
9e8b325 ^







8a34fa5 ^



9e8b325 ^






dba2306 ^
9e8b325 ^

8a34fa5 ^
9e8b325 ^
8a34fa5 ^
adaa28a ^

8cc7f3b ^
adaa28a ^


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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234