|
@@ -19,6 +19,7 @@ import threading
|
|
|
import urllib2
|
|
|
import wave
|
|
|
from datetime import datetime
|
|
|
+from email.mime.text import MIMEText
|
|
|
|
|
|
import linphone
|
|
|
import yaml
|
|
@@ -103,7 +104,13 @@ class SipConnection(object):
|
|
|
def mail(self, mail_cfg, text):
|
|
|
try:
|
|
|
server = smtplib.SMTP(mail_cfg["smtp_host"])
|
|
|
- server.sendmail(mail_cfg["from"], mail_cfg["to"], text)
|
|
|
+
|
|
|
+ msg = MIMEText(text)
|
|
|
+ msg['Subject'] = text
|
|
|
+ msg['From'] = mail_cfg["from"]
|
|
|
+ msg['To'] = mail_cfg["to"]
|
|
|
+
|
|
|
+ server.sendmail(mail_cfg["from"], [mail_cfg["to"]], msg.as_string())
|
|
|
server.quit()
|
|
|
except smtplib.SMTPException as e:
|
|
|
self.log("Error sending email " + e.message)
|
|
@@ -133,6 +140,23 @@ class SipConnection(object):
|
|
|
# On laisse l'autre l'occassion de reparler
|
|
|
self._conversation.status = ConversationStatus.WAITFORANSWER
|
|
|
|
|
|
+ def storage_path(self):
|
|
|
+ path = current_dir + "/out/" + str(self) + "/"
|
|
|
+ if not os.path.isdir(path):
|
|
|
+ os.makedirs(path)
|
|
|
+ return path
|
|
|
+
|
|
|
+ def shoul_daccept_first_call(self, number):
|
|
|
+ first_call_file = self.storage_path() + "first_calls.txt"
|
|
|
+ if not os.path.isfile(first_call_file):
|
|
|
+ os.system("touch " + first_call_file)
|
|
|
+ if "accept_first_call" in self._config_info and self._config_info["accept_first_call"] and number not in open(
|
|
|
+ first_call_file).read():
|
|
|
+ os.system("echo " + number + " `date` >> " + first_call_file)
|
|
|
+ self.log("Accepting first call of " + number)
|
|
|
+ return True
|
|
|
+ return False
|
|
|
+
|
|
|
def incoming_stream_worker(self, core, call):
|
|
|
f = open(self._incoming_stream_file, "rb")
|
|
|
f.seek(0, io.SEEK_END)
|
|
@@ -185,7 +209,7 @@ class SipConnection(object):
|
|
|
# Let's convert wav to mp3
|
|
|
if call.current_params.record_file is not None and os.path.isfile(call.current_params.record_file):
|
|
|
self.log("Saving to mp3 : " + call.current_params.record_file)
|
|
|
- subprocess.call('lame --quiet --preset insane %s' % call.current_params.record_file, shell=True)
|
|
|
+ subprocess.call('lame --quiet --preset medium %s' % call.current_params.record_file, shell=True)
|
|
|
os.remove(call.current_params.record_file)
|
|
|
|
|
|
if state == linphone.CallState.IncomingReceived:
|
|
@@ -195,7 +219,8 @@ class SipConnection(object):
|
|
|
|
|
|
self._replies_pos = 0
|
|
|
|
|
|
- if self.is_in_blacklists(call.remote_address.username):
|
|
|
+ if self.shoul_daccept_first_call(call.remote_address.username) or self.is_in_blacklists(
|
|
|
+ call.remote_address.username):
|
|
|
self.log("telemarketer calling : " + call.remote_address.username)
|
|
|
self.mail_if_needed(call.remote_address.username, self.MailType.Notify_Incoming_Telemarketer_Call)
|
|
|
|
|
@@ -203,7 +228,7 @@ class SipConnection(object):
|
|
|
if not os.path.isdir(current_dir + "/out"):
|
|
|
os.makedirs(current_dir + "/out")
|
|
|
|
|
|
- a_file = current_dir + "/out/call_from_" + slugify(call.remote_address.username) + \
|
|
|
+ a_file = self.storage_path() + "call_from_" + slugify(call.remote_address.username) + \
|
|
|
"_" + datetime.now().strftime(
|
|
|
'%Y-%m-%d_%Hh%Mmn%Ss') + ".wav"
|
|
|
|
|
@@ -300,7 +325,7 @@ class SipConnection(object):
|
|
|
self.mail(mail_cfg, "Appel entrant : " + number)
|
|
|
|
|
|
if type == self.MailType.Notify_Incoming_Telemarketer_Call:
|
|
|
- self.mail(mail_cfg, "Appel télémarketeur entrant : " + number)
|
|
|
+ self.mail(mail_cfg, "Appel telemarketeur entrant : " + number)
|
|
|
|
|
|
def is_in_blacklists(self, a_number):
|
|
|
return self.is_in_local_blacklist(a_number) or self.is_in_directory_ch_blacklist(
|