mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-11 11:33:09 +02:00
Added inline unzip
This commit is contained in:
@@ -166,6 +166,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
||||
private SwitchCompat swImagesPlaceholders;
|
||||
private SwitchCompat swImagesInline;
|
||||
private SwitchCompat swButtonExtra;
|
||||
private SwitchCompat swUnzip;
|
||||
private SwitchCompat swAttachmentsAlt;
|
||||
private SwitchCompat swThumbnails;
|
||||
|
||||
@@ -197,7 +198,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
||||
"message_zoom", "overview_mode", "override_width",
|
||||
"display_font", "contrast", "monospaced_pre",
|
||||
"background_color", "text_color", "text_size", "text_font", "text_align", "text_separators",
|
||||
"collapse_quotes", "image_placeholders", "inline_images", "button_extra", "attachments_alt", "thumbnails",
|
||||
"collapse_quotes", "image_placeholders", "inline_images", "button_extra",
|
||||
"unzip", "attachments_alt", "thumbnails",
|
||||
"bundled_fonts", "parse_classes",
|
||||
"authentication", "authentication_indicator"
|
||||
};
|
||||
@@ -314,6 +316,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
||||
swImagesPlaceholders = view.findViewById(R.id.swImagesPlaceholders);
|
||||
swImagesInline = view.findViewById(R.id.swImagesInline);
|
||||
swButtonExtra = view.findViewById(R.id.swButtonExtra);
|
||||
swUnzip = view.findViewById(R.id.swUnzip);
|
||||
swAttachmentsAlt = view.findViewById(R.id.swAttachmentsAlt);
|
||||
swThumbnails = view.findViewById(R.id.swThumbnails);
|
||||
swBundledFonts = view.findViewById(R.id.swBundledFonts);
|
||||
@@ -1165,6 +1168,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
||||
}
|
||||
});
|
||||
|
||||
swUnzip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("unzip", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
swAttachmentsAlt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
@@ -1430,6 +1440,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
|
||||
swImagesPlaceholders.setChecked(prefs.getBoolean("image_placeholders", true));
|
||||
swImagesInline.setChecked(prefs.getBoolean("inline_images", false));
|
||||
swButtonExtra.setChecked(prefs.getBoolean("button_extra", false));
|
||||
swUnzip.setChecked(prefs.getBoolean("unzip", false));
|
||||
swAttachmentsAlt.setChecked(prefs.getBoolean("attachments_alt", false));
|
||||
swThumbnails.setChecked(prefs.getBoolean("thumbnails", true));
|
||||
|
||||
|
||||
@@ -94,6 +94,8 @@ import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.FileDataSource;
|
||||
@@ -3372,6 +3374,77 @@ public class MessageHelper {
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
|
||||
else if ("application/zip".equals(local.type)) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean unzip = prefs.getBoolean("unzip", false);
|
||||
|
||||
if (unzip) {
|
||||
// https://developer.android.com/reference/java/util/zip/ZipInputStream
|
||||
try (ZipInputStream zis = new ZipInputStream(
|
||||
new BufferedInputStream(new FileInputStream(local.getFile(context))))) {
|
||||
|
||||
int subsequence = 1;
|
||||
|
||||
ZipEntry ze;
|
||||
while ((ze = zis.getNextEntry()) != null)
|
||||
try {
|
||||
String name = ze.getName();
|
||||
long total = ze.getSize();
|
||||
|
||||
// isDirectory:
|
||||
// A directory entry is defined to be one whose name ends with a '/'.
|
||||
if (ze.isDirectory() ||
|
||||
(name != null && name.endsWith("\\"))) {
|
||||
Log.i("Zipped folder=" + name);
|
||||
continue;
|
||||
}
|
||||
|
||||
Log.i("Zipped attachment seq=" + local.sequence + ":" + subsequence +
|
||||
" " + name + ":" + total);
|
||||
|
||||
EntityAttachment entry = new EntityAttachment();
|
||||
entry.message = local.message;
|
||||
entry.sequence = local.sequence;
|
||||
entry.subsequence = subsequence++;
|
||||
entry.name = name;
|
||||
entry.type = Helper.guessMimeType(entry.name);
|
||||
entry.size = total;
|
||||
entry.id = db.attachment().insertAttachment(entry);
|
||||
|
||||
File efile = entry.getFile(context);
|
||||
Log.i("Unzipping to " + efile);
|
||||
|
||||
int last = 0;
|
||||
long size = 0;
|
||||
try (OutputStream os = new FileOutputStream(efile)) {
|
||||
byte[] buffer = new byte[Helper.BUFFER_SIZE];
|
||||
for (int len = zis.read(buffer); len != -1; len = zis.read(buffer)) {
|
||||
size += len;
|
||||
os.write(buffer, 0, len);
|
||||
|
||||
int progress = (int) (size * 100 / total);
|
||||
if (progress / 20 > last / 20) {
|
||||
last = progress;
|
||||
db.attachment().setProgress(entry.id, progress);
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
db.attachment().setError(entry.id, Log.formatThrowable(ex));
|
||||
db.attachment().setAvailable(entry.id, true); // unrecoverable
|
||||
}
|
||||
|
||||
db.attachment().setDownloaded(entry.id, efile.length());
|
||||
} finally {
|
||||
zis.closeEntry();
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
db.attachment().setError(local.id, Log.formatThrowable(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user