mirror of
https://github.com/powerline/powerline.git
synced 2025-04-08 19:25:04 +02:00
Feature: add username_variable, password_variable, server_variable, port_variable to options to mail segment (#2225)
* add username_variable and password_variable to options to mail segment * add server variable * make username/password optional for mail, and fix getting env var typo * add port variable for email * fix sleepy port_variable typo
This commit is contained in:
parent
50d73bfbc8
commit
833f30e88e
@ -1,6 +1,8 @@
|
||||
# vim:fileencoding=utf-8:noet
|
||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||
|
||||
import os
|
||||
|
||||
import re
|
||||
|
||||
from imaplib import IMAP4_SSL_PORT, IMAP4_SSL, IMAP4
|
||||
@ -17,9 +19,19 @@ class EmailIMAPSegment(KwThreadedSegment):
|
||||
interval = 60
|
||||
|
||||
@staticmethod
|
||||
def key(username, password, server='imap.gmail.com', port=IMAP4_SSL_PORT, folder='INBOX', use_ssl=None, **kwargs):
|
||||
def key(username='', password='', server='imap.gmail.com', port=IMAP4_SSL_PORT, username_variable='', password_variable='', server_variable='', port_variable='', folder='INBOX', use_ssl=None, **kwargs):
|
||||
if use_ssl is None:
|
||||
use_ssl = (port == IMAP4_SSL_PORT)
|
||||
# catch if user set custom mail credential env variables
|
||||
if username_variable:
|
||||
username = os.environ[username_variable]
|
||||
if password_variable:
|
||||
password = os.environ[password_variable]
|
||||
if server_variable:
|
||||
server = os.environ[server_variable]
|
||||
if port_variable:
|
||||
port = os.environ[port_variable]
|
||||
|
||||
return _IMAPKey(username, password, server, port, folder, use_ssl)
|
||||
|
||||
def compute_state(self, key):
|
||||
@ -64,6 +76,14 @@ email_imap_alert = with_docstring(EmailIMAPSegment(),
|
||||
e-mail server
|
||||
:param int port:
|
||||
e-mail server port
|
||||
:param str username_variable:
|
||||
name of environment variable to check for login username
|
||||
:param str password_variable:
|
||||
name of environment variable to check for login password
|
||||
:param str server_variable:
|
||||
name of environment variable to check for email server
|
||||
:param str port_variable:
|
||||
name of environment variable to check for email server port
|
||||
:param str folder:
|
||||
folder to check for e-mails
|
||||
:param int max_msgs:
|
||||
|
Loading…
x
Reference in New Issue
Block a user