@@ -3275,24 +3275,19 @@ func (c *conn) cmdAppend(tag, cmd string, p *parser) {
3275
3275
time time.Time
3276
3276
3277
3277
file * os.File // Message file we are appending. Can be nil if we are writing to a nopWriteCloser due to being over quota.
3278
- path string // Path if an actual file, either a temporary file, or of the message file stored in the account.
3279
3278
3280
3279
mw * message.Writer
3281
- m store.Message
3280
+ m store.Message // New message. Delivered file for m.ID is removed on error.
3282
3281
}
3283
3282
3284
3283
var appends []* appendMsg
3285
3284
var commit bool
3286
3285
defer func () {
3287
3286
for _ , a := range appends {
3288
- if a .file != nil {
3289
- err := a .file .Close ()
3290
- c .xsanity (err , "closing APPEND temporary file" )
3291
- }
3292
-
3293
- if ! commit && a .path != "" {
3294
- err := os .Remove (a .path )
3295
- c .xsanity (err , "removing APPEND temporary file" )
3287
+ if ! commit && a .m .ID != 0 {
3288
+ p := c .account .MessagePath (a .m .ID )
3289
+ err := os .Remove (p )
3290
+ c .xsanity (err , "cleaning up temporary append file after error" )
3296
3291
}
3297
3292
}
3298
3293
}()
@@ -3385,7 +3380,7 @@ func (c *conn) cmdAppend(tag, cmd string, p *parser) {
3385
3380
var err error
3386
3381
a .file , err = store .CreateMessageTemp (c .log , "imap-append" )
3387
3382
xcheckf (err , "creating temp file for message" )
3388
- a . path = a .file . Name ( )
3383
+ defer store . CloseRemoveTempFile ( c . log , a .file , "temporary message file" )
3389
3384
f = a .file
3390
3385
3391
3386
c .writelinef ("+ " )
@@ -3398,7 +3393,7 @@ func (c *conn) cmdAppend(tag, cmd string, p *parser) {
3398
3393
var err error
3399
3394
a .file , err = store .CreateMessageTemp (c .log , "imap-append" )
3400
3395
xcheckf (err , "creating temp file for message" )
3401
- a . path = a .file . Name ( )
3396
+ defer store . CloseRemoveTempFile ( c . log , a .file , "temporary message file" )
3402
3397
f = a .file
3403
3398
}
3404
3399
}
@@ -3483,12 +3478,10 @@ func (c *conn) cmdAppend(tag, cmd string, p *parser) {
3483
3478
// todo: do a single junk training
3484
3479
err = c .account .MessageAdd (c .log , tx , & mb , & a .m , a .file , store.AddOpts {SkipDirSync : true })
3485
3480
xcheckf (err , "delivering message" )
3486
- // Update path to what is stored in the account. We may still have to clean it up on errors.
3487
- a .path = c .account .MessagePath (a .m .ID )
3488
3481
3489
3482
changes = append (changes , a .m .ChangeAddUID ())
3490
3483
3491
- msgDirs [filepath .Dir (a . path )] = struct {}{}
3484
+ msgDirs [filepath .Dir (c . account . MessagePath ( a . m . ID ) )] = struct {}{}
3492
3485
}
3493
3486
3494
3487
changes = append (changes , mb .ChangeCounts ())
0 commit comments