|
|
@ -58,6 +58,7 @@ import org.json.JSONException;
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
@ -120,6 +121,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
private static final int CONNECT_BACKOFF_MAX = 128; // seconds
|
|
|
|
private static final int CONNECT_BACKOFF_MAX = 128; // seconds
|
|
|
|
private static final long STORE_NOOP_INTERVAL = 9 * 60 * 1000L; // ms
|
|
|
|
private static final long STORE_NOOP_INTERVAL = 9 * 60 * 1000L; // ms
|
|
|
|
private static final long FOLDER_NOOP_INTERVAL = 9 * 60 * 1000L; // ms
|
|
|
|
private static final long FOLDER_NOOP_INTERVAL = 9 * 60 * 1000L; // ms
|
|
|
|
|
|
|
|
private static final int MAX_MESSAGE_BODY_SIZE = 4096;
|
|
|
|
private static final int ATTACHMENT_BUFFER_SIZE = 8192; // bytes
|
|
|
|
private static final int ATTACHMENT_BUFFER_SIZE = 8192; // bytes
|
|
|
|
|
|
|
|
|
|
|
|
static final String ACTION_PROCESS_OPERATIONS = BuildConfig.APPLICATION_ID + ".PROCESS_OPERATIONS";
|
|
|
|
static final String ACTION_PROCESS_OPERATIONS = BuildConfig.APPLICATION_ID + ".PROCESS_OPERATIONS";
|
|
|
@ -1267,6 +1269,9 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
fp1.add(IMAPFolder.FetchProfileItem.MESSAGE);
|
|
|
|
fp1.add(IMAPFolder.FetchProfileItem.MESSAGE);
|
|
|
|
ifolder.fetch(new Message[]{imessage}, fp1);
|
|
|
|
ifolder.fetch(new Message[]{imessage}, fp1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
EntityMessage message = new EntityMessage();
|
|
|
|
EntityMessage message = new EntityMessage();
|
|
|
|
message.account = folder.account;
|
|
|
|
message.account = folder.account;
|
|
|
|
message.folder = folder.id;
|
|
|
|
message.folder = folder.id;
|
|
|
@ -1294,6 +1299,12 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
message.ui_seen = seen;
|
|
|
|
message.ui_seen = seen;
|
|
|
|
message.ui_hide = false;
|
|
|
|
message.ui_hide = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String large = null;
|
|
|
|
|
|
|
|
if (message.body != null && message.body.length() > MAX_MESSAGE_BODY_SIZE) {
|
|
|
|
|
|
|
|
large = message.body;
|
|
|
|
|
|
|
|
message.body = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
message.id = db.message().insertMessage(message);
|
|
|
|
message.id = db.message().insertMessage(message);
|
|
|
|
Log.i(Helper.TAG, folder.name + " added id=" + message.id + " uid=" + message.uid);
|
|
|
|
Log.i(Helper.TAG, folder.name + " added id=" + message.id + " uid=" + message.uid);
|
|
|
|
|
|
|
|
|
|
|
@ -1307,6 +1318,47 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (large != null) {
|
|
|
|
|
|
|
|
sequence++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EntityAttachment attachment = new EntityAttachment();
|
|
|
|
|
|
|
|
attachment.message = message.id;
|
|
|
|
|
|
|
|
attachment.sequence = sequence;
|
|
|
|
|
|
|
|
attachment.name = "body.html"; // TODO: string resource
|
|
|
|
|
|
|
|
attachment.type = "text/html";
|
|
|
|
|
|
|
|
attachment.size = large.length();
|
|
|
|
|
|
|
|
attachment.id = db.attachment().insertAttachment(attachment);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Build filename
|
|
|
|
|
|
|
|
File dir = new File(getFilesDir(), "attachments");
|
|
|
|
|
|
|
|
dir.mkdir();
|
|
|
|
|
|
|
|
File file = new File(dir, Long.toString(attachment.id));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileWriter out = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
out = new FileWriter(file);
|
|
|
|
|
|
|
|
out.write(large);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
Log.e(Helper.TAG, e + "\n" + Log.getStackTraceString(e));
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (out != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
Log.e(Helper.TAG, e + "\n" + Log.getStackTraceString(e));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attachment.filename = file.getName();
|
|
|
|
|
|
|
|
db.attachment().updateAttachment(attachment);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|