示例#1
0
 def _load_public_config(self):
     self.pub_config = ConfigManager(rules=CONFIG_RULES)
     try:
         self.pub_config.load(None, public_only=True)
         self.secret = GetUserSecret(self.pub_config)
         self.base_url = 'http://%s:%s%s/' % (self.pub_config.sys.http_host,
                                              self.pub_config.sys.http_port,
                                              self.pub_config.sys.http_path)
     except:
         self.pub_config = None
示例#2
0
文件: app.py 项目: utkarshx/Mailpile
def Main(args):
    DisableUnbrokeredConnections()

    # Bootstrap translations until we've loaded everything else
    mailpile.i18n.ActivateTranslation(None, ConfigManager, None)
    try:
        # Create our global config manager and the default (CLI) session
        config = ConfigManager(rules=mailpile.config.defaults.CONFIG_RULES)
        session = Session(config)
        cli_ui = session.ui = UserInteraction(config)
        session.main = True
        try:
            CatchUnixSignals(session)
            config.clean_tempfile_dir()
            config.load(session)
        except IOError:
            if config.sys.debug:
                session.ui.error(
                    _('Failed to decrypt configuration, '
                      'please log in!'))
        HealthCheck(session, None, []).run()
        config.prepare_workers(session)
    except AccessError, e:
        session.ui.error('Access denied: %s\n' % e)
        sys.exit(1)
示例#3
0
文件: app.py 项目: smari/Mailpile
def Main(args):
    mailpile.platforms.DetectBinaries()
    DisableUnbrokeredConnections()

    # Bootstrap translations until we've loaded everything else
    mailpile.i18n.ActivateTranslation(None, ConfigManager, None)
    try:
        # Create our global config manager and the default (CLI) session
        config = ConfigManager(rules=mailpile.config.defaults.CONFIG_RULES)
        session = Session(config)
        cli_ui = session.ui = UserInteraction(config)
        session.main = True
        try:
            CatchUnixSignals(session)
            config.clean_tempfile_dir()
            config.load(session)
        except IOError:
            if config.sys.debug:
                session.ui.error(_('Failed to decrypt configuration, '
                                   'please log in!'))
        HealthCheck(session, None, []).run()
        config.prepare_workers(session)
    except AccessError, e:
        session.ui.error('Access denied: %s\n' % e)
        sys.exit(1)
示例#4
0
class MailpileState(object):
    def __init__(self):
        self.base_url = 'http://localhost:33411/'
        self.pub_config = None
        self.is_running = None
        self.secret = ''

    def check_if_running(self):
        # FIXME: This is rather slow. We should refactor upstream to speed
        #        up or include our own custom parser if that is infeasible.
        wd_lock_path = ConfigManager.LOCK_PATHS()[1]
        wd_lock = fasteners.InterProcessLock(wd_lock_path)
        try:
            if wd_lock.acquire(blocking=False):
                wd_lock.release()
                return False
            else:
                return True
        except (OSError, IOError):
            return False

    def _load_public_config(self):
        self.pub_config = ConfigManager(rules=CONFIG_RULES)
        try:
            self.pub_config.load(None, public_only=True)
            self.secret = GetUserSecret(self.pub_config)
            self.base_url = 'http://%s:%s%s/' % (self.pub_config.sys.http_host,
                                                 self.pub_config.sys.http_port,
                                                 self.pub_config.sys.http_path)
        except:
            import traceback
            traceback.print_exc()
            self.pub_config = None

    def discover(self, argv):
        self._load_public_config()
        self.is_running = self.check_if_running()
        self.http_port = self.pub_config.sys.http_port

        # Check if we have a screen session?

        return self
示例#5
0
 def _load_public_config(self):
     self.pub_config = ConfigManager(rules=CONFIG_RULES)
     try:
         self.pub_config.load(None, public_only=True)
         self.secret = GetUserSecret(self.pub_config)
         self.base_url = 'http://%s:%s%s/' % (
             self.pub_config.sys.http_host,
             self.pub_config.sys.http_port,
             self.pub_config.sys.http_path)
     except:
         self.pub_config = None
示例#6
0
class MailpileState(object):
    def __init__(self):
        self.base_url = 'http://localhost:33411/'
        self.pub_config = None
        self.is_running = None
        self.secret = ''

    def check_if_running(self):
        # FIXME: This is rather slow. We should refactor upstream to speed
        #        up or include our own custom parser if that is infeasible.
        wd_lock_path = ConfigManager.LOCK_PATHS()[1]
        wd_lock = fasteners.InterProcessLock(wd_lock_path)
        try:
            if wd_lock.acquire(blocking=False):
                wd_lock.release()
                return False
            else:
                return True
        except (OSError, IOError):
            return False

    def _load_public_config(self):
        self.pub_config = ConfigManager(rules=CONFIG_RULES)
        try:
            self.pub_config.load(None, public_only=True)
            self.secret = GetUserSecret(self.pub_config)
            self.base_url = 'http://%s:%s%s/' % (
                self.pub_config.sys.http_host,
                self.pub_config.sys.http_port,
                self.pub_config.sys.http_path)
        except:
            self.pub_config = None

    def discover(self, argv):
        self._load_public_config()
        self.is_running = self.check_if_running()
        self.http_port = self.pub_config.sys.http_port

        # Check if we have a screen session?

        return self
示例#7
0
 def check_if_running(self):
     # FIXME: This is rather slow. We should refactor upstream to speed
     #        up or include our own custom parser if that is infeasible.
     wd_lock_path = ConfigManager.LOCK_PATHS()[1]
     wd_lock = fasteners.InterProcessLock(wd_lock_path)
     try:
         if wd_lock.acquire(blocking=False):
             wd_lock.release()
             return False
         else:
             return True
     except (OSError, IOError):
         return False
示例#8
0
文件: app.py 项目: fil82/Mailpile
def Main(args):
    try:
        mailpile.platforms.DetectBinaries(_raise=OSError)
    except OSError as e:
        binary = str(e).split()[0]
        sys.stderr.write("""
Required binary missing or unusable: %s

If you know where it is, or would like to skip this test and run Mailpile
anyway, you can set one of the following environment variables:

    MAILPILE_%s="/path/to/binary"
or
    MAILPILE_SKIP_BINARIES="%s"

Note that skipping a binary check may cause the app to become unstable or
fail in unexpected ways. If it breaks you get to keep both pieces!

""" % (e, binary.upper(), binary))
        sys.exit(1)

    # Enable our connection broker, try to prevent badly behaved plugins from
    # bypassing it.
    DisableUnbrokeredConnections()

    # Bootstrap translations until we've loaded everything else
    mailpile.i18n.ActivateTranslation(None, ConfigManager, None)
    try:
        # Create our global config manager and the default (CLI) session
        config = ConfigManager(rules=mailpile.config.defaults.CONFIG_RULES)
        session = Session(config)
        cli_ui = session.ui = UserInteraction(config)
        session.main = True
        try:
            CatchUnixSignals(session)
            config.clean_tempfile_dir()
            config.load(session)
        except IOError:
            if config.sys.debug:
                session.ui.error(
                    _('Failed to decrypt configuration, '
                      'please log in!'))
        HealthCheck(session, None, []).run()
        config.prepare_workers(session)
    except AccessError, e:
        session.ui.error('Access denied: %s\n' % e)
        sys.exit(1)
示例#9
0
文件: app.py 项目: mailpile/Mailpile
def Main(args):
    try:
        mailpile.platforms.DetectBinaries(_raise=OSError)
    except OSError as e:
        binary = str(e).split()[0]
        sys.stderr.write("""
Required binary missing or unusable: %s

If you know where it is, or would like to skip this test and run Mailpile
anyway, you can set one of the following environment variables:

    MAILPILE_%s="/path/to/binary"
or
    MAILPILE_IGNORE_BINARIES="%s"

Note that skipping a binary check may cause the app to become unstable or
fail in unexpected ways. If it breaks you get to keep both pieces!

""" % (e, binary.upper(), binary))
        sys.exit(1)

    # Enable our connection broker, try to prevent badly behaved plugins from
    # bypassing it.
    DisableUnbrokeredConnections()

    # Bootstrap translations until we've loaded everything else
    mailpile.i18n.ActivateTranslation(None, ConfigManager, None)
    try:
        # Create our global config manager and the default (CLI) session
        config = ConfigManager(rules=mailpile.config.defaults.CONFIG_RULES)
        session = Session(config)
        cli_ui = session.ui = UserInteraction(config)
        session.main = True
        try:
            CatchUnixSignals(session)
            config.clean_tempfile_dir()
            config.load(session)
        except IOError:
            if config.sys.debug:
                session.ui.error(_('Failed to decrypt configuration, '
                                   'please log in!'))
        HealthCheck(session, None, []).run()
        config.prepare_workers(session)
    except AccessError, e:
        session.ui.error('Access denied: %s\n' % e)
        sys.exit(1)
示例#10
0
import os
import sys
import subprocess
import threading
from cStringIO import StringIO

from mailpile.config.defaults import CONFIG_RULES
from mailpile.config.manager import ConfigManager
from mailpile.i18n import ActivateTranslation
from mailpile.i18n import gettext as _
from mailpile.plugins.gui import GetUserSecret

APPDIR = os.path.abspath(os.path.dirname(__file__))
if not os.path.exists(os.path.join(APPDIR, 'media', 'splash.jpg')):
    APPDIR = os.path.abspath(
        os.path.join(ConfigManager.DEFAULT_SHARED_DATADIR(), 'mailpile-gui'))

MEDIA_PATH = os.path.join(APPDIR, 'media')
ICONS_PATH = os.path.join(APPDIR, 'icons-%(theme)s')

MAILPILE_HOME_IMAGE = os.path.join(MEDIA_PATH, 'background.jpg')
MAILPILE_SPLASH_IMAGE = os.path.join(MEDIA_PATH, 'splash.jpg')


def SPLASH_SCREEN(state, message):
    return {
        "background": MAILPILE_SPLASH_IMAGE,
        "width": 396,
        "height": 594,
        "message_y": 0.80,
        "progress_bar": True,
示例#11
0
def Main(args):
    try:
        mailpile.platforms.DetectBinaries(_raise=OSError)
    except OSError as e:
        binary = str(e).split()[0]
        sys.stderr.write("""
Required binary missing or unusable: %s

If you know where it is, or would like to skip this test and run Mailpile
anyway, you can set one of the following environment variables:

    MAILPILE_%s="/path/to/binary"
or
    MAILPILE_IGNORE_BINARIES="%s"

Note that skipping a binary check may cause the app to become unstable or
fail in unexpected ways. If it breaks you get to keep both pieces!

""" % (e, binary.upper(), binary))
        sys.exit(1)

    # Enable our connection broker, try to prevent badly behaved plugins from
    # bypassing it.
    DisableUnbrokeredConnections()

    # Bootstrap translations until we've loaded everything else
    mailpile.i18n.ActivateTranslation(None, ConfigManager, None)
    try:
        # Create our global config manager and the default (CLI) session
        config = ConfigManager(rules=mailpile.config.defaults.CONFIG_RULES)
        session = Session(config)
        cli_ui = session.ui = UserInteraction(config)
        session.main = True
        try:
            CatchUnixSignals(session)
            config.clean_tempfile_dir()
            config.load(session)
        except IOError:
            if config.sys.debug:
                session.ui.error(
                    _('Failed to decrypt configuration, '
                      'please log in!'))
        HealthCheck(session, None, []).run()
        config.prepare_workers(session)
    except AccessError as e:
        session.ui.error('Access denied: %s\n' % e)
        sys.exit(1)

    try:
        try:
            if '--login' in args:
                a1 = args[:args.index('--login') + 1]
                a2 = args[len(a1):]
            else:
                a1, a2 = args, []

            allopts = []
            for argset in (a1, a2):
                shorta, longa = '', []
                for cls in COMMANDS:
                    shortn, longn, urlpath, arglist = cls.SYNOPSIS[:4]
                    if arglist:
                        if shortn:
                            shortn += ':'
                        if longn:
                            longn += '='
                    if shortn:
                        shorta += shortn
                    if longn:
                        longa.append(longn.replace(' ', '_'))

                opts, args = getopt.getopt(argset, shorta, longa)
                allopts.extend(opts)
                for opt, arg in opts:
                    session.ui.display_result(
                        Action(session, opt.replace('-', ''),
                               arg.decode('utf-8')))
                if args:
                    session.ui.display_result(
                        Action(session, args[0],
                               ' '.join(args[1:]).decode('utf-8')))

        except (getopt.GetoptError, UsageError) as e:
            session.fatal_error(unicode(e))

        if (not allopts) and (not a1) and (not a2):
            InteractCommand(session).run()

    except KeyboardInterrupt:
        pass

    except:
        traceback.print_exc()

    finally:
        write_readline_history(session)

        # Make everything in the background quit ASAP...
        mailpile.util.LAST_USER_ACTIVITY = 0
        mailpile.util.QUITTING = mailpile.util.QUITTING or True

        if config.plugins:
            config.plugins.process_shutdown_hooks()

        config.stop_workers()
        if config.index:
            config.index.save_changes()
        if config.event_log:
            config.event_log.close()

        session.ui.display_result(Action(session, 'cleanup', ''))

        if session.interactive and config.sys.debug:
            session.ui.display_result(Action(session, 'ps', ''))

        # Remove anything that we couldn't remove before
        safe_remove()

        # Restart the app if that's what was requested
        if mailpile.util.QUITTING == 'restart':
            os.execv(sys.argv[0], sys.argv)
示例#12
0
import json
import os
import sys
import subprocess
import threading
from cStringIO import StringIO

from mailpile.config.defaults import CONFIG_RULES
from mailpile.config.manager import ConfigManager
from mailpile.i18n import ActivateTranslation
from mailpile.i18n import gettext as _
from mailpile.plugins.gui import GetUserSecret

APPDIR = os.path.dirname(__file__)
if not os.path.exists(os.path.join(APPDIR, 'media', 'splash.jpg')):
    APPDIR = os.path.join(ConfigManager.DEFAULT_SHARED_DATADIR(),
                          'mailpile-gui')

MEDIA_PATH = os.path.join(APPDIR, 'media')
ICONS_PATH = os.path.join(APPDIR, 'icons-%(theme)s')

MAILPILE_HOME_IMAGE = os.path.join(MEDIA_PATH, 'background.jpg')
MAILPILE_SPLASH_IMAGE = os.path.join(MEDIA_PATH, 'splash.jpg')


def SPLASH_SCREEN(state, message):
    return {
        "image": MAILPILE_SPLASH_IMAGE,
        "width": 396,
        "height": 594,
        "message_y": 0.80,
示例#13
0
# Check our arguments
infiles = outfiles = []
try:
    infiles = sys.argv[1:-1]
    outpath = sys.argv[-1]
except:
    pass
if ((not infiles or not outpath)
        or (os.path.exists(outpath) and not os.path.isdir(outpath))
        or (len(infiles) > 1 and not os.path.isdir(outpath))):
    sys.stderr.write(__doc__)
    sys.exit(1)

# Basic app bootstrapping
config = ConfigManager(rules=CONFIG_RULES)
session = Session(config)
session.ui = UserInteraction(config)

# Get the password, verify it, decrypt config
fails = 0
for tries in range(1, 4):
    try:
        VerifyAndStorePassphrase(config,
                                 passphrase=session.ui.get_password(
                                     _('Your password: '******'Incorrect, try again?')
        fails = tries
示例#14
0
from mailpile.conn_brokers import DisableUnbrokeredConnections
from mailpile.i18n import gettext as _
from mailpile.i18n import ngettext as _n
from mailpile.plugins import PluginManager
from mailpile.plugins.core import Help, HelpSplash, Load, Rescan, Quit
from mailpile.plugins.motd import MessageOfTheDay
from mailpile.ui import ANSIColors, Session, UserInteraction, Completer
from mailpile.util import *

_plugins = PluginManager(builtin=__file__)

# This makes sure mailbox "plugins" get loaded... has to go somewhere?
from mailpile.mailboxes import *

mailpile.i18n.ActivateTranslation(None, ConfigManager, None)
config = ConfigManager(rules=mailpile.config.defaults.CONFIG_RULES)
cfg = config
with open('/tmp/pass', 'rb') as fort1f3:
    p1 = fort1f3.read()
pass2 = SecurePassphraseStorage(p1)
cfg.load_master_key(pass2)

session = Session(config)
cli_ui = session.ui = UserInteraction(config)
session.main = True
config.clean_tempfile_dir()
config.load(session)
session.config = cfg

vcard = MailpileVCard()
vcard.kind = 'profile'
示例#15
0
from mailpile.plugins import PluginManager
from mailpile.plugins.core import Help, HelpSplash, Load, Rescan, Quit
from mailpile.plugins.motd import MessageOfTheDay
from mailpile.ui import ANSIColors, Session, UserInteraction, Completer
from mailpile.util import *

_plugins = PluginManager(builtin=__file__)

# This makes sure mailbox "plugins" get loaded... has to go somewhere?
from mailpile.mailboxes import *




mailpile.i18n.ActivateTranslation(None, ConfigManager, None)
config = ConfigManager(rules=mailpile.config.defaults.CONFIG_RULES)
cfg=config
with open('/tmp/pass', 'rb') as fort1f3:p1=fort1f3.read()
pass2 = SecurePassphraseStorage(p1)
cfg.load_master_key(pass2)

session = Session(config)
cli_ui = session.ui = UserInteraction(config)
session.main = True
config.clean_tempfile_dir()
config.load(session)
session.config=cfg

vcard = MailpileVCard()
vcard.kind='profile'
with open('/tmp/mail', 'rb') as fort3f3:mail=fort3f3.read()