def main(): username, config_file, entryid = sys.argv[1:] config = kopano.Config(filename=config_file) server = kopano.server(config=config) process(username, server, entryid)
def main(): username, config_file, entryid = sys.argv[1:] config = kopano.Config(filename=config_file) server = kopano.server(config=config) user = server.user(username) item = user.item(entryid) mr = item.meetingrequest if mr.is_request: server.log.debug("Accepting meeting request tentative from %s", get_sender(item)) mr.accept(tentative=True, response=False) elif mr.is_response: server.log.debug("Processing meeting request response from %s", get_sender(item)) mr.process_response() elif mr.is_cancellation: server.log.debug("Processing meeting request cancellation from %s", get_sender(item)) mr.process_cancellation() now = datetime.now() try: server.log.debug("Updating freebusy") user.freebusy.publish(now - timedelta(7), now + timedelta(180)) except kopano.errors.NotFoundError as e: server.log.error("Unable to publish freebusy information: %s", str(e))
def main(): args = sys.argv[1:] username, config_file = args[:2] entryid = args[2] if len(args) > 2 else None config = kopano.Config(filename=config_file) server = kopano.server(config=config) accept(username, server, entryid)
def main(): parser = kopano.parser( "CSKQ", usage="Usage: %prog [options] from to subject username msgfile") options, args = parser.parse_args() if len(args) != 5: print( "Invalid arguments, you have to supply the arguments: from, to, subject, username, and msgfile", file=sys.stderr) sys.exit(1) config_dict = kopano.CONFIG config_dict.update(CONFIG) config = kopano.Config(config_dict, options=options, service="autorespond") log = logger("autorespond", options=options, config=config) server = kopano.server(options=options, config=config) (from_, to, subject, username, msg_file) = args (to_me, bcc_me, cc_me) = ( os.getenv("MESSAGE_TO_ME"), os.getenv("MESSAGE_BCC_ME"), os.getenv("MESSAGE_CC_ME"), ) try: fh = open(msg_file, "rb") msg = fh.read() fh.close() except: log.info("Could not open msg file: %s", msg_file) sys.exit(1) if not (config["autorespond_norecip"] or (config["autorespond_bcc"] and bcc_me) or (config["autorespond_cc"] and cc_me) or to_me): log.debug("Response not send due to configuration") elif not (from_ and to and username and msg and msg_file): log.info( "One of the input arguments was empty (from: %s, to: %s, username: %s, msg: %s)", from_, to, username, msg) elif from_ == to: log.info("Loop detected, from == to (%s)", from_) elif in_blacklist(log, from_, to): log.info("From or to is in blacklist (from: %s, to: %s)", from_, to) elif check_time(config["senddb"], config["timelimit"], username, to): log.info( "Ignoring since we already sent OOO message within timelimit (username: %s, to: %s, timelimit: %d)", username, to, config["timelimit"]) else: add_time(config["senddb"], username, to) send_ooo(server, username, msg, config["copy_to_sentmail"]) log.info("Sent OOO to %s (username %s)", to, username)
def main(): args = sys.argv[1:] username, config_file = args[:2] config = kopano.Config(filename=config_file) server = kopano.server(config=config) user = server.user(username) autoaccept = user.autoaccept if len(args) > 2: items = [user.item(args[2])] else: items = [] for item in user.inbox: mr = item.meetingrequest if((mr.is_request and mr.response_requested and not mr.processed) or \ (mr.is_cancellation and not mr.processed)): items.append(item) for item in items: mr = item.meetingrequest if mr.is_request: decline_message = None if not autoaccept.recurring and item.recurring: decline_message = "Recurring meetings are not allowed" elif not autoaccept.conflicts: conflicts = conflict_occurrences(user, item) if conflicts: decline_message = conflict_message(conflicts) if decline_message: mr.decline(message=decline_message) else: mr.accept(add_bcc=True) elif mr.is_cancellation: mr.process_cancellation(delete=True) now = datetime.now() try: user.freebusy.publish(now - timedelta(7), now + timedelta(180)) except kopano.errors.NotFoundError as e: print("Unable to publish freebusy information: " + str(e), file=sys.stderr)
def main(): username, config_file, entryid = sys.argv[1:] config = kopano.Config(filename=config_file) server = kopano.server(config=config) user = server.user(username) item = user.item(entryid) mr = item.meetingrequest if mr.is_request: mr.accept(tentative=True, response=False) elif mr.is_response: mr.process_response() elif mr.is_cancellation: mr.process_cancellation() now = datetime.now() user.freebusy.publish(now - timedelta(7), now + timedelta(180))
def main(): parser = kopano.parser() # select common cmd-line options options, args = parser.parse_args() config = kopano.Config(None, service='search', options=options) server = kopano.Server(options, config) # get index_path, run_as_user, run_as_group from search.cfg search_config = server.config if not search_config: print('ERROR: search config is not available', file=sys.stderr) sys.exit(1) index_path = _default(search_config.get('index_path')) search_user = _default(search_config.get('run_as_user')) uid = pwd.getpwnam(search_user).pw_uid search_group = _default(search_config.get('run_as_group')) gid = grp.getgrnam(search_group).gr_gid if (uid, gid) != (os.getuid(), os.getgid()): print( 'ERROR: script should run under user/group as specified in search.cfg', file=sys.stderr) sys.exit(1) cleaned_args = [arg for arg in sys.argv[:1] if not arg.startswith('-')] # find database(s) corresponding to given store GUID(s) dbpaths = [] if len(cleaned_args) > 1: for arg in cleaned_args[1:]: dbpath = os.path.join(index_path, server.guid + '-' + arg) dbpaths.append(dbpath) else: # otherwise, select all databases for compaction dbpaths = [] for path in glob.glob(os.path.join(index_path, server.guid + '-*')): if not path.endswith('.lock'): dbpaths.append(path) # loop and compact count = len(dbpaths) errors = 0 for dbpath in dbpaths: try: if os.path.isdir(dbpath): if len(dbpath.split('-')) > 1: store = dbpath.split('-')[1] try: server.store(store) except kopano.NotFoundError as e: print('deleting:', dbpath) shutil.rmtree(dbpath) os.remove('%s.lock' % dbpath) continue print('compact:', dbpath) with open('%s.lock' % dbpath, 'w') as lockfile: # do not index at the same time fcntl.flock(lockfile.fileno(), fcntl.LOCK_EX) shutil.rmtree(dbpath + '.compact', ignore_errors=True) subprocess.call( ['xapian-compact', dbpath, dbpath + '.compact']) # quickly swap in compacted database shutil.move(dbpath, dbpath + '.old') shutil.move(dbpath + '.compact', dbpath) shutil.rmtree(dbpath + '.old') else: print('ERROR: no such database:', dbpath) errors += 1 print except Exception as e: print('ERROR', file=sys.stderr) traceback.print_exc(e) errors += 1 # summarize print('done compacting (%d processed, %d errors)' % (count, errors))