Navigation

    Kopano
    • Register
    • Login
    • Search
    • Categories
    • Get Official Kopano Support
    • Recent
    Statement regarding the closure of the Kopano community forum and the end of the community edition

    BUG?: kopano-python: restrictions in folders not working

    Kopano Groupware Core
    2
    3
    176
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • marlemion
      marlemion last edited by

      Very simple example:

      #!/usr/bin/env python2
      # -*- coding: utf-8 -*-
      
      import kopano
      import MAPI
      
      # Kopano Server, User and Password
      kopano_server = 'http://xxxxx.net:236/kopano'
      kopano_user = 'xxx'
      kopano_password = 'xxx'
      
      # Connect to kopano
      server = kopano.Server(server_socket=kopano_server, auth_user=kopano_user, auth_pass=kopano_password)
      store = server.user(kopano_user).store
      folder = store.folder('Sent Items')
      
      restriction = MAPI.Struct.SContentRestriction(MAPI.FL_SUBSTRING, MAPI.Tags.PR_SUBJECT_W, MAPI.Struct.SPropValue(MAPI.Tags.PR_SUBJECT_W, str('Your Ref')))
      
      mails = folder.items(restriction)
      
      for mail in mails:
          print(mail.subject)
      

      fails with

      Traceback (most recent call last):
        File "./example.py", line 20, in <module>
          for mail in mails:
        File "/usr/lib/python2.7/site-packages/kopano/folder.py", line 364, in items
          restriction=restriction,
        File "/usr/lib/python2.7/site-packages/kopano/table.py", line 46, in __init__
          self.mapitable.Restrict(restriction.mapiobj, TBL_BATCH)
      AttributeError: SContentRestriction instance has no attribute 'mapiobj'
      

      This seems to be a bug. Can anybody comment on this? It is a major limitation to the advanced use of the python module. Whether python 2 or 3 does not matter, I have tried both. Current stable version (8.7.17).

      longsleep 1 Reply Last reply Reply Quote 0
      • longsleep
        longsleep Kopano @marlemion last edited by

        @marlemion

        I think you mix the low level MAPI object (SContentRestriction) with high level folder API. There is a kopano.Restriction class.

        So try something like

        mails = folder.items(kopano.Restriction(restriction))
        
        marlemion 1 Reply Last reply Reply Quote 0
        • marlemion
          marlemion @longsleep last edited by marlemion

          @longsleep

          Thanks, that did it!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post