diff --git a/src/chat_control.py b/src/chat_control.py
index 66a80fedeab7ea882da8c60e40cc33fa717ce726..da8472b323ea0ccfbeb90ddb0882cbbac59b0faf 100644
--- a/src/chat_control.py
+++ b/src/chat_control.py
@@ -919,10 +919,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
             self.received_history_pos = pos
 
     def print_conversation_line(self, text, kind, name, tim,
-                    other_tags_for_name=[], other_tags_for_time=[],
-                    other_tags_for_text=[], count_as_new=True, subject=None,
-                    old_kind=None, xhtml=None, simple=False, xep0184_id=None,
-                    graphics=True, displaymarking=None):
+    other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
+    count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
+    xep0184_id=None, graphics=True, displaymarking=None, msg_id=None):
         """
         Print 'chat' type messages
         """
@@ -933,9 +932,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
         if self.was_at_the_end or kind == 'outgoing':
             end = True
         textview.print_conversation_line(text, jid, kind, name, tim,
-                other_tags_for_name, other_tags_for_time, other_tags_for_text,
-                subject, old_kind, xhtml, simple=simple, graphics=graphics,
-                displaymarking=displaymarking)
+            other_tags_for_name, other_tags_for_time, other_tags_for_text,
+            subject, old_kind, xhtml, simple=simple, graphics=graphics,
+            displaymarking=displaymarking)
 
         if xep0184_id is not None:
             textview.show_xep0184_warning(xep0184_id)
@@ -978,18 +977,18 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
                     type_ = 'printed_' + self.type_id
                     event = 'message_received'
                 show_in_roster = notify.get_show_in_roster(event,
-                        self.account, self.contact, self.session)
+                    self.account, self.contact, self.session)
                 show_in_systray = notify.get_show_in_systray(event,
-                        self.account, self.contact, type_)
+                    self.account, self.contact, type_)
 
-                event = gajim.events.create_event(type_, (self,),
+                event = gajim.events.create_event(type_, (self, msg_id),
                     show_in_roster=show_in_roster,
                     show_in_systray=show_in_systray)
                 gajim.events.add_event(self.account, full_jid, event)
                 # We need to redraw contact if we show in roster
                 if show_in_roster:
                     gajim.interface.roster.draw_contact(self.contact.jid,
-                            self.account)
+                        self.account)
 
         if not self.parent_win:
             return
@@ -2425,8 +2424,8 @@ class ChatControl(ChatControlBase):
         return gajim.nicks[self.account]
 
     def print_conversation(self, text, frm='', tim=None, encrypted=False,
-                    subject=None, xhtml=None, simple=False, xep0184_id=None,
-                    displaymarking=None):
+    subject=None, xhtml=None, simple=False, xep0184_id=None,
+    displaymarking=None, msg_id=None):
         """
         Print a line in the conversation
 
@@ -2457,21 +2456,22 @@ class ChatControl(ChatControlBase):
                 # ESessions
                 if not encrypted:
                     msg = _('The following message was NOT encrypted')
-                    ChatControlBase.print_conversation_line(self, msg, 'status', '',
-                            tim)
+                    ChatControlBase.print_conversation_line(self, msg, 'status',
+                        '',  tim)
             else:
                 # GPG encryption
                 if encrypted and not self.gpg_is_active:
                     msg = _('The following message was encrypted')
-                    ChatControlBase.print_conversation_line(self, msg, 'status', '',
-                            tim)
-                    # turn on OpenPGP if this was in fact a XEP-0027 encrypted message
+                    ChatControlBase.print_conversation_line(self, msg, 'status',
+                        '', tim)
+                    # turn on OpenPGP if this was in fact a XEP-0027 encrypted
+                    # message
                     if encrypted == 'xep27':
                         self._toggle_gpg()
                 elif not encrypted and self.gpg_is_active:
                     msg = _('The following message was NOT encrypted')
-                    ChatControlBase.print_conversation_line(self, msg, 'status', '',
-                            tim)
+                    ChatControlBase.print_conversation_line(self, msg, 'status',
+                        '', tim)
             if not frm:
                 kind = 'incoming'
                 name = contact.get_shown_name()
@@ -2488,8 +2488,9 @@ class ChatControl(ChatControlBase):
                     if xhtml:
                         xhtml = '<body xmlns="%s">%s</body>' % (NS_XHTML, xhtml)
         ChatControlBase.print_conversation_line(self, text, kind, name, tim,
-                subject=subject, old_kind=self.old_msg_kind, xhtml=xhtml,
-                simple=simple, xep0184_id=xep0184_id, displaymarking=displaymarking)
+            subject=subject, old_kind=self.old_msg_kind, xhtml=xhtml,
+            simple=simple, xep0184_id=xep0184_id, displaymarking=displaymarking,
+            msg_id=msg_id)
         if text.startswith('/me ') or text.startswith('/me\n'):
             self.old_msg_kind = None
         else:
diff --git a/src/roster_window.py b/src/roster_window.py
index df6d06d3348631fd20642f6ff9418cf4d725ca6d..b238460182ca16d862cc9502ef201ed4e0e65752 100644
--- a/src/roster_window.py
+++ b/src/roster_window.py
@@ -1889,6 +1889,18 @@ class RosterWindow:
         Only performed if removal was requested before but the contact still had
         pending events
         """
+
+        msg_ids = []
+        for ev in event_list:
+            if ev.type_ != 'printed_chat':
+                continue
+            if len(ev.parameters) > 1 and ev.parameters[1]:
+                # There is a msg_id
+                msg_ids.append(ev.parameters[1])
+
+        if msg_ids:
+            gajim.logger.set_read_messages(msg_ids)
+
         contact_list = ((event.jid.split('/')[0], event.account) for event in \
                 event_list)
 
@@ -2632,9 +2644,14 @@ class RosterWindow:
 
             obj.session.control.print_conversation(obj.msgtxt, typ,
                 tim=obj.timestamp, encrypted=obj.encrypted, subject=obj.subject,
-                xhtml=obj.xhtml, displaymarking=obj.displaymarking)
+                xhtml=obj.xhtml, displaymarking=obj.displaymarking,
+                msg_id=obj.msg_id)
             if obj.msg_id:
-                gajim.logger.set_read_messages([obj.msg_id])
+                pw = obj.session.control.parent_win
+                end = obj.session.control.was_at_the_end
+                if not pw or (pw.get_active_control() and obj.session.control \
+                == pw.get_active_control() and pw.is_active() and end):
+                    gajim.logger.set_read_messages([obj.msg_id])
         elif obj.popup:
             contact = gajim.contacts.get_contact(obj.conn.name, obj.jid)
             obj.session.control = gajim.interface.new_chat(contact,