Skip to content

Commit 380932c

Browse files
author
Anand
committed
export file wrapped with auto decrypt/encrypt
1 parent d628628 commit 380932c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

actions.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,9 +634,25 @@ func decryptDatabase(dbPath string) (error, string) {
634634
func exportToFile(fileName string) error {
635635

636636
var err error
637-
ext := filepath.Ext(fileName)
637+
var maxKrypt bool
638+
var defaultDB string
639+
var passwd string
640+
641+
maxKrypt, defaultDB = isActiveDatabaseEncryptedAndMaxKryptOn()
642+
643+
ext := strings.ToLower(filepath.Ext(fileName))
644+
645+
if ext == ".csv" || ext == ".md" || ext == ".html" || ext == ".pdf" {
646+
// If max krypt on - then autodecrypt on call and auto encrypt after call
647+
if maxKrypt {
648+
err, passwd = decryptDatabase(defaultDB)
649+
if err != nil {
650+
return err
651+
}
652+
}
653+
}
638654

639-
switch strings.ToLower(ext) {
655+
switch ext {
640656
case ".csv":
641657
err = exportToCsv(fileName)
642658
case ".md":
@@ -657,7 +673,13 @@ func exportToFile(fileName string) error {
657673
fmt.Printf("Exported to %s.\n", fileName)
658674
// Chmod 600
659675
os.Chmod(fileName, 0600)
660-
return nil
676+
677+
// If max krypt on - then autodecrypt on call and auto encrypt after call
678+
if maxKrypt {
679+
err = encryptDatabase(defaultDB, &passwd)
680+
}
681+
682+
return err
661683
}
662684
}
663685

@@ -760,7 +782,7 @@ func exportToPDF(fileName string) error {
760782
}
761783

762784
if pdfTkFound {
763-
fmt.Printf("Password: ")
785+
fmt.Printf("PDF Encryption Password: ")
764786
err, passwd = readPassword()
765787
}
766788

0 commit comments

Comments
 (0)