Create a rule for a user via command-line



  • Hello together,

    I am new here and I hope I create my Topic right…

    I install Zarafa 7.1.14.51822 and I will create a rule\s (forward to or forward as a attachment) for a User via command-line. I do not found some commands that I can create one.

    Is this possible or is this working only with a script?

    Thank you
    kruemel


  • Kopano

    I think there is no command line tool to create rules.
    This can certainly done with scripts, but I wouldn’t know any right now.

    But, why do you install ZCP 7.1? You should definitely go with KC 8.3 or later.

    Cheers,
    Sebastian


  • Kopano

    Hi Kruemel.

    There is a script that can create rules see kopano-rules.py in https://stash.kopano.io/projects/KSC/repos/core-tools/browse

    Cheers,
    Robin



  • Hi Robin,

    Thanks, I found this script and execute this. I got a error “Import zarafa. Importerror: No module named zarafa”.

    • If I coment out this import zarafa I got 3 errors -> main() , in main options args = opt_args and parser = zarafa.parser(‘skpc’) … NameError: global name ‘zarafa’ is not defined …

    How can I import the zarafa modul or is this a class?

    Thank you

    cheers
    kruemel


  • Kopano

    Hi Kruemel.

    I changed the script so it works with python-zarafa (no guarantees that everything works), but you need at least ZCP 7.2.0.
    ZCP 7.1.x doesn’t have python-zarafa and the the version that can be found on GitHub is not compatible anymore.

    ZCP is no longer supported/available so i would recommend to upgrade to Kopano anyway.
    https://kb.kopano.io/display/WIKI/Migration+Quick+Start-Guide±+ZCP+to+Kopano+Core

    Cheers,
    Robin



  • Hi Robin,

    thanks for your help. I will check that and I can make a update to 7.2 or kopano

    Thank you

    Cheers,
    kruemel



  • Hi Robin,

    I test it with 7.2 and it works (thanks), but i have one more question. If I create a rule I will forward all mails which this user get to an forwarded Mail address.

    I use the commandline

    For example:
    python kopano-rules.py --user user1 --create firstrule --conditions "received-from:user3@kopano.com" --actions "forward-to:user2@kopano.com"
    How is the command for --conditionis “received-from: ALL” … ?

    Thank you

    Cheers,
    kruemel


  • Kopano

    Hi Kruemel,

    You can use this if the mails is only sent to you

    python kopano-rules.py --user user1 --create firstrule --conditions "sent-only-to-me"  --actions "forward-to:user2@kopano.com"
    

    Or if your name is into ‘to’ or ‘cc’ field

    python kopano-rules.py --user user1 --create firstrule --conditions "name-in-to-cc"  --actions "forward-to:user2@kopano.com"
    

    You can see all the options in https://stash.kopano.io/projects/KSC/repos/core-tools/browse
    Please be aware that listing a rule with name-in-to-cc will shown correctly but it is working.

    Regards,

    Robin



  • Hi Robin,

    Thank you for your help.

    Cheers
    kruemel



  • Hello Forum,

     python kopano-rules.py --user username --create Forward-Mail --conditions "received-from:user.name@domain" --actions "forward-to:schaden@domain"
    

    gives me this:

    Traceback (most recent call last):
      File "kopano-rules.py", line 837, in <module>
        main()
      File "kopano-rules.py", line 831, in main
        rowlist = createrule(options, lastid)
      File "kopano-rules.py", line 604, in createrule
        username = searchusername(server, tmpname)
      File "kopano-rules.py", line 56, in searchusername
        if str(user.fullname) == name:
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 4: ordinal not in range(128)
    
    

    The first rule i created was successful:

    python kopano-rules.py --user user --create Send-To-Schaden --conditions "received-from:user.name@domain" --actions "forward-to:schaeden@domain"  
    

    But i forward to “schaeden@”, not to “schaden@”

    After that i did

    python kopano-rules.py --user username --list
    +--------+--------------------------------------------+-----------+--------------------------------------------+---------+
    | Number | Name                                       | Condition | Action                                     | State   |
    +--------+--------------------------------------------+-----------+--------------------------------------------+---------+
    | 1      | Kategorien der E-Mails l?schen (empfohlen) |           |                                            | Enabled |
    | 2      | Send-To-Schaden                            |           | Forward message to schaeden@domain         | Enabled |
    +--------+--------------------------------------------+-----------+--------------------------------------------+---------+
    
    
    python kopano-rules.py --user username --rule 2 --state delete
    

    tried again (with same rulename and after that with another name) but run into this error

    Coffee_is_life



  • I think i fixed it :)

    around line 55:

    def searchusername(server, name):
        for user in server.users():
    #        if str(user.fullname) == name:
            if (user.fullname).encode('utf-8') == name:
                return user
    

    just add the utf-8 encoding.

    Now i can create rules again, but it seems the arent working…

    +--------+--------------------------------------------+-----------+--------------------------------------------------+---------+
    | Number | Name                                       | Condition | Action                                           | State   |
    +--------+--------------------------------------------+-----------+--------------------------------------------------+---------+
    | 1      | Kategorien der E-Mails l?schen (empfohlen) |           |                                                  | Enabled |
    | 2      | ForwardSchaden                             |           | Forward message to another.user@DOMAIN.DE        | Enabled |
    +--------+--------------------------------------------+-----------+--------------------------------------------------+---------+
    

    But this other user cant receive this mail… the conditikon was:

    --conditions "received-from:this.user@DOMAIN.de"
    

    The whole line was:

    python kopano-rules.py --user thisuser --create ForwardSchaden --conditions "received-from:this.user@this-domain.de" --actions "forward-to:another.user@this-domain.de"
    

    this user is currenty in holyday, should i use another condition because maybe this rule whould do something if the user actually receive this mail?

    Coffee_is_life



  • OK, this rules wont wotrk but i dont know why…

    i got 3 Rules already:

    +--------+--------------------------------------------+-------------------------------+--------------------------------------------------+---------+
    | Number | Name                                       | Condition                     | Action                                           | State   |
    +--------+--------------------------------------------+-------------------------------+--------------------------------------------------+---------+
    | 1      | Kategorien der E-Mails l?schen (empfohlen) |                               |                                                  | Enabled |
    | 2      | ForwardSchaden                             |                               | Forward message to another.user@this-domain.de   | Enabled |
    | 3      | ForwardSchaden2                            | When my name is in the To box | Forward message to another.user@this-domain.de   | Enabled |
    |        |                                            |                               |                                                  |         |
    | 4      | ForwardSchaden3                            |                               | Forward message to another.user@this-domain.de   | Enabled |
    +--------+--------------------------------------------+-------------------------------+--------------------------------------------------+---------+
    

    First (index 2) is with condition: recieved-from:this.user@this-domain.de
    second one (index 3) is with name-in-to:this.user@this-domain.de
    the third one (index 4) is with sent-to:this.user@this-domain.de

    But in dagent.log:

    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] Delivered message to 'mailarchiv', Subject: "Test Weiterleitung die 3te", Message-Id: <kcim.5937a426.b11.391241d34aab31ff@mailserver.this-domain.de>, size 3607
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] Mail will be delivered in Inbox
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] * PreDelivery processing started
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] * PreDelivery processing done
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] * PreRuleProcess processing started
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] * PreRuleProcess processing done
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] Rule Kategorien der E-Mails l?schen (empfohlen) doesn't match: 0x8004010f
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] Rule ForwardSchaden doesn't match: 0x8004010f
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] Rule ForwardSchaden2 doesn't match: 0x8004010f
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] Rule ForwardSchaden3 doesn't match: 0x8004010f
    Wed Jun  7 08:58:47 2017: [info   ] [ 2837] Starting autoresponder for out-of-office message
    

    someone a hint?

    //EDIT:
    i’ve deleted the rules (they wont work anyways) and now i get this:

    Traceback (most recent call last):
      File "kopano-rules.py", line 838, in <module>
        main()
      File "kopano-rules.py", line 832, in main
        rowlist = createrule(options, lastid)
      File "kopano-rules.py", line 786, in createrule
        returncon = storeconditions[0]
    IndexError: list index out of range
    

    cant even create rules now…
    //EDIT2:

    if len(storeconditions) > 1:
            #returncon = SOrRestriction(storeconditions)
            returncon = SAndRestriction(storeconditions)
        else:
            print( len(storeconditions) )    -  line added
            print(", " .join(storeconditions))  -  line added
            returncon = storeconditions[0]
    

    The length returns 0
    the array itself doenst contain vars.

    Coffee_is_life


  • Kopano

    Hi Coffee_is_life,

    Can you try the new version.
    Removed the GAB check what was causing the unicode error, wasn’t needed anymore
    It will now also print the condition ‘received-from’.

    No idea what is causing the IndexError can you add ‘print storeconditions’ before line 786

    Regards,

    Robin



  • i already did:

    print(", " .join(storeconditions))  -  line added
    

    is prints nothing, not even a ", " - so i think its empty
    length returns 0

    the new version works without unicode-error - check
    but i recieve the IndexError aswell

    Coffe_is_life


  • Kopano

    Did you add an condition?
    without --conditions

    python kopano-rules.py --user user1 --create ForwardSchaden  --actions "forward-to:user3@mailtje.nu"
    Traceback (most recent call last):
      File "kopano-rules.py", line 839, in <module>
        main()
      File "kopano-rules.py", line 833, in main
        rowlist = createrule(options, lastid)
      File "kopano-rules.py", line 786, in createrule
        returncon = storeconditions[0]
    IndexError: list index out of range
    


  • @Coffee_is_life said in Create a rule for a user via command-line:

    python kopano-rules.py --user thisuser --create ForwardSchaden --conditions "received-from:this.user@this-domain.de" --actions "forward-to:another.user@this-domain.de"

    python kopano-rules.py --user thisuser --create ForwardSchaden --conditions "received-from:this.user@this-domain.de" --actions "forward-to:another.user@this-domain.de"
    

    same with sent-to, name-in-to, name-in-to-cc…

    //edit
    i tried with --conditions “name-in-t-cc” without an email…
    Should i use the mail, name or username for this “name in to or cc”?

    //edit2 : ups :) should use '–condition "received-from:this.user@this-domain.de" and it works :)

    had just the condition because i thought “name in to or cc” doesn’t need a name/user or mail behind it :)

    my bad

    ///EDIT3
    BUT:

    python kopano-rules.py --user my_username --create TEST --conditions "name-in-to-cc:my.user@this-domain.de;has-attachment" --exceptions "contain-word-sender-address:Ticketsystem" --actions "forward-to:another-user@this-domain.de"
    

    gives:

    Traceback (most recent call last):
      File "kopano-rules.py", line 839, in <module>
        main()
      File "kopano-rules.py", line 833, in main
        rowlist = createrule(options, lastid)
      File "kopano-rules.py", line 770, in createrule
        storeexceptions.append(SNotRestriction(exceptionslist[0]))
    IndexError: list index out of range
    
    

    Coffee_is_life


  • Kopano

    Your are right ‘name-in-to-cc’ shouldn’t have a name /mail behind it, will fix it.

    Will also check why exceptions is not working,

    Can’t promise to fix it this week.

    Robin



  • I’ve set the rule now via the users webapp - so dont rush it :)

    feel free to text me if you need a test-subject :)

    //EDIT: btw in https://stash.kopano.io/projects/KSC/repos/core-tools/browse the delete-items section has “localize-folders.py” instead of "delete-items.py"
    and the “create rule with multiple conditions”-example should switch with “create rule with one condition”-example :)

    Coffee_is_life


Log in to reply
 

Looks like your connection to Kopano Community Forum was lost, please wait while we try to reconnect.