6
6
"encoding/json"
7
7
"errors"
8
8
"fmt"
9
- "github.com/ProtonMail/go-proton-api/server/backend"
10
9
"net/http"
11
10
"net/mail"
12
11
"net/url"
@@ -17,14 +16,14 @@ import (
17
16
"testing"
18
17
"time"
19
18
20
- "github.com/bradenaw/juniper/parallel"
21
-
22
19
"github.com/Masterminds/semver/v3"
23
20
"github.com/ProtonMail/gluon/async"
24
21
"github.com/ProtonMail/gluon/rfc822"
25
22
"github.com/ProtonMail/go-proton-api"
23
+ "github.com/ProtonMail/go-proton-api/server/backend"
26
24
"github.com/ProtonMail/gopenpgp/v2/crypto"
27
25
"github.com/bradenaw/juniper/iterator"
26
+ "github.com/bradenaw/juniper/parallel"
28
27
"github.com/bradenaw/juniper/stream"
29
28
"github.com/bradenaw/juniper/xslices"
30
29
"github.com/google/uuid"
@@ -2232,6 +2231,89 @@ func TestServer_GetMessageGroupCount(t *testing.T) {
2232
2231
})
2233
2232
}
2234
2233
2234
+ func TestServer_TestDraftActions (t * testing.T ) {
2235
+ withServer (t , func (ctx context.Context , s * Server , m * proton.Manager ) {
2236
+ withUser (ctx , t , s , m , "user" , "pass" , func (c * proton.Client ) {
2237
+ ctx , cancel := context .WithCancel (ctx )
2238
+ defer cancel ()
2239
+
2240
+ user , err := c .GetUser (ctx )
2241
+ require .NoError (t , err )
2242
+
2243
+ addr , err := c .GetAddresses (ctx )
2244
+ require .NoError (t , err )
2245
+
2246
+ salt , err := c .GetSalts (ctx )
2247
+ require .NoError (t , err )
2248
+
2249
+ pass , err := salt .SaltForKey ([]byte ("pass" ), user .Keys .Primary ().ID )
2250
+ require .NoError (t , err )
2251
+
2252
+ _ , addrKRs , err := proton .Unlock (user , addr , pass , async.NoopPanicHandler {})
2253
+ require .NoError (t , err )
2254
+
2255
+ type testData struct {
2256
+ action proton.CreateDraftAction
2257
+ flag proton.MessageFlag
2258
+ }
2259
+
2260
+ tests := []testData {
2261
+ {
2262
+ action : proton .ReplyAction ,
2263
+ flag : proton .MessageFlagReplied ,
2264
+ },
2265
+ {
2266
+ action : proton .ReplyAllAction ,
2267
+ flag : proton .MessageFlagRepliedAll ,
2268
+ },
2269
+ {
2270
+ action : proton .ForwardAction ,
2271
+ flag : proton .MessageFlagForwarded ,
2272
+ },
2273
+ }
2274
+
2275
+ importedMessages := importMessages (ctx , t , c , addr [0 ].ID , addrKRs [addr [0 ].ID ], []string {}, 0 , len (tests ))
2276
+
2277
+ for i := 0 ; i < len (tests ); i ++ {
2278
+ importedMessageID := importedMessages [i ].MessageID
2279
+
2280
+ msg , err := c .GetMessage (ctx , importedMessageID )
2281
+ require .NoError (t , err )
2282
+
2283
+ {
2284
+ kr := addrKRs [addr [0 ].ID ]
2285
+ msg , err := c .CreateDraft (ctx , kr , proton.CreateDraftReq {
2286
+ Message : proton.DraftTemplate {
2287
+ Subject : "Foo" ,
2288
+ Sender : & mail.Address {Address : addr [0 ].Email },
2289
+ ToList : []* mail.Address {{Address : "foo@bar" }},
2290
+ CCList : nil ,
2291
+ BCCList : nil ,
2292
+ },
2293
+ AttachmentKeyPackets : nil ,
2294
+ ParentID : msg .ID ,
2295
+ Action : tests [i ].action ,
2296
+ })
2297
+
2298
+ require .NoError (t , err )
2299
+
2300
+ var sreq proton.SendDraftReq
2301
+
2302
+ require .NoError (t , sreq .AddTextPackage (kr , "Hello" , "text/plain" , map [string ]proton.SendPreferences {}, map [string ]* crypto.SessionKey {}))
2303
+
2304
+ _ , err = c .SendDraft (ctx , msg .ID , sreq )
2305
+ require .NoError (t , err )
2306
+
2307
+ msg , err = c .GetMessage (ctx , importedMessageID )
2308
+ require .NoError (t , err )
2309
+ require .True (t , msg .Flags & tests [i ].flag != 0 )
2310
+ }
2311
+ }
2312
+
2313
+ })
2314
+ })
2315
+ }
2316
+
2235
2317
func withServer (t * testing.T , fn func (ctx context.Context , s * Server , m * proton.Manager ), opts ... Option ) {
2236
2318
ctx , cancel := context .WithCancel (context .Background ())
2237
2319
defer cancel ()
0 commit comments