kopano-cleanup.py script help



  • Hi guys

    I need some help and/or additional infos on the kopano-cleanup.py python script. Is it possible to run the script for all user in the database? I want to clean up periodically the users deleted items folder (after 30 days) and the junk folder after 60 days, but found no help on using the script with wildcards (aka --user=*).

    Has anyone some infos? The knowledge base has very short and poor description, and google says nothing.

    Thomas


  • Kopano

    Hello @teka74 ,

    I guess you are referring to https://kb.kopano.io/display/WIKI/Kopano+cleanup ?

    In the way the script is now you would need to get a user list before and call it per user (there is no “all” switch for the username). Listing users is quite simple, you can find an example at https://stash.kopano.io/projects/KSC/repos/lab-scripts/browse/python-kopano/list-users.py. You can find an example script which has the possibility to run for all users on a system at https://stash.kopano.io/projects/KSC/repos/webapp-tools/browse/set_webapp_default_signature.py

    What more description would you be looking for, for said Knowledgebase article?



  • @fbartels said in kopano-cleanup.py script help:

    Hello @teka74 ,

    I guess you are referring to https://kb.kopano.io/display/WIKI/Kopano+cleanup ?

    In the way the script is now you would need to get a user list before and call it per user (there is no “all” switch for the username). Listing users is quite simple, you can find an example at https://stash.kopano.io/projects/KSC/repos/lab-scripts/browse/python-kopano/list-users.py. You can find an example script which has the possibility to run for all users on a system at https://stash.kopano.io/projects/KSC/repos/webapp-tools/browse/set_webapp_default_signature.py

    What more description would you be looking for, for said Knowledgebase article?

    Yes, it is this script, I will look at the other scripts, and try to get working cleanup script. I will post here in a few days.

    Thanks, and a nice weekend

    Thomas



  • Hello Kopanos!

    I got the cleanup script working, and it worked for several months. After upgrading kopano core to newest version, the cleanup script gives some errors. How do i fix it ?

    I call the script daily via crontab, and error occurs only at first user in list:

    (mail adress made anonymous)

    Running script for 'txxxx@wahlshausen.de'
    Traceback (most recent call last):
      File "/usr/share/kopano/kopano-cleanup.py", line 98, in <module>
        main()
      File "/usr/share/kopano/kopano-cleanup.py", line 82, in main
        count = deleteitems(options, folder, daysbeforedeleted, pbar)
      File "/usr/share/kopano/kopano-cleanup.py", line 51, in deleteitems
        if not item.prop(PR_LAST_MODIFICATION_TIME).value and options.force:
      File "/usr/lib/python2.7/dist-packages/kopano/properties.py", line 39, in prop
        return _prop.prop(self, self.mapiobj, proptag, create=create,
      File "/usr/lib/python2.7/dist-packages/kopano/item.py", line 201, in mapiobj
        self.mapiobj = _utils.openentry_raw(self.store.mapiobj, self._entryid, self._content_flag)
      File "/usr/lib/python2.7/dist-packages/kopano/utils.py", line 74, in openentry_raw
        return _openentry_helper(mapistore, entryid, flags | MAPI_MODIFY)
      File "/usr/lib/python2.7/dist-packages/kopano/utils.py", line 68, in _openentry_helper
        return mapistore.OpenEntry(entryid, IID_IECMessageRaw, flags)
      File "/usr/lib/python2.7/dist-packages/MAPICore.py", line 965, in OpenEntry
        return _MAPICore.IMsgStore_OpenEntry(self, cbEntryID, lpInterface, ulFlags)
    TypeError: in method 'IMsgStore_OpenEntry', argument 2 of type 'ULONG'
    Running script for 'axxxx@wahlshausen.de'
    Deleted 0 item(s) for user 'axxxx@wahlshausen.de' in folder 'Gelöschte Objekte'
    Deleted 0 item(s) for user 'axxxx@wahlshausen.de' in folder 'Junk E-Mail'
    Running script for 'exxxx@wahlshausen.de'
    Deleted 15 item(s) for user 'exxxx@wahlshausen.de' in folder 'Gelöschte Objekte'
    Deleted 3 item(s) for user 'exxxx@wahlshausen.de' in folder 'Junk E-Mail'
    

  • Kopano

    Hi @teka74 ,

    some more information would be helpful.

    • which (exact) version of kopano core are you running now?
    • which (exact) version of kopano core were you running before?
    • which script are you running? if you made modifications to it then having the exact script to reproduce the error would be helpful.


  • I’ve upgraded from an early 8.4.20 to the new 8.4.90

    And the script i’ve been running every night is from here:

    https://stash.kopano.io/projects/KSC/repos/core-tools/browse/kopano-cleanup.py



  • I thinki it’s solved !

    I found this in another thread:

    https://forum.kopano.io/topic/891/solved-message-cannot-be-opened-problem-with-core-8-4-90-1296_0-157-ubuntu_16-04-amd64/7

    followed the instructions, and now the cleanup-script is running as usual without errors

    Thomas



  • The script is working fine for me. But how can i enhance it, that i can delete “Posteingang” and “Gesendete Objekte” too?

    I have some mailboxes with newsletters and very old stuff - so it will be much helpfull for me

    Michael



  • I have made following additions in thescript:

    parser.add_option("–inbox", dest=“inbox”, action=“store_true”, help=“Run cleanup script for the inbox folder”)
    parser.add_option("–sent", dest=“sent”, action=“store_true”, help=“Run cleanup script for the sent folder”)

    and

    if options.inbox:
        folder = user.store.inbox
        if options.progressbar:
            pbar = progressbar(folder, daysbeforedeleted)
        count = deleteitems(options, folder, daysbeforedeleted, pbar)
        if options.progressbar:
            pbar.finish()
        print 'Deleted %s item(s) for user \'%s\' in folder \'%s\'' % (count, user.name, folder.name)
    
    if options.sent:
        folder = user.store.sentmail
        if options.progressbar:
            pbar = progressbar(folder, daysbeforedeleted)
        count = deleteitems(options, folder, daysbeforedeleted, pbar)
        if options.progressbar:
            pbar.finish()
        print 'Deleted %s item(s) for user \'%s\' in folder \'%s\'' % (count, user.name, folder.name)
    

    Now I have the option switches --inbox and --sent for cleanup this folders too



  • Is it possible to distinguish read / unread emails in the inbox deletion process?



  • @teka74
    Hello Thomas,

    would you please publish how you had changed the kopano-cleanup.py to work for all users?

    I found the other script which print all users of my kopano but i don‘t know to combine both because i don’t know anything about python.

    Regards
    Heiko