MessageParser.java

  1package eu.siacs.conversations.parser;
  2
  3import net.java.otr4j.session.Session;
  4import net.java.otr4j.session.SessionStatus;
  5
  6import eu.siacs.conversations.entities.Account;
  7import eu.siacs.conversations.entities.Contact;
  8import eu.siacs.conversations.entities.Conversation;
  9import eu.siacs.conversations.entities.Message;
 10import eu.siacs.conversations.entities.MucOptions;
 11import eu.siacs.conversations.http.HttpConnectionManager;
 12import eu.siacs.conversations.services.MessageArchiveService;
 13import eu.siacs.conversations.services.XmppConnectionService;
 14import eu.siacs.conversations.utils.CryptoHelper;
 15import eu.siacs.conversations.xml.Element;
 16import eu.siacs.conversations.xmpp.OnMessagePacketReceived;
 17import eu.siacs.conversations.xmpp.chatstate.ChatState;
 18import eu.siacs.conversations.xmpp.jid.Jid;
 19import eu.siacs.conversations.xmpp.pep.Avatar;
 20import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
 21
 22public class MessageParser extends AbstractParser implements
 23		OnMessagePacketReceived {
 24	public MessageParser(XmppConnectionService service) {
 25		super(service);
 26	}
 27
 28	private boolean extractChatState(Conversation conversation, final Element element) {
 29		ChatState state = ChatState.parse(element);
 30		if (state != null && conversation != null) {
 31			final Account account = conversation.getAccount();
 32			Jid from = element.getAttributeAsJid("from");
 33			if (from != null && from.toBareJid().equals(account.getJid().toBareJid())) {
 34				conversation.setOutgoingChatState(state);
 35				return false;
 36			} else {
 37				return conversation.setIncomingChatState(state);
 38			}
 39		}
 40		return false;
 41	}
 42
 43	private Message parseChat(MessagePacket packet, Account account) {
 44		final Jid jid = packet.getFrom();
 45		if (jid == null) {
 46			return null;
 47		}
 48		Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid.toBareJid(), false);
 49		String pgpBody = getPgpBody(packet);
 50		Message finishedMessage;
 51		if (pgpBody != null) {
 52			finishedMessage = new Message(conversation,
 53					pgpBody, Message.ENCRYPTION_PGP, Message.STATUS_RECEIVED);
 54		} else {
 55			finishedMessage = new Message(conversation,
 56					packet.getBody(), Message.ENCRYPTION_NONE,
 57					Message.STATUS_RECEIVED);
 58		}
 59		finishedMessage.setRemoteMsgId(packet.getId());
 60		finishedMessage.markable = isMarkable(packet);
 61		if (conversation.getMode() == Conversation.MODE_MULTI
 62				&& !jid.isBareJid()) {
 63			final Jid trueCounterpart = conversation.getMucOptions()
 64					.getTrueCounterpart(jid.getResourcepart());
 65			if (trueCounterpart != null) {
 66				updateLastseen(packet, account, trueCounterpart, false);
 67			}
 68			finishedMessage.setType(Message.TYPE_PRIVATE);
 69			finishedMessage.setTrueCounterpart(trueCounterpart);
 70			if (conversation.hasDuplicateMessage(finishedMessage)) {
 71				return null;
 72			}
 73		} else {
 74			updateLastseen(packet, account, true);
 75		}
 76		finishedMessage.setCounterpart(jid);
 77		finishedMessage.setTime(getTimestamp(packet));
 78		extractChatState(conversation,packet);
 79		return finishedMessage;
 80	}
 81
 82	private Message parseOtrChat(MessagePacket packet, Account account) {
 83		final Jid to = packet.getTo();
 84		final Jid from = packet.getFrom();
 85		if (to == null || from == null) {
 86			return null;
 87		}
 88		boolean properlyAddressed = !to.isBareJid() || account.countPresences() == 1;
 89		Conversation conversation = mXmppConnectionService
 90				.findOrCreateConversation(account, from.toBareJid(), false);
 91		String presence;
 92		if (from.isBareJid()) {
 93			presence = "";
 94		} else {
 95			presence = from.getResourcepart();
 96		}
 97		updateLastseen(packet, account, true);
 98		String body = packet.getBody();
 99		if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) {
100			conversation.endOtrIfNeeded();
101		}
102		if (!conversation.hasValidOtrSession()) {
103			if (properlyAddressed) {
104				conversation.startOtrSession(presence,false);
105			} else {
106				return null;
107			}
108		} else {
109			String foreignPresence = conversation.getOtrSession()
110					.getSessionID().getUserID();
111			if (!foreignPresence.equals(presence)) {
112				conversation.endOtrIfNeeded();
113				if (properlyAddressed) {
114					conversation.startOtrSession(presence, false);
115				} else {
116					return null;
117				}
118			}
119		}
120		try {
121			Session otrSession = conversation.getOtrSession();
122			SessionStatus before = otrSession.getSessionStatus();
123			body = otrSession.transformReceiving(body);
124			SessionStatus after = otrSession.getSessionStatus();
125			if ((before != after) && (after == SessionStatus.ENCRYPTED)) {
126				conversation.setNextEncryption(Message.ENCRYPTION_OTR);
127				mXmppConnectionService.onOtrSessionEstablished(conversation);
128			} else if ((before != after) && (after == SessionStatus.FINISHED)) {
129				conversation.setNextEncryption(Message.ENCRYPTION_NONE);
130				conversation.resetOtrSession();
131				mXmppConnectionService.updateConversationUi();
132			}
133			if ((body == null) || (body.isEmpty())) {
134				return null;
135			}
136			if (body.startsWith(CryptoHelper.FILETRANSFER)) {
137				String key = body.substring(CryptoHelper.FILETRANSFER.length());
138				conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
139				return null;
140			}
141			Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR,
142					Message.STATUS_RECEIVED);
143			finishedMessage.setTime(getTimestamp(packet));
144			finishedMessage.setRemoteMsgId(packet.getId());
145			finishedMessage.markable = isMarkable(packet);
146			finishedMessage.setCounterpart(from);
147			extractChatState(conversation, packet);
148			return finishedMessage;
149		} catch (Exception e) {
150			conversation.resetOtrSession();
151			return null;
152		}
153	}
154
155	private Message parseGroupchat(MessagePacket packet, Account account) {
156		int status;
157		final Jid from = packet.getFrom();
158		if (from == null) {
159			return null;
160		}
161		if (mXmppConnectionService.find(account.pendingConferenceLeaves,
162				account, from.toBareJid()) != null) {
163			return null;
164		}
165		Conversation conversation = mXmppConnectionService
166				.findOrCreateConversation(account, from.toBareJid(), true);
167		final Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(from.getResourcepart());
168		if (trueCounterpart != null) {
169			updateLastseen(packet, account, trueCounterpart, false);
170		}
171		if (packet.hasChild("subject")) {
172			conversation.setHasMessagesLeftOnServer(true);
173			conversation.getMucOptions().setSubject(packet.findChild("subject").getContent());
174			mXmppConnectionService.updateConversationUi();
175			return null;
176		}
177
178		final Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user");
179		if (from.isBareJid() && (x == null || !x.hasChild("status"))) {
180			return null;
181		} else if (from.isBareJid() && x.hasChild("status")) {
182			for(Element child : x.getChildren()) {
183				if (child.getName().equals("status")) {
184					String code = child.getAttribute("code");
185					if (code.contains(MucOptions.STATUS_CODE_ROOM_CONFIG_CHANGED)) {
186						mXmppConnectionService.fetchConferenceConfiguration(conversation);
187					}
188				}
189			}
190			return null;
191		}
192
193		if (from.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
194			if (mXmppConnectionService.markMessage(conversation,
195					packet.getId(), Message.STATUS_SEND_RECEIVED)) {
196				return null;
197			} else if (packet.getId() == null) {
198				Message message = conversation.findSentMessageWithBody(packet.getBody());
199				if (message != null) {
200					mXmppConnectionService.markMessage(message,Message.STATUS_SEND_RECEIVED);
201					return null;
202				} else {
203					status = Message.STATUS_SEND;
204				}
205			} else {
206				status = Message.STATUS_SEND;
207			}
208		} else {
209			status = Message.STATUS_RECEIVED;
210		}
211		String pgpBody = getPgpBody(packet);
212		Message finishedMessage;
213		if (pgpBody == null) {
214			finishedMessage = new Message(conversation,
215					packet.getBody(), Message.ENCRYPTION_NONE, status);
216		} else {
217			finishedMessage = new Message(conversation, pgpBody,
218					Message.ENCRYPTION_PGP, status);
219		}
220		finishedMessage.setRemoteMsgId(packet.getId());
221		finishedMessage.markable = isMarkable(packet);
222		finishedMessage.setCounterpart(from);
223		if (status == Message.STATUS_RECEIVED) {
224			finishedMessage.setTrueCounterpart(conversation.getMucOptions()
225					.getTrueCounterpart(from.getResourcepart()));
226		}
227		if (packet.hasChild("delay")
228				&& conversation.hasDuplicateMessage(finishedMessage)) {
229			return null;
230		}
231		finishedMessage.setTime(getTimestamp(packet));
232		return finishedMessage;
233	}
234
235	private Message parseCarbonMessage(final MessagePacket packet, final Account account) {
236		int status;
237		final Jid fullJid;
238		Element forwarded;
239		if (packet.hasChild("received", "urn:xmpp:carbons:2")) {
240			forwarded = packet.findChild("received", "urn:xmpp:carbons:2")
241					.findChild("forwarded", "urn:xmpp:forward:0");
242			status = Message.STATUS_RECEIVED;
243		} else if (packet.hasChild("sent", "urn:xmpp:carbons:2")) {
244			forwarded = packet.findChild("sent", "urn:xmpp:carbons:2")
245					.findChild("forwarded", "urn:xmpp:forward:0");
246			status = Message.STATUS_SEND;
247		} else {
248			return null;
249		}
250		if (forwarded == null) {
251			return null;
252		}
253		Element message = forwarded.findChild("message");
254		if (message == null) {
255			return null;
256		}
257		if (!message.hasChild("body")) {
258			if (status == Message.STATUS_RECEIVED
259					&& message.getAttribute("from") != null) {
260				parseNonMessage(message, account);
261			} else if (status == Message.STATUS_SEND
262					&& message.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
263				final Jid to = message.getAttributeAsJid("to");
264				if (to != null) {
265					final Conversation conversation = mXmppConnectionService.find(
266							mXmppConnectionService.getConversations(), account,
267							to.toBareJid());
268					if (conversation != null) {
269						mXmppConnectionService.markRead(conversation);
270					}
271				}
272			}
273			return null;
274		}
275		if (status == Message.STATUS_RECEIVED) {
276			fullJid = message.getAttributeAsJid("from");
277			if (fullJid == null) {
278				return null;
279			} else {
280				updateLastseen(message, account, true);
281			}
282		} else {
283			fullJid = message.getAttributeAsJid("to");
284			if (fullJid == null) {
285				return null;
286			}
287		}
288		if (message.hasChild("x","http://jabber.org/protocol/muc#user")
289				&& "chat".equals(message.getAttribute("type"))) {
290			return null;
291		}
292		Conversation conversation = mXmppConnectionService
293				.findOrCreateConversation(account, fullJid.toBareJid(), false);
294		String pgpBody = getPgpBody(message);
295		Message finishedMessage;
296		if (pgpBody != null) {
297			finishedMessage = new Message(conversation, pgpBody,
298					Message.ENCRYPTION_PGP, status);
299		} else {
300			String body = message.findChild("body").getContent();
301			finishedMessage = new Message(conversation, body,
302					Message.ENCRYPTION_NONE, status);
303		}
304		extractChatState(conversation,message);
305		finishedMessage.setTime(getTimestamp(message));
306		finishedMessage.setRemoteMsgId(message.getAttribute("id"));
307		finishedMessage.markable = isMarkable(message);
308		finishedMessage.setCounterpart(fullJid);
309		if (conversation.getMode() == Conversation.MODE_MULTI
310				&& !fullJid.isBareJid()) {
311			finishedMessage.setType(Message.TYPE_PRIVATE);
312			finishedMessage.setTrueCounterpart(conversation.getMucOptions()
313					.getTrueCounterpart(fullJid.getResourcepart()));
314			if (conversation.hasDuplicateMessage(finishedMessage)) {
315				return null;
316			}
317		}
318		return finishedMessage;
319	}
320
321	private Message parseMamMessage(MessagePacket packet, final Account account) {
322		final Element result = packet.findChild("result","urn:xmpp:mam:0");
323		if (result == null ) {
324			return null;
325		}
326		final MessageArchiveService.Query query = this.mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid"));
327		if (query!=null) {
328			query.incrementTotalCount();
329		}
330		final Element forwarded = result.findChild("forwarded","urn:xmpp:forward:0");
331		if (forwarded == null) {
332			return null;
333		}
334		final Element message = forwarded.findChild("message");
335		if (message == null) {
336			return null;
337		}
338		final Element body = message.findChild("body");
339		if (body == null || message.hasChild("private","urn:xmpp:carbons:2") || message.hasChild("no-copy","urn:xmpp:hints")) {
340			return null;
341		}
342		int encryption;
343		String content = getPgpBody(message);
344		if (content != null) {
345			encryption = Message.ENCRYPTION_PGP;
346		} else {
347			encryption = Message.ENCRYPTION_NONE;
348			content = body.getContent();
349		}
350		if (content == null) {
351			return null;
352		}
353		final long timestamp = getTimestamp(forwarded);
354		final Jid to = message.getAttributeAsJid("to");
355		final Jid from = message.getAttributeAsJid("from");
356		Jid counterpart;
357		int status;
358		Conversation conversation;
359		if (from!=null && to != null && from.toBareJid().equals(account.getJid().toBareJid())) {
360			status = Message.STATUS_SEND;
361			conversation = this.mXmppConnectionService.findOrCreateConversation(account,to.toBareJid(),false,query);
362			counterpart = to;
363		} else if (from !=null && to != null) {
364			status = Message.STATUS_RECEIVED;
365			conversation = this.mXmppConnectionService.findOrCreateConversation(account,from.toBareJid(),false,query);
366			counterpart = from;
367		} else {
368			return null;
369		}
370		Message finishedMessage = new Message(conversation,content,encryption,status);
371		finishedMessage.setTime(timestamp);
372		finishedMessage.setCounterpart(counterpart);
373		finishedMessage.setRemoteMsgId(message.getAttribute("id"));
374		finishedMessage.setServerMsgId(result.getAttribute("id"));
375		if (conversation.hasDuplicateMessage(finishedMessage)) {
376			return null;
377		}
378		if (query!=null) {
379			query.incrementMessageCount();
380		}
381		return finishedMessage;
382	}
383
384	private void parseError(final MessagePacket packet, final Account account) {
385		final Jid from = packet.getFrom();
386		mXmppConnectionService.markMessage(account, from.toBareJid(),
387				packet.getId(), Message.STATUS_SEND_FAILED);
388	}
389
390	private void parseNonMessage(Element packet, Account account) {
391		final Jid from = packet.getAttributeAsJid("from");
392		if (extractChatState(from == null ? null : mXmppConnectionService.find(account,from), packet)) {
393			mXmppConnectionService.updateConversationUi();
394		}
395		Element invite = extractInvite(packet);
396		if (invite != null) {
397			Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, from, true);
398			if (!conversation.getMucOptions().online()) {
399				Element password = invite.findChild("password");
400				conversation.getMucOptions().setPassword(password == null ? null : password.getContent());
401				mXmppConnectionService.databaseBackend.updateConversation(conversation);
402				mXmppConnectionService.joinMuc(conversation);
403				mXmppConnectionService.updateConversationUi();
404			}
405		}
406		if (packet.hasChild("event", "http://jabber.org/protocol/pubsub#event")) {
407			Element event = packet.findChild("event",
408					"http://jabber.org/protocol/pubsub#event");
409			parseEvent(event, from, account);
410		} else if (from != null && packet.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
411			String id = packet
412					.findChild("displayed", "urn:xmpp:chat-markers:0")
413					.getAttribute("id");
414			updateLastseen(packet, account, true);
415			final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), id, Message.STATUS_SEND_DISPLAYED);
416			Message message = displayedMessage == null ? null :displayedMessage.prev();
417			while (message != null
418					&& message.getStatus() == Message.STATUS_SEND_RECEIVED
419					&& message.getTimeSent() < displayedMessage.getTimeSent()) {
420				mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED);
421				message = message.prev();
422			}
423		} else if (from != null
424				&& packet.hasChild("received", "urn:xmpp:chat-markers:0")) {
425			String id = packet.findChild("received", "urn:xmpp:chat-markers:0")
426					.getAttribute("id");
427			updateLastseen(packet, account, false);
428			mXmppConnectionService.markMessage(account, from.toBareJid(),
429					id, Message.STATUS_SEND_RECEIVED);
430		} else if (from != null
431				&& packet.hasChild("received", "urn:xmpp:receipts")) {
432			String id = packet.findChild("received", "urn:xmpp:receipts")
433					.getAttribute("id");
434			updateLastseen(packet, account, false);
435			mXmppConnectionService.markMessage(account, from.toBareJid(),
436					id, Message.STATUS_SEND_RECEIVED);
437		}
438	}
439
440	private Element extractInvite(Element message) {
441		Element x = message.findChild("x","http://jabber.org/protocol/muc#user");
442		if (x == null) {
443			x = message.findChild("x","jabber:x:conference");
444		}
445		if (x != null && x.hasChild("invite")) {
446			return x;
447		} else {
448			return null;
449		}
450	}
451
452	private void parseEvent(final Element event, final Jid from, final Account account) {
453		Element items = event.findChild("items");
454		if (items == null) {
455			return;
456		}
457		String node = items.getAttribute("node");
458		if (node == null) {
459			return;
460		}
461		if (node.equals("urn:xmpp:avatar:metadata")) {
462			Avatar avatar = Avatar.parseMetadata(items);
463			if (avatar != null) {
464				avatar.owner = from;
465				if (mXmppConnectionService.getFileBackend().isAvatarCached(
466						avatar)) {
467					if (account.getJid().toBareJid().equals(from)) {
468						if (account.setAvatar(avatar.getFilename())) {
469							mXmppConnectionService.databaseBackend
470									.updateAccount(account);
471						}
472						mXmppConnectionService.getAvatarService().clear(
473								account);
474						mXmppConnectionService.updateConversationUi();
475						mXmppConnectionService.updateAccountUi();
476					} else {
477						Contact contact = account.getRoster().getContact(
478								from);
479						contact.setAvatar(avatar.getFilename());
480						mXmppConnectionService.getAvatarService().clear(
481								contact);
482						mXmppConnectionService.updateConversationUi();
483						mXmppConnectionService.updateRosterUi();
484					}
485				} else {
486					mXmppConnectionService.fetchAvatar(account, avatar);
487				}
488			}
489		} else if (node.equals("http://jabber.org/protocol/nick")) {
490			Element item = items.findChild("item");
491			if (item != null) {
492				Element nick = item.findChild("nick",
493						"http://jabber.org/protocol/nick");
494				if (nick != null) {
495					if (from != null) {
496						Contact contact = account.getRoster().getContact(
497								from);
498						contact.setPresenceName(nick.getContent());
499						mXmppConnectionService.getAvatarService().clear(account);
500						mXmppConnectionService.updateConversationUi();
501						mXmppConnectionService.updateAccountUi();
502					}
503				}
504			}
505		}
506	}
507
508	private String getPgpBody(Element message) {
509		Element child = message.findChild("x", "jabber:x:encrypted");
510		if (child == null) {
511			return null;
512		} else {
513			return child.getContent();
514		}
515	}
516
517	private boolean isMarkable(Element message) {
518		return message.hasChild("markable", "urn:xmpp:chat-markers:0");
519	}
520
521	@Override
522	public void onMessagePacketReceived(Account account, MessagePacket packet) {
523		Message message = null;
524		this.parseNick(packet, account);
525		if ((packet.getType() == MessagePacket.TYPE_CHAT || packet.getType() == MessagePacket.TYPE_NORMAL)) {
526			if ((packet.getBody() != null)
527					&& (packet.getBody().startsWith("?OTR"))) {
528				message = this.parseOtrChat(packet, account);
529				if (message != null) {
530					message.markUnread();
531				}
532			} else if (packet.hasChild("body") && extractInvite(packet) == null) {
533				message = this.parseChat(packet, account);
534				if (message != null) {
535					message.markUnread();
536				}
537			} else if (packet.hasChild("received", "urn:xmpp:carbons:2")
538					|| (packet.hasChild("sent", "urn:xmpp:carbons:2"))) {
539				message = this.parseCarbonMessage(packet, account);
540				if (message != null) {
541					if (message.getStatus() == Message.STATUS_SEND) {
542						account.activateGracePeriod();
543						mXmppConnectionService.markRead(message.getConversation());
544					} else {
545						message.markUnread();
546					}
547				}
548			} else if (packet.hasChild("result","urn:xmpp:mam:0")) {
549				message = parseMamMessage(packet, account);
550				if (message != null) {
551					Conversation conversation = message.getConversation();
552					conversation.add(message);
553					mXmppConnectionService.databaseBackend.createMessage(message);
554				}
555				return;
556			} else if (packet.hasChild("fin","urn:xmpp:mam:0")) {
557				Element fin = packet.findChild("fin","urn:xmpp:mam:0");
558				mXmppConnectionService.getMessageArchiveService().processFin(fin);
559			} else {
560				parseNonMessage(packet, account);
561			}
562		} else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) {
563			message = this.parseGroupchat(packet, account);
564			if (message != null) {
565				if (message.getStatus() == Message.STATUS_RECEIVED) {
566					message.markUnread();
567				} else {
568					mXmppConnectionService.markRead(message.getConversation());
569					account.activateGracePeriod();
570				}
571			}
572		} else if (packet.getType() == MessagePacket.TYPE_ERROR) {
573			this.parseError(packet, account);
574			return;
575		} else if (packet.getType() == MessagePacket.TYPE_HEADLINE) {
576			this.parseHeadline(packet, account);
577			return;
578		}
579		if ((message == null) || (message.getBody() == null)) {
580			return;
581		}
582		if ((mXmppConnectionService.confirmMessages())
583				&& ((packet.getId() != null))) {
584			if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) {
585				MessagePacket receipt = mXmppConnectionService
586						.getMessageGenerator().received(account, packet,
587								"urn:xmpp:chat-markers:0");
588				mXmppConnectionService.sendMessagePacket(account, receipt);
589			}
590			if (packet.hasChild("request", "urn:xmpp:receipts")) {
591				MessagePacket receipt = mXmppConnectionService
592						.getMessageGenerator().received(account, packet,
593								"urn:xmpp:receipts");
594				mXmppConnectionService.sendMessagePacket(account, receipt);
595			}
596		}
597		Conversation conversation = message.getConversation();
598		conversation.add(message);
599		if (account.getXmppConnection() != null && account.getXmppConnection().getFeatures().advancedStreamFeaturesLoaded()) {
600			if (conversation.setLastMessageTransmitted(System.currentTimeMillis())) {
601				mXmppConnectionService.updateConversation(conversation);
602			}
603		}
604
605		if (message.getStatus() == Message.STATUS_RECEIVED
606				&& conversation.getOtrSession() != null
607				&& !conversation.getOtrSession().getSessionID().getUserID()
608				.equals(message.getCounterpart().getResourcepart())) {
609			conversation.endOtrIfNeeded();
610		}
611
612		if (packet.getType() != MessagePacket.TYPE_ERROR) {
613			if (message.getEncryption() == Message.ENCRYPTION_NONE
614					|| mXmppConnectionService.saveEncryptedMessages()) {
615				mXmppConnectionService.databaseBackend.createMessage(message);
616			}
617		}
618		final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
619		if (message.trusted() && message.bodyContainsDownloadable() && manager.getAutoAcceptFileSize() > 0) {
620			manager.createNewConnection(message);
621		} else if (!message.isRead()) {
622			mXmppConnectionService.getNotificationService().push(message);
623		}
624		mXmppConnectionService.updateConversationUi();
625	}
626
627	private void parseHeadline(MessagePacket packet, Account account) {
628		if (packet.hasChild("event", "http://jabber.org/protocol/pubsub#event")) {
629			Element event = packet.findChild("event",
630					"http://jabber.org/protocol/pubsub#event");
631			parseEvent(event, packet.getFrom(), account);
632		}
633	}
634
635	private void parseNick(MessagePacket packet, Account account) {
636		Element nick = packet.findChild("nick",
637				"http://jabber.org/protocol/nick");
638		if (nick != null) {
639			if (packet.getFrom() != null) {
640				Contact contact = account.getRoster().getContact(
641						packet.getFrom());
642				contact.setPresenceName(nick.getContent());
643			}
644		}
645	}
646}