|
|
|
@ -114,9 +114,9 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
|
|
|
|
|
public ServiceSynchronize() {
|
|
|
|
|
// https://docs.oracle.com/javaee/6/api/javax/mail/internet/package-summary.html
|
|
|
|
|
System.setProperty("mail.mime.ignoreunknownencoding" , "true");
|
|
|
|
|
System.setProperty("mail.mime.decodefilename" , "true");
|
|
|
|
|
System.setProperty("mail.mime.encodefilename" , "true");
|
|
|
|
|
System.setProperty("mail.mime.ignoreunknownencoding", "true");
|
|
|
|
|
System.setProperty("mail.mime.decodefilename", "true");
|
|
|
|
|
System.setProperty("mail.mime.encodefilename", "true");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -178,6 +178,21 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
Log.i(Helper.TAG, "Service start");
|
|
|
|
|
super.onStartCommand(intent, flags, startId);
|
|
|
|
|
|
|
|
|
|
if ("unseen".equals(intent.getAction())) {
|
|
|
|
|
final long now = new Date().getTime();
|
|
|
|
|
executor.submit(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
DaoAccount dao = DB.getInstance(ServiceSynchronize.this).account();
|
|
|
|
|
for (EntityAccount account : dao.getAccounts(true)) {
|
|
|
|
|
account.seen_until = now;
|
|
|
|
|
dao.updateAccount(account);
|
|
|
|
|
}
|
|
|
|
|
Log.i(Helper.TAG, "Updated seen until");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return START_STICKY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -217,6 +232,10 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
PendingIntent pi = PendingIntent.getActivity(
|
|
|
|
|
this, ActivityView.REQUEST_UNSEEN, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
Intent delete = new Intent(this, ServiceSynchronize.class);
|
|
|
|
|
delete.setAction("unseen");
|
|
|
|
|
PendingIntent pid = PendingIntent.getService(this, 1, delete, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
|
|
|
|
|
|
|
|
// Build notification
|
|
|
|
@ -231,11 +250,11 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
.setContentTitle(getString(R.string.title_notification_unseen, unseen))
|
|
|
|
|
.setContentIntent(pi)
|
|
|
|
|
.setSound(uri)
|
|
|
|
|
.setOngoing(true)
|
|
|
|
|
.setShowWhen(false)
|
|
|
|
|
.setPriority(Notification.PRIORITY_DEFAULT)
|
|
|
|
|
.setCategory(Notification.CATEGORY_STATUS)
|
|
|
|
|
.setVisibility(Notification.VISIBILITY_PUBLIC);
|
|
|
|
|
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
|
|
|
|
.setDeleteIntent(pid);
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
@ -284,8 +303,8 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
IMAPStore istore = null;
|
|
|
|
|
try {
|
|
|
|
|
Properties props = MessageHelper.getSessionProperties();
|
|
|
|
|
props.put("mail.imaps.peek" , "true");
|
|
|
|
|
props.setProperty("mail.mime.address.strict" , "false");
|
|
|
|
|
props.put("mail.imaps.peek", "true");
|
|
|
|
|
props.setProperty("mail.mime.address.strict", "false");
|
|
|
|
|
//props.put("mail.imaps.minidletime", "5000");
|
|
|
|
|
Session isession = Session.getInstance(props, null);
|
|
|
|
|
// isession.setDebug(true);
|
|
|
|
@ -390,7 +409,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
if (!EntityFolder.TYPE_OUTBOX.equals(folder.type))
|
|
|
|
|
lbm.sendBroadcast(new Intent(ACTION_PROCESS_FOLDER)
|
|
|
|
|
.setType("account/" + account.id)
|
|
|
|
|
.putExtra("folder" , folder.id));
|
|
|
|
|
.putExtra("folder", folder.id));
|
|
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.e(Helper.TAG, account.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
@ -442,7 +461,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
BroadcastReceiver processReceiver = new BroadcastReceiver() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
final long fid = intent.getLongExtra("folder" , -1);
|
|
|
|
|
final long fid = intent.getLongExtra("folder", -1);
|
|
|
|
|
|
|
|
|
|
IMAPFolder ifolder;
|
|
|
|
|
synchronized (mapFolder) {
|
|
|
|
@ -796,7 +815,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
Address[] to = imessage.getAllRecipients();
|
|
|
|
|
itransport.sendMessage(imessage, to);
|
|
|
|
|
Log.i(Helper.TAG, "Sent via " + ident.host + "/" + ident.user +
|
|
|
|
|
" to " + TextUtils.join(", " , to));
|
|
|
|
|
" to " + TextUtils.join(", ", to));
|
|
|
|
|
|
|
|
|
|
msg.sent = new Date().getTime();
|
|
|
|
|
msg.seen = true;
|
|
|
|
@ -917,7 +936,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (candidate) {
|
|
|
|
|
Log.i(Helper.TAG, ifolder.getFullName() + " candidate attr=" + TextUtils.join("," , attrs));
|
|
|
|
|
Log.i(Helper.TAG, ifolder.getFullName() + " candidate attr=" + TextUtils.join(",", attrs));
|
|
|
|
|
EntityFolder folder = dao.getFolderByName(account.id, ifolder.getFullName());
|
|
|
|
|
if (folder == null) {
|
|
|
|
|
folder = new EntityFolder();
|
|
|
|
@ -1066,7 +1085,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
message.folder = folder.id;
|
|
|
|
|
message.uid = uid;
|
|
|
|
|
message.msgid = helper.getMessageID();
|
|
|
|
|
message.references = TextUtils.join(" " , helper.getReferences());
|
|
|
|
|
message.references = TextUtils.join(" ", helper.getReferences());
|
|
|
|
|
message.inreplyto = helper.getInReplyTo();
|
|
|
|
|
message.thread = helper.getThreadId(uid);
|
|
|
|
|
message.from = helper.getFrom();
|
|
|
|
@ -1119,7 +1138,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
|
|
|
|
public Object doCommand(IMAPProtocol p) throws ProtocolException {
|
|
|
|
|
Log.i(Helper.TAG, ifolder.getName() + " start NOOP");
|
|
|
|
|
p.simpleCommand("NOOP" , null);
|
|
|
|
|
p.simpleCommand("NOOP", null);
|
|
|
|
|
Log.i(Helper.TAG, ifolder.getName() + " end NOOP");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
@ -1232,20 +1251,20 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
NotificationManager nm = context.getSystemService(NotificationManager.class);
|
|
|
|
|
|
|
|
|
|
NotificationChannel service = new NotificationChannel(
|
|
|
|
|
"service" ,
|
|
|
|
|
"service",
|
|
|
|
|
context.getString(R.string.channel_service),
|
|
|
|
|
NotificationManager.IMPORTANCE_MIN);
|
|
|
|
|
service.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
|
|
|
|
nm.createNotificationChannel(service);
|
|
|
|
|
|
|
|
|
|
NotificationChannel notification = new NotificationChannel(
|
|
|
|
|
"notification" ,
|
|
|
|
|
"notification",
|
|
|
|
|
context.getString(R.string.channel_notification),
|
|
|
|
|
NotificationManager.IMPORTANCE_DEFAULT);
|
|
|
|
|
nm.createNotificationChannel(notification);
|
|
|
|
|
|
|
|
|
|
NotificationChannel error = new NotificationChannel(
|
|
|
|
|
"error" ,
|
|
|
|
|
"error",
|
|
|
|
|
context.getString(R.string.channel_error),
|
|
|
|
|
NotificationManager.IMPORTANCE_HIGH);
|
|
|
|
|
nm.createNotificationChannel(error);
|
|
|
|
|