示例#1
0
 def __init__(self):
     # 設定をコピー
     self.settings = {}
     for key in ('id', 'pw', 'auto', 'addr', 'http', 'https', 'session'):
         self.settings[key] = Common.GET('garapon_%s' % key)
     # サーバアドレス
     self.server = 'http://%s' % self.settings['addr']
     if self.settings['http']:
         self.server = '%s:%s' % (self.server, self.settings['http'])
示例#2
0
 def __init__(self):
     # トークン初期化
     self.data = Common.read_json(Common.TOKEN_FILE) or {}
     # settings.xmlを作成
     self.update_settings()
     # 表示するメール数
     self.listsize = Common.GET('listsize')
     if self.listsize == 'Unlimited':
         self.listsize = 0
     else:
         self.listsize = int(self.listsize)
示例#3
0
 def check_timer(self):
     interval = Common.GET('interval')
     status = False
     if interval == 'None':
         self.timer = 0
     elif self.timer < int(interval):
         self.timer += 1
     else:
         status = True
         self.timer = 0
     return status
示例#4
0
 def check(self, refresh=True):
     # 管理用ファイル
     criterion_file = os.path.join(self.cache_path, '.criterion')
     newmails_file = os.path.join(self.cache_path, '.newmails')
     # ロケールを変更
     locale.setlocale(locale.LC_TIME, 'en_US.UTF-8')
     # 前回表示時の月日を読み込む
     if os.path.isfile(criterion_file):
         f = open(criterion_file, 'r')
         criterion = f.read()
         f.close()
     else:
         # 前回表示時の月日が不明の場合は30日前に設定
         d = datetime.datetime.utcnow() - datetime.timedelta(days=30)
         criterion = d.strftime('SINCE %d-%b-%Y')
     # 設定した期間のメールを検索
     newmails, senders = self.receive(criterion)
     if len(newmails) > 0:
         # 新着メールのファイルパスリストを書き出す
         f = open(newmails_file, 'a')
         f.write('\n'.join(newmails) + '\n')
         f.close()
         xbmc.sleep(1000)
         # Kodiをアクティベート
         if Common.GET('cec') == 'true':
             xbmc.executebuiltin('XBMC.CECActivateSource')
         # 新着があることを通知
         Common.notify('New mail from %s' % senders[newmails[0]])
     # アドオン操作で呼び出された場合の処理
     if refresh:
         if os.path.isfile(newmails_file):
             # 新着メールのファイルパスリストを読み込む
             f = open(newmails_file, 'r')
             newmails = f.read().split('\n')
             f.close()
             # 新着メールのファイルパスリストを削除
             os.remove(newmails_file)
         else:
             newmails = []
         # リストを表示
         self.list(newmails)
         # 次回表示時のために今回表示時の月日を書き出す
         d = datetime.datetime.utcnow()
         criterion = d.strftime('SINCE %d-%b-%Y')
         f = open(criterion_file, 'w')
         f.write(criterion)
         f.close()
# -*- coding: utf-8 -*-

import sys
import os
import re

from resources.lib.common import Common
from resources.lib.phonebook import PhoneBook
from resources.lib.history import History
from resources.lib.defaultsearch import search

# searchをインポート
path = Common.GET('customsearch')
if os.path.isfile(path):
    dirname = os.path.dirname(path)
    if os.path.samefile(path, os.path.join(dirname, 'customsearch.py')):
        sys.path.append(os.path.dirname(path))
        from customsearch import search


def parse(uri):
    key = None
    m = re.compile(r'(?:"(.*)"|(.*))\s*<(sip:(.*)@.*|.*)>').search(uri)
    if m:
        key = m.group(1) or m.group(2) or m.group(4) or m.group(3)
    return key


def lookup(uri):
    name = None
    key = parse(uri)
示例#6
0
from resources.lib.common import Common
from resources.lib.history import History
from resources.lib.phonebook import PhoneBook

if __name__ == '__main__':

    # 引数
    args = parse_qs(sys.argv[2][1:], keep_blank_values=True)
    for key in args.keys():
        args[key] = args[key][0]
    action = args.get('action', 'showHistory')

    # アドオン設定
    settings = {}
    for key in ('key', 'name'):
        settings[key] = Common.GET(key)
    Common.SET('key', '')
    Common.SET('name', '')
    Common.SET('mode', 'create')

    # actionに応じた処理

    # 着信履歴
    if action == 'showHistory':
        History().show()
    elif action == 'clearHistory':
        History().clear()
        xbmc.executebuiltin('Container.Refresh()')

    # 電話帳
    elif action == 'showPhoneBook':
示例#7
0
            return False


if __name__ == '__main__':
    # パラメータ抽出
    args = parse_qs(sys.argv[2][1:], keep_blank_values=True)
    for key in args.keys():
        args[key] = args[key][0]
    action = args.get('action')
    # トークンの有無をチェック
    if action != 'addtoken' and len(Token().data.keys()) == 0:
        Common.ADDON.openSettings()
        sys.exit()
    # メイン処理
    if action is None:
        if Common.GET('startup') == "0":
            # トークン一覧を表示
            Token().show_tokens()
        else:
            # デフォルトトークンのメッセージの履歴を表示
            Token().show_history(Common.GET('defaultname'))
    elif action == 'token':
        # トークン一覧を表示
        Token().show_tokens()
    elif action == 'history':
        # メッセージの履歴を表示
        name = args.get('name', Common.GET('defaultname'))
        if name:
            Token().show_history(name)
    elif action == 'message':
        # メッセージの内容を表示
    # パラメータ抽出
    args = parse_qs(sys.argv[2][1:], keep_blank_values=True)
    for key in args.keys():
        args[key] = args[key][0]

    mode = args.get('mode', '')
    url = args.get('url', '')

    # アドオン設定をコピー
    settings = {}
    if not os.path.isfile(Common.SETTINGS_FILE):
        # settings.xmlがない場合はテンプレートをコピーする
        shutil.copyfile(Common.TEMPLATE_FILE, Common.SETTINGS_FILE)
    else:
        for id in ['keyword', 'query']:
            settings[id] = Common.GET(id)
            Common.SET(id, '')
        for id in ['source']:
            settings[id] = Common.GET(id)
            Common.SET(id, '0')
        for id in ['channel']:
            settings[id] = Common.GET(id)
            Common.SET(id, Channel().getDefault())
        for id in [
                'g0', 'g00', 'g01', 'g02', 'g03', 'g04', 'g05', 'g06', 'g07',
                'g08', 'g09', 'g10', 'g11'
        ]:
            settings[id] = Common.GET(id)
            Common.SET(id, Genre().getDefault(id))

    # キャッシュサイズが未設定の場合は設定
def checkSettings():
    # 必須設定項目をチェック
    return Common.GET('garapon_id') and Common.GET('garapon_pw') and Common.GET('garapon_addr') and Common.GET('garapon_session')
 def onIncomingCall(self, param):
     # ログ
     Common.log('\n'.join([
         # https://www.pjsip.org/pjsip/docs/html/structpj_1_1OnIncomingCallParam.htm
         'callId: %s' % param.callId,
         # 'rdata: %s' % param.rdata,
         'rdata.info: %s' % param.rdata.info,
         'rdata.wholeMsg: \n-----\n%s\n-----' % '\n'.join(param.rdata.wholeMsg.strip().split('\r\n')),
         'rdata.srcAddress: %s' % param.rdata.srcAddress,
         'rdata.pjRxData: %s' % param.rdata.pjRxData,
     ]))
     call = pj.Call(self, param.callId)
     info = call.getInfo()
     Common.log('\n'.join([
         # https://www.pjsip.org/pjsip/docs/html/structpj_1_1CallInfo.htm
         'id: %s' % info.id,
         'role: %s' % info.role,
         'accId: %s' % info.accId,
         'localUri: %s' % info.localUri,
         'localContact: %s' % info.localContact,
         'remoteUri: %s' % info.remoteUri,
         'remoteContact: %s' % info.remoteContact,
         'callIdString: %s' % info.callIdString,
         # 'setting: %s' % info.setting,
         'setting.flag: %s' % info.setting.flag,
         'setting.reqKeyframeMethod: %s' % info.setting.reqKeyframeMethod,
         'setting.audioCount: %s' % info.setting.audioCount,
         'setting.videoCount: %s' % info.setting.videoCount,
         'state: %s' % info.state,
         'stateText: %s' % info.stateText,
         'lastStatusCode: %s' % info.lastStatusCode,
         'media: %s' % info.media,
         'provMedia: %s' % info.provMedia,
         'connectDuration: %d.%03d' % (info.connectDuration.sec, info.connectDuration.msec),
         'totalDuration: %d.%03d' % (info.totalDuration.sec, info.totalDuration.msec),
         'remOfferer: %s' % info.remOfferer,
         'remAudioCount: %s' % info.remAudioCount,
         'remVideoCount: %s' % info.remVideoCount,
     ]))
     # Kodiをアクティベート
     if Common.GET('cec') == 'true':
         xbmc.executebuiltin('CECActivateSource')
     # 発信者番号から番号検索
     name, key = lookup(info.remoteUri)
     local = parse(info.localUri)
     # 通知
     duration = Common.GET('duration')
     Common.notify(name, time=int(duration) * 1000)
     # メールによる通知
     if Common.GET('mailaddon') and Common.GET('mailnotify') == 'true':
         template = Common.GET('mailtemplate') or Common.STR(32913)
         address = Common.GET('mailaddress')
         message = template.format(name=name, key=key, local=local)
         xbmc.executebuiltin('RunPlugin("plugin://%s?%s")' % (Common.GET('mailaddon'), urlencode({
             'action': 'send',
             'subject': message,
             'message': message,
             'to': address
         })))
     # LINE notifyによる通知
     if Common.GET('lineaddon') and Common.GET('linenotify') == 'true':
         template = Common.GET('linetemplate') or Common.STR(32913)
         token = Common.GET('linetoken')
         message = template.format(name=name, key=key, local=local)
         xbmc.executebuiltin('RunPlugin("plugin://%s?%s")' % (Common.GET('lineaddon'), urlencode({
             'action': 'send',
             'name': token,
             'message': message
         })))
import sys
import os
import glob
import shutil
import xbmc
import xbmcaddon

from urllib.parse import urlencode

from resources.lib.common import Common
from resources.lib.lookup import parse
from resources.lib.lookup import lookup

# pjsua2.pyのパス設定を取得
srcfile = Common.GET('pjsua2')
# 設定をチェック
if not os.path.isfile(srcfile) or os.path.basename(srcfile) != 'pjsua2.py':
    Common.ADDON.openSettings()
    sys.exit()
try:
    # pjsua2.pyをコピー
    shutil.copy(srcfile, Common.PY_FILE)
    # _pjsua2.soをコピー
    srcfile = glob.glob(os.path.join(os.path.dirname(srcfile), '_pjsua2*.so'))[0]
    shutil.copy(srcfile, Common.SO_FILE)
    # インポート実行
    from resources.pjsua2 import pjsua2 as pj
except Exception as e:
    Common.notify('Importing pjsua2 failed', time=3000, error=True)
    Common.log(e)
示例#12
0
 def main(self):
     # パラメータ抽出
     params = {
         'action': '',
         'filename': '',
         'subject': '',
         'message': '',
         'to': [],
         'cc': []
     }
     args = parse_qs(sys.argv[2][1:])
     for key in params.keys():
         params[key] = args.get(key, params[key])
     for key in ['action', 'filename', 'subject', 'message']:
         params[key] = params[key] and params[key][0]
     # メイン処理
     if params['action'] == '':
         start = Common.GET('start')
         if start == "true":
             # 新着をチェックして表示
             self.check()
         else:
             # 新着をチェックしないで表示
             self.list(newmails=[])
     elif params['action'] == 'check':
         # 新着をチェックして表示
         self.check()
     elif params['action'] == 'refresh':
         # キャッシュクリア
         files = os.listdir(self.cache_path)
         for filename in files:
             os.remove(os.path.join(self.cache_path, filename))
         # 再読み込み
         xbmc.executebuiltin('Container.Update(%s?action=check,replace)' %
                             (sys.argv[0]))
     elif params['action'] == 'open':
         # メールの内容を表示
         if params['filename']:
             self.open(params['filename'])
     elif params['action'] == 'sendmessage':
         # メールを送信
         subject = Common.GET('subject')
         message = Common.GET('message')
         to = Common.GET('to')
         cc = Common.GET('cc')
         # 送信データ
         values = {
             'action': 'send',
             'subject': subject,
             'message': message,
             'to': to,
             'cc': cc
         }
         postdata = urlencode(values)
         xbmc.executebuiltin('RunPlugin(%s?%s)' % (sys.argv[0], postdata))
     elif params['action'] == 'prepmessage':
         Common.SET('subject', params['subject'])
         Common.SET('message', params['message'])
         Common.SET('to', ','.join(params['to']))
         Common.SET('cc', ','.join(params['cc']))
         xbmc.executebuiltin('Addon.OpenSettings(%s)' % Common.ADDON_ID)
         xbmc.executebuiltin('SetFocus(101)')  # 2nd category
         xbmc.executebuiltin('SetFocus(203)')  # 4th control
     elif params['action'] == 'send':
         # メールを送信
         if Common.GET('bcc') == 'true':
             bcc = [self.service.smtp_from]
         else:
             bcc = []
         self.send(subject=params['subject'],
                   message=params['message'],
                   to=params['to'],
                   cc=params['cc'],
                   bcc=bcc)
示例#13
0
 def __init__(self, service=None):
     # メールサービスを初期化
     self.service = None
     service = service or Common.GET('service')
     if service == 'Custom':
         user = Common.GET('user')
         password = Common.GET('password')
         smtp_host = Common.GET('smtp_host')
         smtp_port = Common.GET('smtp_port')
         smtp_auth = Common.GET('smtp_auth')
         smtp_ssl = Common.GET('smtp_ssl')
         smtp_tls = Common.GET('smtp_tls')
         smtp_from = Common.GET('smtp_from')
         imap_host = Common.GET('imap_host')
         imap_port = Common.GET('imap_port')
         imap_ssl = Common.GET('imap_ssl')
         imap_tls = Common.GET('imap_tls')
         if user and password and smtp_host and smtp_port and smtp_from and smtp_host and smtp_port:
             config = {
                 'smtp_host': smtp_host,
                 'smtp_port': int(smtp_port),
                 'smtp_auth': smtp_auth == 'true',
                 'smtp_ssl': smtp_ssl == 'true',
                 'smtp_tls': smtp_tls == 'true',
                 'smtp_from': smtp_from,
                 'imap_host': imap_host,
                 'imap_port': int(imap_port),
                 'imap_ssl': imap_ssl == 'true',
                 'imap_tls': imap_tls == 'true'
             }
             self.service = Mail(user, password, config)
     elif service == 'Gmail':
         user = Common.GET('user1')
         password = Common.GET('password1')
         if user and password:
             self.service = Gmail(user, password)
     elif service == 'iCloud':
         user = Common.GET('user2')
         password = Common.GET('password2')
         if user and password:
             self.service = iCloud(user, password)
     # メールサービスが正常に初期化されたら他の初期化を実行
     if self.service:
         # キャッシュディレクトリのパス
         profile_path = xbmcvfs.translatePath(Common.INFO('profile'))
         self.cache_path = os.path.join(profile_path, 'cache', service)
         if not os.path.isdir(self.cache_path):
             os.makedirs(self.cache_path)
         # 表示するメール数
         self.listsize = Common.GET('listsize')
         if self.listsize == 'Unlimited':
             self.listsize = 0
         else:
             self.listsize = int(self.listsize)