1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-24 17:45:50 +01:00

K-9 Mail notifications: Hopefully fix #7 and #8

K-9 Mail seems to completely ignore the where clause when querying for messages.
That is why we got data from the newest message instead of the one requested.
Work around by walking through the messages and match the uri manually.
This is not as expensive as I thought because in most cases it is the first
message is the one we want anyway.
This commit is contained in:
Andreas Shimokawa 2015-03-16 16:18:11 +01:00
parent eeb74b4c61
commit 2260d60bac

View File

@ -28,19 +28,36 @@ public class K9Receiver extends BroadcastReceiver {
}
}
// get sender and subject from the Intent
String sender = intent.getStringExtra("com.fsck.k9.intent.extra.FROM");
String subject = intent.getStringExtra("com.fsck.k9.intent.extra.SUBJECT");
String uriWanted = intent.getData().toString();
// get preview from K9 Content Provider, unfortunately this does not come with the Intent
String[] whereParameters = {intent.getData().toString()};
String[] messagesProjection = {
"preview"
"senderAddress",
"subject",
"preview",
"uri"
};
Cursor c = context.getContentResolver().query(k9Uri, null, "uri=?", whereParameters, " LIMIT 1");
String sender = "";
String subject = "";
String preview = "";
/*
* there seems to be no way to specify the the uri in the where clause.
* If we do so, we just get the newest message, not the one requested.
* So, we will just search our message and match the uri manually.
* It should be the first one returned by the query in most cases,
*/
Cursor c = context.getContentResolver().query(k9Uri, messagesProjection, null, null, null);
c.moveToFirst();
String preview = c.getString(c.getColumnIndex("preview"));
do {
String uri = c.getString(c.getColumnIndex("uri"));
if (uri.equals(uriWanted)) {
sender = c.getString(c.getColumnIndex("senderAddress"));
subject = c.getString(c.getColumnIndex("subject"));
preview = c.getString(c.getColumnIndex("preview"));
break;
}
} while (c.moveToNext());
c.close();
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);