Author Topic: Tasker Integration Issue  (Read 8512 times)

lueq

  • Newbie
  • *
  • Posts: 7
Tasker Integration Issue
« on: February 26, 2016, 03:30:22 am »
I just started to use AquaMail because of its Tasker integration.
I am using Automagic, a Tasker alternative which supports Tasker plugins, to automate some stuff on my Galaxy S5.
I am trying to monitor my incoming mails and trigger special alerts if I get a mail from a favorite (starred) contact in my address book.
Overall this functionality works, but I have come across one issue that seems to make it not work in some cases.

The filter conditions are too complex to enter into AquaMail plugin conditions. Therefore I did not define any conditions/filters in the plugin and do all filtering within Automagic. This way it is also much more flexible - I just need to star/unstar a contact in my address book and it will be included or excluded in the special handling automatically.
However it seems that Automagic only gets information about one email from AquaMail if more than one email was received in one mail check process. That's my observation and I also read statements to thisets effect in other threads on this forum. So if I received an email from a starred contact together with other emails, it would be a matter of luck whether it triggered the special treatment or not, depending on its position in the batch of mails.

Is there any way to receive information for every new email, even if more than one email was received in the same mail check cycle?
If that functionality does not exist, would you consider adding it to the plugin functionality? Maybe as an additional option that you can activate explicitly?
The information about multiple emails could either be supplied in separate calls/triggers (don't know the details of which app calls which), or alternatively the multiple emails could be provided as lists or arrays.
For example, the plugin could have an option "return one/return all" (or "max number of emails returned" to allow for an upper limit). And if "return all" was selected, it could return the actual count of emails in a variable, and each of the other AquaMail variables such as aqmfrom etc. would contain an array or a list of values, with one entry for each email. This way the overall structure wouldn't change very much and the data could be processed easily in Automagic (or Tasker).

I would consider this a nice improvement, and I assume I wouldn't be alone with it.

Thanks for your consideration!

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12742
Re: Tasker Integration Issue
« Reply #1 on: February 26, 2016, 05:17:39 pm »
Yes, it is true.

This feature isn't really intended to be used for message filtering.

In any case, it could be changed, but...

Last time I discussed it with Pent (a long time ago), he was going to implement some optimizations so that checking every single message vs. every single condition wouldn't get too slow.

I don't know where Tasker is wrt. to this now, maybe you could find out?

There does not appear to be any new info here:

http://tasker.dinglisch.net/plugins.html

If you read under "Tasker Event Plugin Extension" you'll see that right now the protocol is like this:

1. Plugin to Tasker: "something's changed, maybe, possibly, but I don't know"

2. Tasker to Plugin: "here is the actual condition, please check if it matches what's changed"

Right now the "iota" of "something's changed" is a "batch" of messages, not a single message.
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

lueq

  • Newbie
  • *
  • Posts: 7
Re: Tasker Integration Issue
« Reply #2 on: February 27, 2016, 04:42:30 am »
Thanks for the response and confirmation of the functionality.

I took a look at the link you provided, but it's too technical for me to understand easily and I don't want to spend a lot of time trying to dig deeper, especially given that I am not really using Tasker but just the plugin support.

Too bad it works the way it does. My tests indicate that K-9 Mail provides a trigger for each email, even if I get multiple ones in a mail check cycle.
In many ways I don't like it as much as AquaMail but this functionality is important to me, so I guess that's the easiest way out for me.
Maybe you'll change the AquaMail functionality at some time and I can use it, but I understand if you don't do that just on my request.

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12742
Re: Tasker Integration Issue
« Reply #3 on: February 28, 2016, 06:26:04 pm »
Re: K-9 Mail provides a trigger for each email

K9 / Tasker integration 1) was done by Pent himself and 2) is a one-off, a special case, just for K9 Mail specifically.

Aqua's integration 1) was done by me 2) uses the general purpose "events" mechanism added to Tasker since 4.4 or so

This general mechanism, I think, can be too slow if it checked every single message vs. every single rule.

Pent was going to implement an optimization, but I don't know if he has.
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

lueq

  • Newbie
  • *
  • Posts: 7
Re: Tasker Integration Issue
« Reply #4 on: February 28, 2016, 07:41:56 pm »
I see. So the Aquamail integration uses a different mechanism than the K9 integration.

As I understand it now, K9 sends a broadcast intent to let all interested apps know about each new mail. Apps can register themselves in the system to be informed when such a broadcast is sent.
I use Automagic, not Tasker, and K9 mail received integration does not require a plugin there. From what you say Tasker also has it built-in. So the broadcast intents from K9 allow these apps to react to each email received.

Could you also provide an option for Aquamail to send such broadcast intents, maybe even in the same format as K9 does, just with your own package name?
Then the integration would be very simple for any app that wants to support it. I am confident that the Automagic developer would add it to his app, and probably the Tasker developer, too.
And I don't think there would be a performance impact, as your app just broadcasts an intent and doesn't wait for anyone to respond.
The K9 intent is com.fsck.k9.intent.action.EMAIL_RECEIVED. You can find details about it at github.com/k9mail/k-9/wiki/Intents (This forum doesn't allow me to post the full link).

The current plugin-based integration is somewhat counter-intuitive. When I read about the AquaMail integration, I assumed it would work for each email, not just one of the mail cycle. I am sure I'm not the only one who would make this assumption, because that's the way I have experienced other integrations, and that would make the most sense.

I believe it would be a valuable improvement for AquaMail to support the broadcast intent based form of integration.

Thanks!


Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12742
Re: Tasker Integration Issue
« Reply #5 on: February 28, 2016, 09:47:37 pm »
Re: Could you also provide an option for Aquamail to send such broadcast intents, maybe even in the same format as K9 does, just with your own package name?

There already are some broadcasts, used by LightFlow and a few others.

Re: Then the integration would be very simple for any app that wants to support it. I am confident that the Automagic developer would add it to his app, and probably the Tasker developer, too.

The developer of Tasker (Pent) specifically wrote to me that:

- He has no interest in redoing what he's done for K9 Mail -- for every mail app that happens to come along

- The "condition" plugin API is what he wants all apps to use, so that the work is done by the developers of those apps (AquaMail here) not him

It's my understanding that Automagic is a Tasker "clone".

And so to me, Tasker comes first, and "clones" next (for a while Automagic didn't support the Tasker "event" plugins at all).

On the other hand, if the developer of Automagic wants to integrate with AquaMail the same way as Tasker integrates with K9 Mail, sure, I don't mind and will provide the information.

---

With Tasker, it comes down to this:

Tasker "condition" plugins are not aware of any actual "conditions" set by the user.

So the model is:

A plugin sends an event to Tasker, "hey, something might have happened" and then Tasker calls the plugin for every condition set by the user, for the plugin to check if the "something" matches the actual condition.

Imagine 10 just received messages * 10 conditions, or 20 * 20, etc.
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

lueq

  • Newbie
  • *
  • Posts: 7
Re: Tasker Integration Issue
« Reply #6 on: February 28, 2016, 11:43:18 pm »
Thanks for the response!

I understand that the Tasker condition plugin is not suited for checking every email against every conI don't believe Automagic is a Tasker clone - but you put it into qudition.

Do you have a broadcast that is sent for each received email and contains some data about the email, such as sender, recipients, and subject?
If that's the case I'll ask the Automagic developer whether he'll get in touch with you to implement a K9-like integration.


Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12742
Re: Tasker Integration Issue
« Reply #7 on: February 29, 2016, 12:46:59 am »
Re: I understand that the Tasker condition plugin is not suited for checking every email against every con

But that's how Tasker "condition" plugins work.

Tasker is the only "thing" that "knows" about all actual conditions created by the user, so it asks the plugin "did this happen" for X conditions * Y potential matches.

Re: I don't believe Automagic is a Tasker clone - but you put it into qudition.

In terms of plugins, yes.

Re: Do you have a broadcast that is sent for each received email and contains some data

No, I don't. But there is a broadcast for new notifications.

I'm attaching a .txt file with the current API.

The basic idea is to trigger on broadcast "org.kman.AquaMail.NEW_NOTIFICATION" and then query "content://org.kman.AquaMail.datax.messages/account/<accountIdhere>/unread" ContentProvider.

If it all seems to work, I can add another broadcast which will be sent even if the user disabled notifications.

The content provider may return same messages multiple times over time, so code in Automagic should be ready for that (maybe keep track of "max seen message _id").
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

lueq

  • Newbie
  • *
  • Posts: 7
Re: Tasker Integration Issue
« Reply #8 on: February 29, 2016, 06:40:32 am »
Thanks for the additional details, especially the API. Very useful information!

In looking at the API, it should be possible to use the functions without any additional enhancements to Automagic itself.
Automagic supports general broadcast triggers for starting a flow, so it should be possible to get your notification and react to it. As an alternative it would also be possible to use the plugin as the trigger.
It also supports querying content providers, so it should be possible to retrieve the unread emails and process them in whichever way I want.

I'll see when I have some time to try it out.

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12742
Re: Tasker Integration Issue
« Reply #9 on: March 01, 2016, 06:02:04 pm »
Ah, interesting.

But please don't forget that the content provider is protected by a permission.

I'd like to know how it works out, please let me know.
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

lueq

  • Newbie
  • *
  • Posts: 7
Re: Tasker Integration Issue
« Reply #10 on: March 02, 2016, 02:11:08 am »
It works as expected.

As Automagic does not (yet) have the permissions for the AquaMail content providers I have to use the "Execute Root Command" action in Automagic to read the content provider ("content query --uri content://org.kman.AquaMail.datax.messages/account/1001/unread --projection _id:header_when:header_from:header_to:header_subject").
The query returns a list with all unread messages on the account.
I can trigger it through the new mail trigger from the AquaMail plugin.
This makes it possible to get all messages, not just the one that triggered the plugin.

Processing is a little complex as it requires to keep track of the latest email processed before (I guess based on _id or header_when) to only consider the newest mails, but it is doable.

If the Automagic developer includes the required permissions in his app, this should work without root by using the Query Content Provider action. I don't know the details of incorporating such permissions, so I don't know whether that's feasible  for him or not.

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12742
Re: Tasker Integration Issue
« Reply #11 on: March 02, 2016, 10:09:02 pm »
Re: Execute Root Command

Wow. Speechless. In a good way of course.

Re: the details of incorporating such permissions

They have to be added at compile time (in Automagic, I mean) -- but on the plus side, since those permissions are defined by AquaMail, they will only show if the user has Aqua installed (i.e. it won't confuse the others with "what the heck is this permission").
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

lueq

  • Newbie
  • *
  • Posts: 7
Re: Tasker Integration Issue
« Reply #12 on: March 04, 2016, 06:20:40 am »
I contacted the Automagic developer and he plans to add the permissions to the next early access build which should come out in a few weeks.  :)

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12742
Re: Tasker Integration Issue
« Reply #13 on: March 06, 2016, 02:45:08 pm »
Wow, excellent! Thank you!
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/

Kostya Vasilyev

  • Hero Member
  • *****
  • Posts: 12742
Re: Tasker Integration Issue
« Reply #14 on: July 01, 2016, 11:41:48 pm »
Version 1.6.2.6-pre7

+ Tasker: the plugin now returns data from all matching messages, as arrays (not just one).

http://www.aqua-mail.com/forum/index.php?topic=4820.0
Creating debug logs for diagnostics: https://www.aqua-mail.com/troubleshooting/

The official FAQ: https://www.aqua-mail.com/faq/

Лог-файлы для диагностики: https://www.aqua-mail.com/ru/troubleshooting/

Вопросы и ответы: https://www.aqua-mail.com/ru/faq/