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