@@ -889,9 +889,10 @@ def message_route(self, cr, uid, message, message_dict, model=None, thread_id=No
889
889
thread_references = references or in_reply_to
890
890
891
891
# 1. message is a reply to an existing message (exact match of message_id)
892
+ ref_match = thread_references and tools .reference_re .search (thread_references )
892
893
msg_references = thread_references .split ()
893
894
mail_message_ids = mail_msg_obj .search (cr , uid , [('message_id' , 'in' , msg_references )], context = context )
894
- if mail_message_ids :
895
+ if ref_match and mail_message_ids :
895
896
original_msg = mail_msg_obj .browse (cr , SUPERUSER_ID , mail_message_ids [0 ], context = context )
896
897
model , thread_id = original_msg .model , original_msg .res_id
897
898
route = self .message_route_verify (
@@ -905,7 +906,6 @@ def message_route(self, cr, uid, message, message_dict, model=None, thread_id=No
905
906
return [route ]
906
907
907
908
# 2. message is a reply to an existign thread (6.1 compatibility)
908
- ref_match = thread_references and tools .reference_re .search (thread_references )
909
909
if ref_match :
910
910
reply_thread_id = int (ref_match .group (1 ))
911
911
reply_model = ref_match .group (2 ) or fallback_model
@@ -945,8 +945,9 @@ def message_route(self, cr, uid, message, message_dict, model=None, thread_id=No
945
945
(mail_message .model , mail_message .res_id , custom_values , uid , None ),
946
946
update_author = True , assert_model = True , create_fallback = True , allow_private = True , context = context )
947
947
if route :
948
- _logger .info ('Routing mail from %s to %s with Message-Id %s: direct reply to a private message: %s, custom_values: %s, uid: %s' ,
949
- email_from , email_to , message_id , mail_message .id , custom_values , uid )
948
+ _logger .info (
949
+ 'Routing mail from %s to %s with Message-Id %s: direct reply to a private message: %s, custom_values: %s, uid: %s' ,
950
+ email_from , email_to , message_id , mail_message .id , custom_values , uid )
950
951
return [route ]
951
952
952
953
# 3. Look for a matching mail.alias entry
@@ -975,11 +976,12 @@ def message_route(self, cr, uid, message, message_dict, model=None, thread_id=No
975
976
user_id = uid
976
977
_logger .info ('No matching user_id for the alias %s' , alias .alias_name )
977
978
route = (alias .alias_model_id .model , alias .alias_force_thread_id , eval (alias .alias_defaults ), user_id , alias )
978
- _logger .info ('Routing mail from %s to %s with Message-Id %s: direct alias match: %r' ,
979
- email_from , email_to , message_id , route )
980
979
route = self .message_route_verify (cr , uid , message , message_dict , route ,
981
980
update_author = True , assert_model = True , create_fallback = True , context = context )
982
981
if route :
982
+ _logger .info (
983
+ 'Routing mail from %s to %s with Message-Id %s: direct alias match: %r' ,
984
+ email_from , email_to , message_id , route )
983
985
routes .append (route )
984
986
return routes
985
987
@@ -993,15 +995,16 @@ def message_route(self, cr, uid, message, message_dict, model=None, thread_id=No
993
995
thread_id = int (thread_id )
994
996
except :
995
997
thread_id = False
996
- _logger .info ('Routing mail from %s to %s with Message-Id %s: fallback to model:%s, thread_id:%s, custom_values:%s, uid:%s' ,
997
- email_from , email_to , message_id , fallback_model , thread_id , custom_values , uid )
998
998
route = self .message_route_verify (cr , uid , message , message_dict ,
999
999
(fallback_model , thread_id , custom_values , uid , None ),
1000
1000
update_author = True , assert_model = True , context = context )
1001
1001
if route :
1002
+ _logger .info (
1003
+ 'Routing mail from %s to %s with Message-Id %s: fallback to model:%s, thread_id:%s, custom_values:%s, uid:%s' ,
1004
+ email_from , email_to , message_id , fallback_model , thread_id , custom_values , uid )
1002
1005
return [route ]
1003
1006
1004
- # AssertionError if no routes found and if no bounce occured
1007
+ # ValueError if no routes found and if no bounce occured
1005
1008
raise ValueError (
1006
1009
'No possible route found for incoming message from %s to %s (Message-Id %s:). '
1007
1010
'Create an appropriate mail.alias or force the destination model.' %
@@ -1171,7 +1174,14 @@ def _message_extract_payload(self, message, save_original=False):
1171
1174
body = u''
1172
1175
if save_original :
1173
1176
attachments .append (('original_email.eml' , message .as_string ()))
1174
- if not message .is_multipart () or 'text/' in message .get ('content-type' , '' ):
1177
+
1178
+ # Be careful, content-type may contain tricky content like in the
1179
+ # following example so test the MIME type with startswith()
1180
+ #
1181
+ # Content-Type: multipart/related;
1182
+ # boundary="_004_3f1e4da175f349248b8d43cdeb9866f1AMSPR06MB343eurprd06pro_";
1183
+ # type="text/html"
1184
+ if not message .is_multipart () or message .get ('content-type' , '' ).startswith ("text/" ):
1175
1185
encoding = message .get_content_charset ()
1176
1186
body = message .get_payload (decode = True )
1177
1187
body = tools .ustr (body , encoding , errors = 'replace' )
0 commit comments