diff --git a/Mailnag/common/accounts.py b/Mailnag/common/accounts.py index 6eb5403..eb2fe8a 100644 --- a/Mailnag/common/accounts.py +++ b/Mailnag/common/accounts.py @@ -24,9 +24,9 @@ import poplib import logging -import daemon.imaplib2 as imaplib -from common.i18n import _ -from common.keyring import Keyring +import Mailnag.daemon.imaplib2 as imaplib +from Mailnag.common.i18n import _ +from Mailnag.common.keyring import Keyring account_defaults = { 'enabled' : '0', diff --git a/Mailnag/common/config.py b/Mailnag/common/config.py index 1f77a59..9efc681 100644 --- a/Mailnag/common/config.py +++ b/Mailnag/common/config.py @@ -24,7 +24,7 @@ import os import xdg.BaseDirectory as bd from ConfigParser import RawConfigParser -from common.i18n import _ +from Mailnag.common.i18n import _ mailnag_defaults = { 'core': diff --git a/Mailnag/common/dist_cfg.py b/Mailnag/common/dist_cfg.py index 8729b75..375fbf2 100644 --- a/Mailnag/common/dist_cfg.py +++ b/Mailnag/common/dist_cfg.py @@ -3,7 +3,7 @@ # # dist_cfg.py # -# Copyright 2012, 2013 Patrick Ulbrich +# Copyright 2012 - 2014 Patrick Ulbrich # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ # Application version displayed in the # about dialog of the config window. -APP_VERSION = "1.0.0" +APP_VERSION = '1.0.0' # The PACKAGE_NAME variable is used to configure # 1) the path where all app data (glade files, images) is loaded from @@ -37,7 +37,7 @@ APP_VERSION = "1.0.0" # 2) paths for localization files generated with gen_locales # (usually /usr/share/locale//LC_MESSAGES/.mo). # Typically, there's no need to touch this variable. -PACKAGE_NAME = "mailnag" +PACKAGE_NAME = 'mailnag' # The LOCALE_DIR variable specifies the root path for localization files # (usually you have to make it point to '/usr/share/locale'). @@ -45,7 +45,7 @@ LOCALE_DIR = './locale' # The LIB_DIR variable specifies the root path for the Mailnag python files # (usually you have to make it point to /Mailnag). -LIB_DIR = "./Mailnag" +LIB_DIR = './Mailnag' # The BIN_DIR variable specifies the path for the mailnag start scripts # (usually you have to make it point to '/usr/bin'). diff --git a/Mailnag/common/i18n.py b/Mailnag/common/i18n.py index 3bcda9f..3ca3a7f 100644 --- a/Mailnag/common/i18n.py +++ b/Mailnag/common/i18n.py @@ -3,7 +3,7 @@ # # i18n.py # -# Copyright 2011, 2012 Patrick Ulbrich +# Copyright 2011, 2012, 2014 Patrick Ulbrich # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ import locale import gettext -from common.dist_cfg import PACKAGE_NAME, LOCALE_DIR +from Mailnag.common.dist_cfg import PACKAGE_NAME, LOCALE_DIR # bind textdomain for GTK Builder locale.bindtextdomain(PACKAGE_NAME, LOCALE_DIR) diff --git a/Mailnag/common/keyring.py b/Mailnag/common/keyring.py index e8e10c5..bfac289 100644 --- a/Mailnag/common/keyring.py +++ b/Mailnag/common/keyring.py @@ -23,7 +23,7 @@ # from gi.repository import GnomeKeyring -from common.i18n import _ +from Mailnag.common.i18n import _ class KeyringUnlockException(Exception): diff --git a/Mailnag/common/plugins.py b/Mailnag/common/plugins.py index 0918f02..440569d 100644 --- a/Mailnag/common/plugins.py +++ b/Mailnag/common/plugins.py @@ -26,8 +26,8 @@ import imp import inspect import logging -from common.config import cfg_folder -from common.dist_cfg import LIB_DIR +from Mailnag.common.config import cfg_folder +from Mailnag.common.dist_cfg import LIB_DIR PLUGIN_LIB_PATH = os.path.join(LIB_DIR, 'plugins') PLUGIN_USER_PATH = os.path.join(cfg_folder, 'plugins') diff --git a/Mailnag/common/utils.py b/Mailnag/common/utils.py index eb20f29..7899aa9 100644 --- a/Mailnag/common/utils.py +++ b/Mailnag/common/utils.py @@ -28,8 +28,9 @@ import sys import time import dbus import logging +import inspect -from common.dist_cfg import PACKAGE_NAME, DBUS_BUS_NAME, DBUS_OBJ_PATH +from Mailnag.common.dist_cfg import PACKAGE_NAME, DBUS_BUS_NAME, DBUS_OBJ_PATH def get_data_paths(): @@ -55,6 +56,15 @@ def get_data_file(filename): return None +def fix_cwd(): + # Change into local Mailnag source dir, where paths + # in dist_cfg.py point to (e.g. "./locale"). + # Only required when running Mailnag locally (wihout installation). + main_script_path = os.path.realpath(inspect.stack()[-1][1]) + main_script_dir = os.path.dirname(main_script_path) + os.chdir(main_script_dir) + + def set_procname(newname): from ctypes import cdll, byref, create_string_buffer libc = cdll.LoadLibrary('libc.so.6') diff --git a/Mailnag/config.py b/Mailnag/config.py deleted file mode 100644 index 706295c..0000000 --- a/Mailnag/config.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python2 -# -*- coding: utf-8 -*- -# -# config.py -# -# Copyright 2011 - 2014 Patrick Ulbrich -# Copyright 2011 Ralf Hersel -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program 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 this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -# MA 02110-1301, USA. -# - -import os -import subprocess -from gi.repository import Gtk -from dbus.mainloop.glib import DBusGMainLoop - -from common.utils import set_procname, shutdown_existing_instance -from common.dist_cfg import BIN_DIR -from configuration.configwindow import ConfigWindow - - -def main(): - set_procname("mailnag-config") - confwin = ConfigWindow() - Gtk.main() - - if confwin.daemon_enabled: - try: - # the launched daemon shuts down - # an already running daemon - print "Launching Mailnag daemon." - subprocess.Popen(os.path.join(BIN_DIR, "mailnagd")) - except: - print "ERROR: Failed to launch Mailnag daemon." - else: - DBusGMainLoop(set_as_default = True) - # shutdown running Mailnag daemon - shutdown_existing_instance() - - -if __name__ == "__main__": main() diff --git a/Mailnag/configuration/accountdialog.py b/Mailnag/configuration/accountdialog.py index 1592848..db56e83 100644 --- a/Mailnag/configuration/accountdialog.py +++ b/Mailnag/configuration/accountdialog.py @@ -22,9 +22,9 @@ # from gi.repository import GLib, Gtk -from common.dist_cfg import PACKAGE_NAME -from common.i18n import _ -from common.utils import get_data_file +from Mailnag.common.dist_cfg import PACKAGE_NAME +from Mailnag.common.i18n import _ +from Mailnag.common.utils import get_data_file IDX_GMAIL = 0 IDX_GMX = 1 diff --git a/Mailnag/configuration/configwindow.py b/Mailnag/configuration/configwindow.py index 461ed31..0d7677f 100644 --- a/Mailnag/configuration/configwindow.py +++ b/Mailnag/configuration/configwindow.py @@ -26,14 +26,14 @@ import os import xdg.BaseDirectory as bd from gi.repository import GLib, GdkPixbuf, Gdk, Gtk, GObject -from common.dist_cfg import PACKAGE_NAME, APP_VERSION -from common.i18n import _ -from common.utils import get_data_file, get_data_paths -from common.config import read_cfg, write_cfg -from common.accounts import Account, AccountList -from common.plugins import Plugin -from configuration.accountdialog import AccountDialog -from configuration.plugindialog import PluginDialog +from Mailnag.common.dist_cfg import PACKAGE_NAME, APP_VERSION, BIN_DIR +from Mailnag.common.i18n import _ +from Mailnag.common.utils import get_data_file, get_data_paths +from Mailnag.common.config import read_cfg, write_cfg +from Mailnag.common.accounts import Account, AccountList +from Mailnag.common.plugins import Plugin +from Mailnag.configuration.accountdialog import AccountDialog +from Mailnag.configuration.plugindialog import PluginDialog class ConfigWindow: @@ -269,10 +269,8 @@ class ConfigWindow: def _create_autostart(self): - # get current working directory - curdir = os.getcwd() # path to mailnag startscript - exec_file = os.path.join(curdir, "mailnagd") + exec_file = os.path.join(os.path.abspath(BIN_DIR), "mailnag") content = "\n" + \ "[Desktop Entry]\n" + \ diff --git a/Mailnag/configuration/plugindialog.py b/Mailnag/configuration/plugindialog.py index e2ddea9..8b9a6ff 100644 --- a/Mailnag/configuration/plugindialog.py +++ b/Mailnag/configuration/plugindialog.py @@ -22,8 +22,8 @@ # from gi.repository import GLib, Gtk -from common.dist_cfg import PACKAGE_NAME -from common.utils import get_data_file +from Mailnag.common.dist_cfg import PACKAGE_NAME +from Mailnag.common.utils import get_data_file class PluginDialog: def __init__(self, parent, plugin): diff --git a/Mailnag/daemon/idlers.py b/Mailnag/daemon/idlers.py index 9699725..f37aac9 100644 --- a/Mailnag/daemon/idlers.py +++ b/Mailnag/daemon/idlers.py @@ -25,8 +25,8 @@ import threading import time import logging -from daemon.imaplib2 import AUTH -from common.exceptions import InvalidOperationException +from Mailnag.daemon.imaplib2 import AUTH +from Mailnag.common.exceptions import InvalidOperationException class ConnectionException(Exception): diff --git a/Mailnag/daemon/mailchecker.py b/Mailnag/daemon/mailchecker.py index 1bf9e53..2c50a7c 100644 --- a/Mailnag/daemon/mailchecker.py +++ b/Mailnag/daemon/mailchecker.py @@ -25,10 +25,10 @@ import threading import logging -from common.utils import try_call -from common.i18n import _ -from common.plugins import HookTypes -from daemon.mails import MailSyncer +from Mailnag.common.utils import try_call +from Mailnag.common.i18n import _ +from Mailnag.common.plugins import HookTypes +from Mailnag.daemon.mails import MailSyncer class MailChecker: diff --git a/Mailnag/daemon/mailnagdaemon.py b/Mailnag/daemon/mailnagdaemon.py index 0b260ba..ea12b17 100644 --- a/Mailnag/daemon/mailnagdaemon.py +++ b/Mailnag/daemon/mailnagdaemon.py @@ -25,15 +25,15 @@ import threading import logging import time -from common.accounts import AccountList -from daemon.mailchecker import MailChecker -from daemon.mails import Memorizer -from daemon.idlers import IdlerRunner -from daemon.conntest import ConnectivityTest, TestModes -from common.plugins import Plugin, HookRegistry, HookTypes, MailnagController -from common.exceptions import InvalidOperationException -from common.config import read_cfg -from common.utils import try_call +from Mailnag.common.accounts import AccountList +from Mailnag.daemon.mailchecker import MailChecker +from Mailnag.daemon.mails import Memorizer +from Mailnag.daemon.idlers import IdlerRunner +from Mailnag.daemon.conntest import ConnectivityTest, TestModes +from Mailnag.common.plugins import Plugin, HookRegistry, HookTypes, MailnagController +from Mailnag.common.exceptions import InvalidOperationException +from Mailnag.common.config import read_cfg +from Mailnag.common.utils import try_call testmode_mapping = { diff --git a/Mailnag/daemon/mails.py b/Mailnag/daemon/mails.py index f0845b4..d64db24 100644 --- a/Mailnag/daemon/mails.py +++ b/Mailnag/daemon/mails.py @@ -29,9 +29,9 @@ import os import logging import hashlib -from common.i18n import _ -from common.config import cfg_folder from email.header import decode_header +from Mailnag.common.i18n import _ +from Mailnag.common.config import cfg_folder # diff --git a/Mailnag/plugins/dbusplugin.py b/Mailnag/plugins/dbusplugin.py index 9108ad9..bcc530c 100644 --- a/Mailnag/plugins/dbusplugin.py +++ b/Mailnag/plugins/dbusplugin.py @@ -23,10 +23,10 @@ import dbus import dbus.service -from common.dist_cfg import DBUS_BUS_NAME, DBUS_OBJ_PATH -from common.plugins import Plugin, HookTypes -from common.exceptions import InvalidOperationException -from common.i18n import _ +from Mailnag.common.dist_cfg import DBUS_BUS_NAME, DBUS_OBJ_PATH +from Mailnag.common.plugins import Plugin, HookTypes +from Mailnag.common.exceptions import InvalidOperationException +from Mailnag.common.i18n import _ plugin_defaults = {} diff --git a/Mailnag/plugins/libnotifyplugin.py b/Mailnag/plugins/libnotifyplugin.py index 5f128fd..3bea5e8 100644 --- a/Mailnag/plugins/libnotifyplugin.py +++ b/Mailnag/plugins/libnotifyplugin.py @@ -25,11 +25,11 @@ import os import dbus import threading from gi.repository import Notify, Gio, Gtk -from common.plugins import Plugin, HookTypes -from common.i18n import _ -from common.subproc import start_subprocess -from common.exceptions import InvalidOperationException -from daemon.mails import sort_mails +from Mailnag.common.plugins import Plugin, HookTypes +from Mailnag.common.i18n import _ +from Mailnag.common.subproc import start_subprocess +from Mailnag.common.exceptions import InvalidOperationException +from Mailnag.daemon.mails import sort_mails MAX_VISIBLE_MAILS_LIMIT = 20.0 diff --git a/Mailnag/plugins/soundplugin.py b/Mailnag/plugins/soundplugin.py index 2822a71..1e94bd1 100644 --- a/Mailnag/plugins/soundplugin.py +++ b/Mailnag/plugins/soundplugin.py @@ -23,10 +23,11 @@ import os import threading -from common.plugins import Plugin, HookTypes -from common.utils import get_data_file -from common.i18n import _ from gi.repository import Gst +from Mailnag.common.plugins import Plugin, HookTypes +from Mailnag.common.utils import get_data_file +from Mailnag.common.i18n import _ + plugin_defaults = { 'soundfile' : 'mailnag.ogg' } diff --git a/Mailnag/plugins/spamfilterplugin.py b/Mailnag/plugins/spamfilterplugin.py index 38db66f..f0d4cad 100644 --- a/Mailnag/plugins/spamfilterplugin.py +++ b/Mailnag/plugins/spamfilterplugin.py @@ -22,8 +22,8 @@ # from gi.repository import Gtk -from common.plugins import Plugin, HookTypes -from common.i18n import _ +from Mailnag.common.plugins import Plugin, HookTypes +from Mailnag.common.i18n import _ plugin_defaults = { 'filter_text' : 'newsletter, viagra' } diff --git a/Mailnag/plugins/userscriptplugin.py b/Mailnag/plugins/userscriptplugin.py index dfd8948..2543572 100644 --- a/Mailnag/plugins/userscriptplugin.py +++ b/Mailnag/plugins/userscriptplugin.py @@ -23,9 +23,9 @@ import os from gi.repository import Gtk -from common.plugins import Plugin, HookTypes -from common.i18n import _ -from common.subproc import start_subprocess +from Mailnag.common.plugins import Plugin, HookTypes +from Mailnag.common.i18n import _ +from Mailnag.common.subproc import start_subprocess plugin_defaults = { 'script_file' : '' } diff --git a/data/mailnagd.1 b/data/mailnag.1 similarity index 73% rename from data/mailnagd.1 rename to data/mailnag.1 index cbf8785..8262b45 100644 --- a/data/mailnagd.1 +++ b/data/mailnag.1 @@ -1,10 +1,10 @@ -.TH MAILNAGD "1" "June 2014" "Mailnag 1.0.0" +.TH MAILNAG "1" "June 2014" "Mailnag 1.0.0" .SH NAME mailnag \- an extensible mail notification daemon .SH SYNOPSIS -\fBmailnagd\fP +\fBmailnag\fP .SH DESCRIPTION -\fBmailnagd\fP is a daemon program that checks POP3 and IMAP servers for new mail. +\fBmailnag\fP is a daemon program that checks POP3 and IMAP servers for new mail. On mail arrival it performs various actions provided by plugins. It comes with a set of desktop-independent default plugins for visual/sound notifications, script execution etc. and can be extended @@ -15,7 +15,7 @@ Note that you must first run \fBmailnag-config\fR to setup Mailnag. .PP \fBmailnag-config\fP(1) .SH AUTHOR -\fBmailnagd\fP was written by Patrick Ulbrich . +\fBmailnag\fP was written by Patrick Ulbrich . .PP This manual page was written by Vincent Cheng , for the Debian project (and may be used by others). diff --git a/Mailnag/mailnag.py b/mailnag old mode 100644 new mode 100755 similarity index 88% rename from Mailnag/mailnag.py rename to mailnag index 6d0c2f1..6a137fc --- a/Mailnag/mailnag.py +++ b/mailnag @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- # -# mailnag.py +# mailnag # # Copyright 2011 - 2014 Patrick Ulbrich # Copyright 2011 Leighton Earl @@ -32,14 +32,14 @@ import logging.handlers import os import signal -from common.config import cfg_exists -from common.dist_cfg import APP_VERSION -from common.utils import set_procname, shutdown_existing_instance -from common.subproc import terminate_subprocesses -from common.exceptions import InvalidOperationException -from daemon.mailnagdaemon import MailnagDaemon +from Mailnag.common.config import cfg_exists +from Mailnag.common.dist_cfg import APP_VERSION +from Mailnag.common.utils import set_procname, shutdown_existing_instance, fix_cwd +from Mailnag.common.subproc import terminate_subprocesses +from Mailnag.common.exceptions import InvalidOperationException +from Mailnag.daemon.mailnagdaemon import MailnagDaemon -PROGNAME = 'mailnagd' +PROGNAME = 'mailnag' LOG_LEVEL = logging.DEBUG LOG_FORMAT = '%(levelname)s (%(asctime)s): %(message)s' @@ -71,9 +71,7 @@ def get_args(): parser.add_argument('-q', '--quiet', action = 'store_true', help = "don't print log messages to stdout") parser.add_argument('-v', '--version', action = 'version', - version = 'Mailnag %s' % APP_VERSION) - parser.add_argument('-f', '--foreground', action = 'store_true', - help = "don't run mailnagd in daemon mode") + version = '%s %s' % (PROGNAME, APP_VERSION)) return parser.parse_args() @@ -104,6 +102,8 @@ def sigterm_handler(mainloop): def main(): + fix_cwd() + mainloop = GLib.MainLoop() daemon = None diff --git a/mailnag-config b/mailnag-config index 992c460..964820f 100755 --- a/mailnag-config +++ b/mailnag-config @@ -1,5 +1,55 @@ -#!/bin/bash -LIB_DIR=./Mailnag +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# +# mailnag-config +# +# Copyright 2011 - 2014 Patrick Ulbrich +# Copyright 2011 Ralf Hersel +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. +# -cd $(dirname $(readlink -f $0)) -python2 $LIB_DIR/config.py $@ +import os +import subprocess +from gi.repository import Gtk +from dbus.mainloop.glib import DBusGMainLoop + +from Mailnag.common.utils import set_procname, shutdown_existing_instance, fix_cwd +from Mailnag.common.dist_cfg import BIN_DIR +from Mailnag.configuration.configwindow import ConfigWindow + + +def main(): + fix_cwd() + set_procname("mailnag-config") + confwin = ConfigWindow() + Gtk.main() + + if confwin.daemon_enabled: + try: + # the launched daemon shuts down + # an already running daemon + print "Launching Mailnag daemon." + subprocess.Popen(os.path.join(BIN_DIR, "mailnag")) + except: + print "ERROR: Failed to launch Mailnag daemon." + else: + DBusGMainLoop(set_as_default = True) + # shutdown running Mailnag daemon + shutdown_existing_instance() + + +if __name__ == "__main__": main() diff --git a/mailnagd b/mailnagd deleted file mode 100755 index 0b764c4..0000000 --- a/mailnagd +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -LIB_DIR=./Mailnag - -cd $(dirname $(readlink -f $0)) - -if [ $# -eq 0 ] || [ $1 == "--quiet" ] || [ $1 == "-q" ]; then - python2 $LIB_DIR/mailnag.py $@ & -else - python2 $LIB_DIR/mailnag.py $@ -fi diff --git a/setup.py b/setup.py index c01bedd..26beab8 100755 --- a/setup.py +++ b/setup.py @@ -56,13 +56,13 @@ class BuildData(build): shutil.copytree('Mailnag/common', os.path.join(BUILD_PATCH_DIR, 'common')) # patch paths - self._patch_file('./mailnagd', os.path.join(BUILD_PATCH_DIR, 'mailnagd'), './Mailnag', INSTALL_LIB_DIR) - self._patch_file('./mailnag-config', os.path.join(BUILD_PATCH_DIR, 'mailnag-config'), './Mailnag', INSTALL_LIB_DIR) self._patch_file('./data/mailnag-config.desktop', os.path.join(BUILD_PATCH_DIR, 'mailnag-config.desktop'), '/usr', PREFIX) self._patch_file(os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), './locale', os.path.join(PREFIX, 'share/locale')) self._patch_file(os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), './Mailnag', os.path.join(PREFIX, INSTALL_LIB_DIR)) + self._patch_file(os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), + "'.'", "'%s'" % os.path.join(PREFIX, 'bin')) build.run (self) @@ -111,13 +111,13 @@ setup(name=PACKAGE_NAME, license='GNU GPL2', package_dir = {'Mailnag.common' : os.path.join(BUILD_PATCH_DIR, 'common')}, packages=['Mailnag', 'Mailnag.common', 'Mailnag.configuration', 'Mailnag.daemon', 'Mailnag.plugins'], - scripts=[os.path.join(BUILD_PATCH_DIR, 'mailnagd'), os.path.join(BUILD_PATCH_DIR, 'mailnag-config')], + scripts=['mailnag', 'mailnag-config'], data_files=[('share/mailnag', glob.glob('data/*.ui')), ('share/mailnag', ['data/config_window.css']), ('share/mailnag', ['data/mailnag.ogg']), ('share/mailnag', ['data/mailnag.png']), ('share/applications', [os.path.join(BUILD_PATCH_DIR, 'mailnag-config.desktop')])], cmdclass={'build': BuildData, - 'install_data': InstallData, - 'uninstall': Uninstall} + 'install_data': InstallData, + 'uninstall': Uninstall} )