detect error while encrypting message, block sending it, and display error message. fixes #2712
This commit is contained in:
parent
0229aa33ec
commit
f89ccfe441
|
@ -498,16 +498,19 @@ class ChatControlBase(MessageControl):
|
||||||
|
|
||||||
def send_message(self, message, keyID = '', type = 'chat', chatstate = None,
|
def send_message(self, message, keyID = '', type = 'chat', chatstate = None,
|
||||||
msg_id = None, composing_jep = None, resource = None):
|
msg_id = None, composing_jep = None, resource = None):
|
||||||
'''Send the given message to the active tab'''
|
'''Send the given message to the active tab. Doesn't return None if error
|
||||||
|
'''
|
||||||
if not message or message == '\n':
|
if not message or message == '\n':
|
||||||
return
|
return 1
|
||||||
|
|
||||||
|
|
||||||
if not self._process_command(message):
|
if not self._process_command(message):
|
||||||
MessageControl.send_message(self, message, keyID, type = type,
|
ret = MessageControl.send_message(self, message, keyID, type = type,
|
||||||
chatstate = chatstate, msg_id = msg_id,
|
chatstate = chatstate, msg_id = msg_id,
|
||||||
composing_jep = composing_jep, resource = resource,
|
composing_jep = composing_jep, resource = resource,
|
||||||
user_nick = self.user_nick)
|
user_nick = self.user_nick)
|
||||||
|
if ret:
|
||||||
|
return ret
|
||||||
# Record message history
|
# Record message history
|
||||||
self.save_sent_message(message)
|
self.save_sent_message(message)
|
||||||
|
|
||||||
|
@ -1166,10 +1169,10 @@ class ChatControl(ChatControlBase):
|
||||||
gobject.source_remove(self.possible_inactive_timeout_id)
|
gobject.source_remove(self.possible_inactive_timeout_id)
|
||||||
self._schedule_activity_timers()
|
self._schedule_activity_timers()
|
||||||
|
|
||||||
ChatControlBase.send_message(self, message, keyID, type = 'chat',
|
if not ChatControlBase.send_message(self, message, keyID, type = 'chat',
|
||||||
chatstate = chatstate_to_send,
|
chatstate = chatstate_to_send, composing_jep = composing_jep):
|
||||||
composing_jep = composing_jep)
|
self.print_conversation(message, self.contact.jid,
|
||||||
self.print_conversation(message, self.contact.jid, encrypted = encrypted)
|
encrypted = encrypted)
|
||||||
|
|
||||||
def check_for_possible_paused_chatstate(self, arg):
|
def check_for_possible_paused_chatstate(self, arg):
|
||||||
''' did we move mouse of that window or write something in message
|
''' did we move mouse of that window or write something in message
|
||||||
|
|
|
@ -79,16 +79,20 @@ else:
|
||||||
return str
|
return str
|
||||||
self.options.recipients = recipients # a list!
|
self.options.recipients = recipients # a list!
|
||||||
|
|
||||||
proc = self.run(['--encrypt'], create_fhs=['stdin', 'stdout'])
|
proc = self.run(['--encrypt'], create_fhs=['stdin', 'stdout',
|
||||||
|
'stderr'])
|
||||||
proc.handles['stdin'].write(str)
|
proc.handles['stdin'].write(str)
|
||||||
proc.handles['stdin'].close()
|
proc.handles['stdin'].close()
|
||||||
|
|
||||||
output = proc.handles['stdout'].read()
|
output = proc.handles['stdout'].read()
|
||||||
proc.handles['stdout'].close()
|
proc.handles['stdout'].close()
|
||||||
|
|
||||||
|
error = proc.handles['stderr'].read()
|
||||||
|
proc.handles['stderr'].close()
|
||||||
|
|
||||||
try: proc.wait()
|
try: proc.wait()
|
||||||
except IOError: pass
|
except IOError: pass
|
||||||
return self._stripHeaderFooter(output)
|
return self._stripHeaderFooter(output), error
|
||||||
|
|
||||||
def decrypt(self, str, keyID):
|
def decrypt(self, str, keyID):
|
||||||
if not USE_GPG:
|
if not USE_GPG:
|
||||||
|
|
|
@ -687,11 +687,11 @@ class Connection(ConnectionHandlers):
|
||||||
chatstate = None, msg_id = None, composing_jep = None, resource = None,
|
chatstate = None, msg_id = None, composing_jep = None, resource = None,
|
||||||
user_nick = None, xhtml = None):
|
user_nick = None, xhtml = None):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return 1
|
||||||
if msg and not xhtml and gajim.config.get('rst_formatting_outgoing_messages'):
|
if msg and not xhtml and gajim.config.get('rst_formatting_outgoing_messages'):
|
||||||
xhtml = create_xhtml(msg)
|
xhtml = create_xhtml(msg)
|
||||||
if not msg and chatstate is None:
|
if not msg and chatstate is None:
|
||||||
return
|
return 2
|
||||||
fjid = jid
|
fjid = jid
|
||||||
if resource:
|
if resource:
|
||||||
fjid += '/' + resource
|
fjid += '/' + resource
|
||||||
|
@ -699,14 +699,19 @@ class Connection(ConnectionHandlers):
|
||||||
msgenc = ''
|
msgenc = ''
|
||||||
if keyID and USE_GPG:
|
if keyID and USE_GPG:
|
||||||
#encrypt
|
#encrypt
|
||||||
msgenc = self.gpg.encrypt(msg, [keyID])
|
msgenc, error = self.gpg.encrypt(msg, [keyID])
|
||||||
if msgenc:
|
if msgenc and not error:
|
||||||
msgtxt = '[This message is encrypted]'
|
msgtxt = '[This message is encrypted]'
|
||||||
lang = os.getenv('LANG')
|
lang = os.getenv('LANG')
|
||||||
if lang is not None and lang != 'en': # we're not english
|
if lang is not None and lang != 'en': # we're not english
|
||||||
# one in locale and one en
|
# one in locale and one en
|
||||||
msgtxt = _('[This message is *encrypted* (See :JEP:`27`]') +\
|
msgtxt = _('[This message is *encrypted* (See :JEP:`27`]') +\
|
||||||
' ([This message is *encrypted* (See :JEP:`27`])'
|
' ([This message is *encrypted* (See :JEP:`27`])'
|
||||||
|
else:
|
||||||
|
# Encryption failed, do not send message
|
||||||
|
tim = time.localtime()
|
||||||
|
self.dispatch('MSGNOTSENT', (jid, error, msgtxt, tim))
|
||||||
|
return 3
|
||||||
if msgtxt and not xhtml and gajim.config.get(
|
if msgtxt and not xhtml and gajim.config.get(
|
||||||
'rst_formatting_outgoing_messages'):
|
'rst_formatting_outgoing_messages'):
|
||||||
# Generate a XHTML part using reStructured text markup
|
# Generate a XHTML part using reStructured text markup
|
||||||
|
|
|
@ -711,6 +711,12 @@ class Interface:
|
||||||
if msg and gajim.config.get_per('soundevents', 'message_sent', 'enabled'):
|
if msg and gajim.config.get_per('soundevents', 'message_sent', 'enabled'):
|
||||||
helpers.play_sound('message_sent')
|
helpers.play_sound('message_sent')
|
||||||
|
|
||||||
|
def handle_event_msgnotsent(self, account, array):
|
||||||
|
#('MSGNOTSENT', account, (jid, ierror_msg, msg, time))
|
||||||
|
msg = _('error while sending %s ( %s )') % (array[2], array[1])
|
||||||
|
self.roster.on_message(array[0], msg, array[3], account,
|
||||||
|
msg_type='error')
|
||||||
|
|
||||||
def handle_event_subscribe(self, account, array):
|
def handle_event_subscribe(self, account, array):
|
||||||
#('SUBSCRIBE', account, (jid, text, user_nick)) user_nick is JEP-0172
|
#('SUBSCRIBE', account, (jid, text, user_nick)) user_nick is JEP-0172
|
||||||
dialogs.SubscriptionRequestWindow(array[0], array[1], account, array[2])
|
dialogs.SubscriptionRequestWindow(array[0], array[1], account, array[2])
|
||||||
|
@ -1780,6 +1786,7 @@ class Interface:
|
||||||
'MSG': self.handle_event_msg,
|
'MSG': self.handle_event_msg,
|
||||||
'MSGERROR': self.handle_event_msgerror,
|
'MSGERROR': self.handle_event_msgerror,
|
||||||
'MSGSENT': self.handle_event_msgsent,
|
'MSGSENT': self.handle_event_msgsent,
|
||||||
|
'MSGNOTSENT': self.handle_event_msgnotsent,
|
||||||
'SUBSCRIBED': self.handle_event_subscribed,
|
'SUBSCRIBED': self.handle_event_subscribed,
|
||||||
'UNSUBSCRIBED': self.handle_event_unsubscribed,
|
'UNSUBSCRIBED': self.handle_event_unsubscribed,
|
||||||
'SUBSCRIBE': self.handle_event_subscribe,
|
'SUBSCRIBE': self.handle_event_subscribe,
|
||||||
|
|
|
@ -117,10 +117,11 @@ class MessageControl:
|
||||||
def send_message(self, message, keyID = '', type = 'chat',
|
def send_message(self, message, keyID = '', type = 'chat',
|
||||||
chatstate = None, msg_id = None, composing_jep = None, resource = None,
|
chatstate = None, msg_id = None, composing_jep = None, resource = None,
|
||||||
user_nick = None):
|
user_nick = None):
|
||||||
'''Send the given message to the active tab'''
|
'''Send the given message to the active tab. Doesn't return None if error
|
||||||
|
'''
|
||||||
jid = self.contact.jid
|
jid = self.contact.jid
|
||||||
# Send and update history
|
# Send and update history
|
||||||
gajim.connections[self.account].send_message(jid, message, keyID,
|
return gajim.connections[self.account].send_message(jid, message, keyID,
|
||||||
type = type, chatstate = chatstate, msg_id = msg_id,
|
type = type, chatstate = chatstate, msg_id = msg_id,
|
||||||
composing_jep = composing_jep, resource = self.resource,
|
composing_jep = composing_jep, resource = self.resource,
|
||||||
user_nick = user_nick)
|
user_nick = user_nick)
|
||||||
|
|
Loading…
Reference in New Issue