|
|
@ -50,7 +50,6 @@ import com.sun.mail.util.FolderClosedIOException;
|
|
|
|
import com.sun.mail.util.MessageRemovedIOException;
|
|
|
|
import com.sun.mail.util.MessageRemovedIOException;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveEntry;
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveEntry;
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveException;
|
|
|
|
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
|
|
|
|
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
|
|
|
|
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
|
|
|
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
|
|
@ -99,8 +98,6 @@ import java.util.TimeZone;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
|
|
|
import java.util.zip.ZipInputStream;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.activation.DataHandler;
|
|
|
|
import javax.activation.DataHandler;
|
|
|
|
import javax.activation.FileDataSource;
|
|
|
|
import javax.activation.FileDataSource;
|
|
|
@ -149,7 +146,8 @@ public class MessageHelper {
|
|
|
|
static final String HEADER_CORRELATION_ID = "X-Correlation-ID";
|
|
|
|
static final String HEADER_CORRELATION_ID = "X-Correlation-ID";
|
|
|
|
static final int MAX_SUBJECT_AGE = 48; // hours
|
|
|
|
static final int MAX_SUBJECT_AGE = 48; // hours
|
|
|
|
static final int DEFAULT_THREAD_RANGE = 7; // 2^7 = 128 days
|
|
|
|
static final int DEFAULT_THREAD_RANGE = 7; // 2^7 = 128 days
|
|
|
|
static final int MAX_UNZIP = 10;
|
|
|
|
static final int MAX_UNZIP_COUNT = 20;
|
|
|
|
|
|
|
|
static final long MAX_UNZIP_SIZE = 1000 * 1000 * 1000L;
|
|
|
|
|
|
|
|
|
|
|
|
static final List<String> RECEIVED_WORDS = Collections.unmodifiableList(Arrays.asList(
|
|
|
|
static final List<String> RECEIVED_WORDS = Collections.unmodifiableList(Arrays.asList(
|
|
|
|
"from", "by", "via", "with", "id", "for"
|
|
|
|
"from", "by", "via", "with", "id", "for"
|
|
|
@ -3395,46 +3393,48 @@ public class MessageHelper {
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Gzipped attachment seq=" + local.sequence + " " + name + ":" + total);
|
|
|
|
Log.i("Gzipped attachment seq=" + local.sequence + " " + name + ":" + total);
|
|
|
|
|
|
|
|
|
|
|
|
if (name == null &&
|
|
|
|
if (total <= MAX_UNZIP_SIZE) {
|
|
|
|
local.name != null && local.name.endsWith(".gz"))
|
|
|
|
if (name == null &&
|
|
|
|
name = local.name.substring(0, local.name.length() - 3);
|
|
|
|
local.name != null && local.name.endsWith(".gz"))
|
|
|
|
|
|
|
|
name = local.name.substring(0, local.name.length() - 3);
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
|
|
|
attachment.message = local.message;
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
attachment.sequence = local.sequence;
|
|
|
|
attachment.message = local.message;
|
|
|
|
attachment.subsequence = 1;
|
|
|
|
attachment.sequence = local.sequence;
|
|
|
|
attachment.name = name;
|
|
|
|
attachment.subsequence = 1;
|
|
|
|
attachment.type = Helper.guessMimeType(name);
|
|
|
|
attachment.name = name;
|
|
|
|
if (total >= 0)
|
|
|
|
attachment.type = Helper.guessMimeType(name);
|
|
|
|
attachment.size = total;
|
|
|
|
if (total >= 0)
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
attachment.size = total;
|
|
|
|
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
File efile = attachment.getFile(context);
|
|
|
|
|
|
|
|
Log.i("Gunzipping to " + efile);
|
|
|
|
File efile = attachment.getFile(context);
|
|
|
|
|
|
|
|
Log.i("Gunzipping to " + efile);
|
|
|
|
int last = 0;
|
|
|
|
|
|
|
|
long size = 0;
|
|
|
|
int last = 0;
|
|
|
|
try (OutputStream os = new FileOutputStream(efile)) {
|
|
|
|
long size = 0;
|
|
|
|
byte[] buffer = new byte[Helper.BUFFER_SIZE];
|
|
|
|
try (OutputStream os = new FileOutputStream(efile)) {
|
|
|
|
for (int len = gzip.read(buffer); len != -1; len = gzip.read(buffer)) {
|
|
|
|
byte[] buffer = new byte[Helper.BUFFER_SIZE];
|
|
|
|
size += len;
|
|
|
|
for (int len = gzip.read(buffer); len != -1; len = gzip.read(buffer)) {
|
|
|
|
os.write(buffer, 0, len);
|
|
|
|
size += len;
|
|
|
|
|
|
|
|
os.write(buffer, 0, len);
|
|
|
|
if (total > 0) {
|
|
|
|
|
|
|
|
int progress = (int) (size * 100 / total);
|
|
|
|
if (total > 0) {
|
|
|
|
if (progress / 20 > last / 20) {
|
|
|
|
int progress = (int) (size * 100 / total);
|
|
|
|
last = progress;
|
|
|
|
if (progress / 20 > last / 20) {
|
|
|
|
db.attachment().setProgress(attachment.id, progress);
|
|
|
|
last = progress;
|
|
|
|
|
|
|
|
db.attachment().setProgress(attachment.id, progress);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
db.attachment().setError(attachment.id, Log.formatThrowable(ex));
|
|
|
|
|
|
|
|
db.attachment().setAvailable(attachment.id, true); // unrecoverable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
|
|
|
db.attachment().setError(attachment.id, Log.formatThrowable(ex));
|
|
|
|
|
|
|
|
db.attachment().setAvailable(attachment.id, true); // unrecoverable
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.attachment().setDownloaded(attachment.id, efile.length());
|
|
|
|
db.attachment().setDownloaded(attachment.id, efile.length());
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
Log.e(ex);
|
|
|
|
db.attachment().setWarning(local.id, Log.formatThrowable(ex));
|
|
|
|
db.attachment().setWarning(local.id, Log.formatThrowable(ex));
|
|
|
@ -3447,12 +3447,15 @@ public class MessageHelper {
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
ArchiveEntry entry;
|
|
|
|
ArchiveEntry entry;
|
|
|
|
while ((entry = ais.getNextEntry()) != null)
|
|
|
|
while ((entry = ais.getNextEntry()) != null)
|
|
|
|
if (ais.canReadEntryData(entry) && !entry.isDirectory())
|
|
|
|
if (ais.canReadEntryData(entry) && !entry.isDirectory()) {
|
|
|
|
if (++count > MAX_UNZIP)
|
|
|
|
if (entry.getSize() > MAX_UNZIP_SIZE)
|
|
|
|
|
|
|
|
count = MAX_UNZIP_COUNT;
|
|
|
|
|
|
|
|
if (++count > MAX_UNZIP_COUNT)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Zip entries=" + count);
|
|
|
|
Log.i("Zip entries=" + count);
|
|
|
|
if (count <= MAX_UNZIP) {
|
|
|
|
if (count <= MAX_UNZIP_COUNT) {
|
|
|
|
fis.getChannel().position(0);
|
|
|
|
fis.getChannel().position(0);
|
|
|
|
|
|
|
|
|
|
|
|
ais = new ArchiveStreamFactory().createArchiveInputStream(
|
|
|
|
ais = new ArchiveStreamFactory().createArchiveInputStream(
|
|
|
|