def add_gmail_username_account(bot, update, user_data): db = DBC() email_server = db.search_email_server('GMAIL', 'IMAP') account = Account('GMAIL', None, None, email_server.host, email_server.port, email_server.protocol, None) account.username = update.message.text user_data['account'] = account update.message.reply_text('Type your password:') return PASSWORD
def add_refresh_time_account(bot, update, user_data): db = DBC() user = db.search_user(str(update.message.chat_id)) account = user_data['account'] if int(update.message.text) != 0: account.refresh_time = int(update.message.text) db.add_account_to_user(user, account) update.message.reply_text('Great! Your account has been saved.') return ConversationHandler.END
def init(config_path, token, db_path, refresh_chollos, log_level, log_path): set_config(Config()) if config_path: get_config().load_config_file(config_path) get_config().load_config_variables(token, db_path, refresh_chollos, log_level, log_path) # ================== Initializer ================== set_dbc(DBC(path=get_config().db_path)) init_scheduler() # ============== LOGs ============ log_formatter = logging.Formatter( fmt= '[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', datefmt='%d-%m-%y %H:%M:%S') logger = logging.getLogger() if get_config().log_path is not None: fileHandler = RotatingFileHandler(get_config().log_path, mode='a', maxBytes=5 * 1024 * 1024, backupCount=2, encoding='utf-8', delay=0) fileHandler.setFormatter(log_formatter) logger.addHandler(fileHandler) consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(log_formatter) logger.addHandler(consoleHandler) logger.setLevel(get_config().log_level) logging.getLogger('telegram').setLevel(logging.INFO) # ================== BOT ================== updater = Updater(get_config().telegram_token) load_dispatcher(updater.dispatcher) set_bot(updater.bot) # Start the Bot updater.start_polling(timeout=15, read_latency=6) logging.info("Bot started") schedule_chollos(get_config().default_refresh_chollos) # Run the bot until the user presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT updater.idle() logging.info("Bye !")
def remove_account_account(bot, update): db = DBC() user = db.search_user(str(update.message.chat_id)) account = db.get_account_of_user(user, update.message.text) db.remove_account_of_user(user, account) update.message.reply_text('Account removed successfully!') return ConversationHandler.END
def init(config_path, token, admin_user_id, admin_username, db_path, refresh_inbox, log_level, log_path): set_config(Config()) if config_path: get_config().load_config_file(config_path) get_config().load_config_variables(token, admin_user_id, admin_username, db_path, refresh_inbox, log_level, log_path) # ================== Initializer ================== set_dbc(DBC(path=get_config().db_path)) init_scheduler() # ============== LOGs ============ log_formatter = logging.Formatter( fmt= '[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', datefmt='%d-%m-%y %H:%M:%S') logger = logging.getLogger() if get_config().log_path is not None: fileHandler = logging.FileHandler(get_config().log_path) fileHandler.setFormatter(log_formatter) logger.addHandler(fileHandler) consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(log_formatter) logger.addHandler(consoleHandler) logger.setLevel(get_config().log_level) logging.getLogger('telegram').setLevel(logging.INFO) # ================== BOT ================== updater = Updater(get_config().telegram_token) load_dispatcher(updater.dispatcher) set_bot(updater.bot) # Start the Bot updater.start_polling(timeout=15, read_latency=6) logging.error("Bot started") init_email_service() # Run the bot until the user presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT updater.idle() logging.error("Bye !")
def modify_refresh_time_refresh_time(bot, update, user_data): db = DBC() user = db.search_user(str(update.message.chat_id)) account = db.get_account_of_user(user, user_data['username']) account.refresh_time = int(update.message.text) db.update_account_of_user(user, account) update.message.reply_text('Refresh Time modified successfully!') return ConversationHandler.END
def modify_password_password(bot, update, user_data): db = DBC() user = db.search_user(str(update.message.chat_id)) account = db.get_account_of_user(user, user_data['username']) account.password = update.message.text db.update_account_of_user(user, account) update.message.reply_text('Password modified successfully!') return ConversationHandler.END
def add_gmail_account(bot, update): query = update.callback_query db = DBC() try: db.search_user(str(query.message.chat_id)) except: db.insert_user(str(query.message.chat_id), []) query.message.reply_text('Type your email address:') logging.debug(query.message.chat_id) return ACCOUNT
# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Notmail Bot is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Notmail Bot. If not, see <http:#www.gnu.org/licenses/>. import os from repository.repository import DBC from repository.account import Account, parse_accounts_to_json # Test DATABASE utils db = DBC(os.path.join('..', 'config', 'tmail-bot.json')) # Test User account1 = Account('Gmail', '*****@*****.**', 'mypass', 'test.com', 465, 'IMAP', 15) account2 = Account('Outlook', '*****@*****.**', 'mypass', 'test.com', 465, 'IMAP', 25) accounts = [account1, account2] db.insert_user('123456789', accounts) User = db.search_user('123456789') print('\n[' + User.id + ']\nAccounts: ' + str(parse_accounts_to_json(User.accounts))) db.remove_user('123456789')
# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Notmail Bot is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Notmail Bot. If not, see <http:#www.gnu.org/licenses/>. import os from repository.repository import DBC from repository.account import Account, parse_accounts_to_json db = DBC(os.path.join('..', 'config', 'tmail-bot.json')) # Test Accounts account1 = Account('Gmail', '*****@*****.**', 'mypass', 'test.com', 465, 'IMAP', 15) account2 = Account('Outlook', '*****@*****.**', 'mypass', 'test.com', 465, 'IMAP', 25) accounts = [account1, account2] db.insert_user('123456789', accounts) User = db.search_user('123456789') account3 = Account('Gmail', '*****@*****.**', 'mypass', 'test.com', 465, 'IMAP', 15) account4 = Account('Outlook', '*****@*****.**', 'mypass', 'test.com', 465, 'IMAP', 25) accounts = [account3]
# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Notmail Bot is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Notmail Bot. If not, see <http:#www.gnu.org/licenses/>. import os from repository.repository import DBC #Test DATABASE utils db = DBC(os.path.join('..', 'config', 'tmail-bot.json')) #Test EmailServer db.insert_email_server('Gmail', 'smtp.gmail.com', 465, 'SMTP') EmailServer = db.search_email_server('Gmail', 'IMAP') print('\n[' + EmailServer.name + ']\nHost: ' + EmailServer.host + '\nPort: ' + str(EmailServer.port) + '\nProtocol: ' + EmailServer.protocol) EmailServer.port = 468 db.update_email_server(EmailServer) EmailServer = db.search_email_server('Gmail', 'IMAP') print('\n[' + EmailServer.name + ']\nHost: ' + EmailServer.host + '\nPort: ' + str(EmailServer.port) + '\nProtocol: ' + EmailServer.protocol) db.remove_email_server('Gmail', 'IMAP')
def populateDatabase(): # Insert Default Servers db = DBC(os.path.join('..', 'config', 'tmail-bot.json')) db.purge() db.insert_email_server('GMAIL', 'imap.gmail.com', '993', 'IMAP') db.insert_email_server('GMAIL', 'smtp.gmail.com', '465', 'SMTP') db.insert_email_server('OUTLOOK', 'pop3.live.com', '995', 'POP3') db.insert_email_server('OUTLOOK', 'smtp.live.com', '587', 'SMTP') #Insert Test Config config = ConfigParser() config.read(os.path.join('..', 'config', 'myconfig.ini')) db.insert_email_server('Test', config['email test']['SMTP_SERVER'], config['email test']['SMTP_SERVER_PORT'], 'SMTP') account = Account('Test', config['email test']['FROM_EMAIL'], config['email test']['FROM_PWD'], config['email test']['SMTP_SERVER'], config['email test']['SMTP_SERVER_PORT'], 'IMAP', 180) db.insert_user(config['Telegram']['ADMIN_ID'], [account])