Optimize attachment file handling
QuickLookView (a struct in AttPreview.swift) previews the content of files. It is currently used to
- a) preview attachment files of received or sent E-Mails and
- b) while writing/composing mails
To view the content of a file correctly, QuickLookView has to write the file data into the Documents Directory (DD) otherwise only a default content preview (name of the file) will be shown.
There are some problems/simplifications needed:
-
Currently the files are downloaded into the DD rather simplistic. A new file is created by appending the filename to the path of the DD
create new file at: DDPath/filename
and the data is written into that new file.
If we however receive or send two attachment files with the same filename, the newer one would be written onto the older one and we would preview two identical files even if they are different. Therefore some unique filenames, subdirectories etc. should be introduced.
- It should be checked whether the DD is as lean as possible. If we do not clean it regularly the DD will accumulate a huge amount of files over time. Therefore we should delete files as soon as possible. From my understanding it would be only necessary to keep the files in the DD as long as the QuickLookView file previews are "alive", that means when a user a) opens and reads an E-Mail containing attachments or b) writes an E-Mail using ComposeView. After closing the E-Mail or sending the E-Mail we can delete the files from the DD. We should not need to worry about loosing the file data from sent/received E-Mails. They should be stored in the Database that stores all the sent/received E-Mails. It is therefore only redundant and inefficient to keep them in the DD as well.
This is already implemented for b) writing E-Mails.
- There seems to be a lot of redundancy going on between the 'AttPrev' struct (which calls and uses QuickLookView) in AttachmentsViewMain and AttPreviews 'QuickLookView' struct. The responsibilities for downloading and deleting should be clear: for example the current solution for b) writing E-Mails assumes that QuickLookView takes responsibility for writing the file data into the DD, while the responsibility to delete the files lies with the "Caller". That should maybe be copied for a) opening/reading E-Mails.