simple addon development

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

simple addon development

Igal-2
hi,

I'm trying to create a simple Thunderbird addon:

onLoad:  check if there is a filter named "addon-filter-blacklist", and if not -- create a filter that deletes messages that match a sender email address.

then, whenever a message is selected, the user is provided with two options:

  1) add sender's email to blacklist
  2) add sender's domain to blacklist

once the user selects one of those options, the sender's email (or domain) is added to the "addon-filter-blacklist" rules with an OR operator.

after many hours I've managed to gain access to:  the sender's email address, the filter list, and the filter's searchTerms.

I'm trying to iterate over the filter's searchTerms but it doesn't work for me (see code below).

any ideas will be appreciated.


for ( var i=0; i < filter.searchTerms.Count(); i++ ) {

    Debug.dump( filter.searchTerms.GetElementAt( i ) );
}
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|

Re: simple addon development

R Kent James
On 9/15/2012 12:12 AM, Igal wrote:

> hi,
>
> I'm trying to create a simple Thunderbird addon:
>
> onLoad:  check if there is a filter named "addon-filter-blacklist", and if not -- create a filter that deletes messages that match a sender email address.
>
> then, whenever a message is selected, the user is provided with two options:
>
>    1) add sender's email to blacklist
>    2) add sender's domain to blacklist
>
> once the user selects one of those options, the sender's email (or domain) is added to the "addon-filter-blacklist" rules with an OR operator.
>
> after many hours I've managed to gain access to:  the sender's email address, the filter list, and the filter's searchTerms.
>
> I'm trying to iterate over the filter's searchTerms but it doesn't work for me (see code below).
>
> any ideas will be appreciated.
>
>
> for ( var i=0; i < filter.searchTerms.Count(); i++ ) {
>
>      Debug.dump( filter.searchTerms.GetElementAt( i ) );
> }
>

You didn't really define what you mean by "doesn't work". However, it
would be much more common with an nsISupportsArray like searchTerms to
use QueryElementAt:

filter.searchTerms.QueryElementAt(i,
Components.interfaces.nsIMsgSearchTerm);

Also, I don't use Debug.dump but simply dump myself.

:rkent

_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|

Re: simple addon development

Igal-2
hi Kent,

thanks for your reply.

  filter.searchTerms.QueryElementAt(i, Components.interfaces.nsIMsgSearchTerm);

works!  but how did you know that the function needs the 2nd argument and its type?  is there reference/documentation for that anywhere?

as for your other comments -- when I wrote doesn't work I meant that it doesn't give me any information.  the only thing I could get out of it was that the object has a method called QueryInterface().

also, Debug.dump() is a function that I wrote that iterates over all the keys in the object and outputs their values.  for some reason dump() doesn't do anything when I call it (I expect it to write to the Error Console?).

thanks again,


Igal


On Sunday, September 16, 2012 4:09:34 PM UTC-7, Kent James wrote:

> On 9/15/2012 12:12 AM, Igal wrote:
>
> > hi,
>
> >
>
> > I'm trying to create a simple Thunderbird addon:
>
> >
>
> > onLoad:  check if there is a filter named "addon-filter-blacklist", and if not -- create a filter that deletes messages that match a sender email address.
>
> >
>
> > then, whenever a message is selected, the user is provided with two options:
>
> >
>
> >    1) add sender's email to blacklist
>
> >    2) add sender's domain to blacklist
>
> >
>
> > once the user selects one of those options, the sender's email (or domain) is added to the "addon-filter-blacklist" rules with an OR operator.
>
> >
>
> > after many hours I've managed to gain access to:  the sender's email address, the filter list, and the filter's searchTerms.
>
> >
>
> > I'm trying to iterate over the filter's searchTerms but it doesn't work for me (see code below).
>
> >
>
> > any ideas will be appreciated.
>
> >
>
> >
>
> > for ( var i=0; i < filter.searchTerms.Count(); i++ ) {
>
> >
>
> >      Debug.dump( filter.searchTerms.GetElementAt( i ) );
>
> > }
>
> >
>
>
>
> You didn't really define what you mean by "doesn't work". However, it
>
> would be much more common with an nsISupportsArray like searchTerms to
>
> use QueryElementAt:
>
>
>
> filter.searchTerms.QueryElementAt(i,
>
> Components.interfaces.nsIMsgSearchTerm);
>
>
>
> Also, I don't use Debug.dump but simply dump myself.
>
>
>
> :rkent
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|

Re: simple addon development

Igal-2
I'm trying to create an nsIMsgSearchTerm and add it to a filter, so I'm trying to use the Filter's AddTerm() method, so I'm trying:


    var aAttrib = Ci.nsMsgSearchAttrib.Sender;
    var aOp = nsMsgSearchOp.Contains;
    var aValue = "[hidden email]";

    var x = filter.AddTerm( aAttrib, aOp, aValue, false, "xyz" );

but apparently aValue should be of type nsIMsgSearchValue which I don't know how to create.

any ideas?


thanks

from https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIMsgFilter

void nsIMsgFilter::AddTerm
(
    in nsMsgSearchAttribValue   attrib,
    in nsMsgSearchOpValue       op,
    in nsIMsgSearchValue        value,
    in boolean                  BooleanAND,
    in ACString                 arbitraryHeader
)




https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIMsgSearchValue


On Tuesday, September 18, 2012 1:23:22 AM UTC-7, Igal wrote:

> hi Kent,
>
>
>
> thanks for your reply.
>
>
>
>   filter.searchTerms.QueryElementAt(i, Components.interfaces.nsIMsgSearchTerm);
>
>
>
> works!  but how did you know that the function needs the 2nd argument and its type?  is there reference/documentation for that anywhere?
>
>
>
> as for your other comments -- when I wrote doesn't work I meant that it doesn't give me any information.  the only thing I could get out of it was that the object has a method called QueryInterface().
>
>
>
> also, Debug.dump() is a function that I wrote that iterates over all the keys in the object and outputs their values.  for some reason dump() doesn't do anything when I call it (I expect it to write to the Error Console?).
>
>
>
> thanks again,
>
>
>
>
>
> Igal
>
>
>
>
>
> On Sunday, September 16, 2012 4:09:34 PM UTC-7, Kent James wrote:
>
> > On 9/15/2012 12:12 AM, Igal wrote:
>
> >
>
> > > hi,
>
> >
>
> > >
>
> >
>
> > > I'm trying to create a simple Thunderbird addon:
>
> >
>
> > >
>
> >
>
> > > onLoad:  check if there is a filter named "addon-filter-blacklist", and if not -- create a filter that deletes messages that match a sender email address.
>
> >
>
> > >
>
> >
>
> > > then, whenever a message is selected, the user is provided with two options:
>
> >
>
> > >
>
> >
>
> > >    1) add sender's email to blacklist
>
> >
>
> > >    2) add sender's domain to blacklist
>
> >
>
> > >
>
> >
>
> > > once the user selects one of those options, the sender's email (or domain) is added to the "addon-filter-blacklist" rules with an OR operator.
>
> >
>
> > >
>
> >
>
> > > after many hours I've managed to gain access to:  the sender's email address, the filter list, and the filter's searchTerms.
>
> >
>
> > >
>
> >
>
> > > I'm trying to iterate over the filter's searchTerms but it doesn't work for me (see code below).
>
> >
>
> > >
>
> >
>
> > > any ideas will be appreciated.
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > for ( var i=0; i < filter.searchTerms.Count(); i++ ) {
>
> >
>
> > >
>
> >
>
> > >      Debug.dump( filter.searchTerms.GetElementAt( i ) );
>
> >
>
> > > }
>
> >
>
> > >
>
> >
>
> >
>
> >
>
> > You didn't really define what you mean by "doesn't work". However, it
>
> >
>
> > would be much more common with an nsISupportsArray like searchTerms to
>
> >
>
> > use QueryElementAt:
>
> >
>
> >
>
> >
>
> > filter.searchTerms.QueryElementAt(i,
>
> >
>
> > Components.interfaces.nsIMsgSearchTerm);
>
> >
>
> >
>
> >
>
> > Also, I don't use Debug.dump but simply dump myself.
>
> >
>
> >
>
> >
>
> > :rkent
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|

Re: simple addon development

Andrew Sutherland-3
On 09/18/2012 04:51 PM, Igal wrote:
> I'm trying to create an nsIMsgSearchTerm and add it to a filter, so I'm trying to use the Filter's AddTerm() method, so I'm trying:

You want to use createTerm (which should be present on the
nsIMsgSearchSession or similar instance).  Examples can be found here
that might be helpful.  Note the odd idiom we use where we copy the
value reference out then re-assign it.  I forget the details, but I
believe it to be important.

http://mxr.mozilla.org/comm-central/source/mail/base/modules/quickFilterManager.js#545

Andrew
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|

Re: simple addon development

GS__
In reply to this post by Igal-2
Hi,

if some is still interested, here is an approach:

// get current message
var msg = gFolderDisplay.selectedMessage;
var author = msg.author;
var email = author.substring(author.indexOf("@")+1, author.lastIndexOf(">"));
var buttonFilter = msg.folder.server.getFilterList(msgWindow).getFilterNamed("addon-filter-blacklist");
if(buttonFilter == null)
        return alert('no filter "addon-filter-blacklist"');
// new filter term and init
var newTerm = buttonFilter.createTerm();
newTerm.attrib = Components.interfaces.nsMsgSearchAttrib.Sender;
var value = newTerm.value; // needs to be init in own value (otherwise readonly)
value.attrib = newTerm.attrib;
value.str = email;
newTerm.value = value;
newTerm.op = Components.interfaces.nsMsgSearchOp.EndsWith;
newTerm.booleanAnd = false;
// add filter term
buttonFilter.appendTerm(newTerm);

GS__
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird