MessageParser.java

  1package eu.siacs.conversations.parser;
  2
  3import android.util.Log;
  4import android.util.Pair;
  5
  6import eu.siacs.conversations.crypto.PgpDecryptionService;
  7import net.java.otr4j.session.Session;
  8import net.java.otr4j.session.SessionStatus;
  9
 10import java.util.ArrayList;
 11import java.util.Set;
 12
 13import eu.siacs.conversations.Config;
 14import eu.siacs.conversations.crypto.axolotl.AxolotlService;
 15import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
 16import eu.siacs.conversations.entities.Account;
 17import eu.siacs.conversations.entities.Bookmark;
 18import eu.siacs.conversations.entities.Contact;
 19import eu.siacs.conversations.entities.Conversation;
 20import eu.siacs.conversations.entities.Message;
 21import eu.siacs.conversations.entities.MucOptions;
 22import eu.siacs.conversations.http.HttpConnectionManager;
 23import eu.siacs.conversations.services.MessageArchiveService;
 24import eu.siacs.conversations.services.XmppConnectionService;
 25import eu.siacs.conversations.utils.CryptoHelper;
 26import eu.siacs.conversations.xml.Element;
 27import eu.siacs.conversations.xmpp.OnMessagePacketReceived;
 28import eu.siacs.conversations.xmpp.chatstate.ChatState;
 29import eu.siacs.conversations.xmpp.jid.Jid;
 30import eu.siacs.conversations.xmpp.pep.Avatar;
 31import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
 32
 33public class MessageParser extends AbstractParser implements
 34		OnMessagePacketReceived {
 35	public MessageParser(XmppConnectionService service) {
 36		super(service);
 37	}
 38
 39	private boolean extractChatState(Conversation conversation, final MessagePacket packet) {
 40		ChatState state = ChatState.parse(packet);
 41		if (state != null && conversation != null) {
 42			final Account account = conversation.getAccount();
 43			Jid from = packet.getFrom();
 44			if (from.toBareJid().equals(account.getJid().toBareJid())) {
 45				conversation.setOutgoingChatState(state);
 46				if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) {
 47					mXmppConnectionService.markRead(conversation);
 48					account.activateGracePeriod();
 49				}
 50				return false;
 51			} else {
 52				return conversation.setIncomingChatState(state);
 53			}
 54		}
 55		return false;
 56	}
 57
 58	private Message parseOtrChat(String body, Jid from, String id, Conversation conversation) {
 59		String presence;
 60		if (from.isBareJid()) {
 61			presence = "";
 62		} else {
 63			presence = from.getResourcepart();
 64		}
 65		if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) {
 66			conversation.endOtrIfNeeded();
 67		}
 68		if (!conversation.hasValidOtrSession()) {
 69			conversation.startOtrSession(presence,false);
 70		} else {
 71			String foreignPresence = conversation.getOtrSession().getSessionID().getUserID();
 72			if (!foreignPresence.equals(presence)) {
 73				conversation.endOtrIfNeeded();
 74				conversation.startOtrSession(presence, false);
 75			}
 76		}
 77		try {
 78			conversation.setLastReceivedOtrMessageId(id);
 79			Session otrSession = conversation.getOtrSession();
 80			body = otrSession.transformReceiving(body);
 81			SessionStatus status = otrSession.getSessionStatus();
 82			if (body == null && status == SessionStatus.ENCRYPTED) {
 83				mXmppConnectionService.onOtrSessionEstablished(conversation);
 84				return null;
 85			} else if (body == null && status == SessionStatus.FINISHED) {
 86				conversation.resetOtrSession();
 87				mXmppConnectionService.updateConversationUi();
 88				return null;
 89			} else if (body == null || (body.isEmpty())) {
 90				return null;
 91			}
 92			if (body.startsWith(CryptoHelper.FILETRANSFER)) {
 93				String key = body.substring(CryptoHelper.FILETRANSFER.length());
 94				conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
 95				return null;
 96			}
 97			Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED);
 98			conversation.setLastReceivedOtrMessageId(null);
 99			return finishedMessage;
100		} catch (Exception e) {
101			conversation.resetOtrSession();
102			return null;
103		}
104	}
105
106	private Message parseAxolotlChat(Element axolotlMessage, Jid from, String id, Conversation conversation, int status) {
107		Message finishedMessage = null;
108		AxolotlService service = conversation.getAccount().getAxolotlService();
109		XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid());
110		XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage);
111		if(plaintextMessage != null) {
112			finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
113			finishedMessage.setAxolotlFingerprint(plaintextMessage.getFingerprint());
114			Log.d(Config.LOGTAG, AxolotlService.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint());
115		}
116
117		return finishedMessage;
118	}
119
120	private Message parsePGPChat(final Conversation conversation, String pgpEncrypted, int status) {
121		final Message message = new Message(conversation, pgpEncrypted, Message.ENCRYPTION_PGP, status);
122		PgpDecryptionService pgpDecryptionService = conversation.getAccount().getPgpDecryptionService();
123		pgpDecryptionService.add(message);
124		return message;
125	}
126
127	private class Invite {
128		Jid jid;
129		String password;
130		Invite(Jid jid, String password) {
131			this.jid = jid;
132			this.password = password;
133		}
134
135		public boolean execute(Account account) {
136			if (jid != null) {
137				Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true);
138				if (!conversation.getMucOptions().online()) {
139					conversation.getMucOptions().setPassword(password);
140					mXmppConnectionService.databaseBackend.updateConversation(conversation);
141					mXmppConnectionService.joinMuc(conversation);
142					mXmppConnectionService.updateConversationUi();
143				}
144				return true;
145			}
146			return false;
147		}
148	}
149
150	private Invite extractInvite(Element message) {
151		Element x = message.findChild("x", "http://jabber.org/protocol/muc#user");
152		if (x != null) {
153			Element invite = x.findChild("invite");
154			if (invite != null) {
155				Element pw = x.findChild("password");
156				return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent(): null);
157			}
158		} else {
159			x = message.findChild("x","jabber:x:conference");
160			if (x != null) {
161				return new Invite(x.getAttributeAsJid("jid"),x.getAttribute("password"));
162			}
163		}
164		return null;
165	}
166
167	private static String extractStanzaId(Element packet, Jid by) {
168		for(Element child : packet.getChildren()) {
169			if (child.getName().equals("stanza-id")
170					&& "urn:xmpp:sid:0".equals(child.getNamespace())
171					&& by.equals(child.getAttributeAsJid("by"))) {
172				return child.getAttribute("id");
173			}
174		}
175		return null;
176	}
177
178	private void parseEvent(final Element event, final Jid from, final Account account) {
179		Element items = event.findChild("items");
180		String node = items == null ? null : items.getAttribute("node");
181		if ("urn:xmpp:avatar:metadata".equals(node)) {
182			Avatar avatar = Avatar.parseMetadata(items);
183			if (avatar != null) {
184				avatar.owner = from.toBareJid();
185				if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
186					if (account.getJid().toBareJid().equals(from)) {
187						if (account.setAvatar(avatar.getFilename())) {
188							mXmppConnectionService.databaseBackend.updateAccount(account);
189						}
190						mXmppConnectionService.getAvatarService().clear(account);
191						mXmppConnectionService.updateConversationUi();
192						mXmppConnectionService.updateAccountUi();
193					} else {
194						Contact contact = account.getRoster().getContact(from);
195						contact.setAvatar(avatar);
196						mXmppConnectionService.getAvatarService().clear(contact);
197						mXmppConnectionService.updateConversationUi();
198						mXmppConnectionService.updateRosterUi();
199					}
200				} else {
201					mXmppConnectionService.fetchAvatar(account, avatar);
202				}
203			}
204		} else if ("http://jabber.org/protocol/nick".equals(node)) {
205			Element i = items.findChild("item");
206			Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick");
207			if (nick != null && nick.getContent() != null) {
208				Contact contact = account.getRoster().getContact(from);
209				contact.setPresenceName(nick.getContent());
210				mXmppConnectionService.getAvatarService().clear(account);
211				mXmppConnectionService.updateConversationUi();
212				mXmppConnectionService.updateAccountUi();
213			}
214		} else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
215			Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Received PEP device list update from "+ from + ", processing...");
216			Element item = items.findChild("item");
217			Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
218			AxolotlService axolotlService = account.getAxolotlService();
219			axolotlService.registerDevices(from, deviceIds);
220			mXmppConnectionService.updateAccountUi();
221		}
222	}
223
224	private boolean handleErrorMessage(Account account, MessagePacket packet) {
225		if (packet.getType() == MessagePacket.TYPE_ERROR) {
226			Jid from = packet.getFrom();
227			if (from != null) {
228				Element error = packet.findChild("error");
229				String text = error == null ? null : error.findChildContent("text");
230				if (text != null) {
231					Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending message to "+ from+ " failed - " + text);
232				} else if (error != null) {
233					Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending message to "+ from+ " failed - " + error);
234				}
235				Message message = mXmppConnectionService.markMessage(account,
236						from.toBareJid(),
237						packet.getId(),
238						Message.STATUS_SEND_FAILED);
239				if (message != null && message.getEncryption() == Message.ENCRYPTION_OTR) {
240					message.getConversation().endOtrIfNeeded();
241				}
242			}
243			return true;
244		}
245		return false;
246	}
247
248	@Override
249	public void onMessagePacketReceived(Account account, MessagePacket original) {
250		if (handleErrorMessage(account, original)) {
251			return;
252		}
253		final MessagePacket packet;
254		Long timestamp = null;
255		final boolean isForwarded;
256		boolean isCarbon = false;
257		String serverMsgId = null;
258		final Element fin = original.findChild("fin", "urn:xmpp:mam:0");
259		if (fin != null) {
260			mXmppConnectionService.getMessageArchiveService().processFin(fin,original.getFrom());
261			return;
262		}
263		final Element result = original.findChild("result","urn:xmpp:mam:0");
264		final MessageArchiveService.Query query = result == null ? null : mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid"));
265		if (query != null && query.validFrom(original.getFrom())) {
266			Pair<MessagePacket, Long> f = original.getForwardedMessagePacket("result", "urn:xmpp:mam:0");
267			if (f == null) {
268				return;
269			}
270			timestamp = f.second;
271			packet = f.first;
272			isForwarded = true;
273			serverMsgId = result.getAttribute("id");
274			query.incrementMessageCount();
275		} else if (query != null) {
276			Log.d(Config.LOGTAG,account.getJid().toBareJid()+": received mam result from invalid sender");
277			return;
278		} else if (original.fromServer(account)) {
279			Pair<MessagePacket, Long> f;
280			f = original.getForwardedMessagePacket("received", "urn:xmpp:carbons:2");
281			f = f == null ? original.getForwardedMessagePacket("sent", "urn:xmpp:carbons:2") : f;
282			packet = f != null ? f.first : original;
283			if (handleErrorMessage(account, packet)) {
284				return;
285			}
286			timestamp = f != null ? f.second : null;
287			isCarbon = f != null;
288			isForwarded = isCarbon;
289		} else {
290			packet = original;
291			isForwarded = false;
292		}
293
294		if (timestamp == null) {
295			timestamp = AbstractParser.getTimestamp(packet, System.currentTimeMillis());
296		}
297		final String body = packet.getBody();
298		final Element mucUserElement = packet.findChild("x", "http://jabber.org/protocol/muc#user");
299		final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted");
300		final Element replaceElement = packet.findChild("replace","urn:xmpp:message-correct:0");
301		final String replacementId = replaceElement == null ? null : replaceElement.getAttribute("id");
302		final Element axolotlEncrypted = packet.findChild(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX);
303		int status;
304		final Jid counterpart;
305		final Jid to = packet.getTo();
306		final Jid from = packet.getFrom();
307		final String remoteMsgId = packet.getId();
308
309		if (from == null) {
310			Log.d(Config.LOGTAG,"no from in: "+packet.toString());
311			return;
312		}
313		
314		boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT;
315		boolean isProperlyAddressed = (to != null ) && (!to.isBareJid() || account.countPresences() <= 1);
316		boolean isMucStatusMessage = from.isBareJid() && mucUserElement != null && mucUserElement.hasChild("status");
317		if (packet.fromAccount(account)) {
318			status = Message.STATUS_SEND;
319			counterpart = to != null ? to : account.getJid();
320		} else {
321			status = Message.STATUS_RECEIVED;
322			counterpart = from;
323		}
324
325		Invite invite = extractInvite(packet);
326		if (invite != null && invite.execute(account)) {
327			return;
328		}
329
330		if (extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), packet)) {
331			mXmppConnectionService.updateConversationUi();
332		}
333
334		if ((body != null || pgpEncrypted != null || axolotlEncrypted != null) && !isMucStatusMessage) {
335			Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, query);
336			if (isTypeGroupChat) {
337				if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
338					status = Message.STATUS_SEND_RECEIVED;
339					isCarbon = true; //not really carbon but received from another resource
340					if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status)) {
341						return;
342					} else if (remoteMsgId == null || Config.IGNORE_ID_REWRITE_IN_MUC) {
343						Message message = conversation.findSentMessageWithBody(packet.getBody());
344						if (message != null) {
345							mXmppConnectionService.markMessage(message, status);
346							return;
347						}
348					}
349				} else {
350					status = Message.STATUS_RECEIVED;
351				}
352			}
353			Message message;
354			if (body != null && body.startsWith("?OTR")) {
355				if (!isForwarded && !isTypeGroupChat && isProperlyAddressed) {
356					message = parseOtrChat(body, from, remoteMsgId, conversation);
357					if (message == null) {
358						return;
359					}
360				} else {
361					Log.d(Config.LOGTAG,account.getJid().toBareJid()+": ignoring OTR message from "+from+" isForwarded="+Boolean.toString(isForwarded)+", isProperlyAddressed="+Boolean.valueOf(isProperlyAddressed));
362					message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
363				}
364			} else if (pgpEncrypted != null) {
365				message = parsePGPChat(conversation, pgpEncrypted, status);
366			} else if (axolotlEncrypted != null) {
367				message = parseAxolotlChat(axolotlEncrypted, from, remoteMsgId, conversation, status);
368				if (message == null) {
369					return;
370				}
371			} else {
372				message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
373			}
374
375			if (serverMsgId == null) {
376				serverMsgId = extractStanzaId(packet, isTypeGroupChat ? conversation.getJid().toBareJid() : account.getServer());
377			}
378
379			message.setCounterpart(counterpart);
380			message.setRemoteMsgId(remoteMsgId);
381			message.setServerMsgId(serverMsgId);
382			message.setCarbon(isCarbon);
383			message.setTime(timestamp);
384			message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
385			if (conversation.getMode() == Conversation.MODE_MULTI) {
386				Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());
387				message.setTrueCounterpart(trueCounterpart);
388				if (trueCounterpart != null) {
389					updateLastseen(timestamp, account, trueCounterpart, false);
390				}
391				if (!isTypeGroupChat) {
392					message.setType(Message.TYPE_PRIVATE);
393				}
394			} else {
395				updateLastseen(timestamp, account, packet.getFrom(), true);
396			}
397
398			if (replacementId != null && mXmppConnectionService.allowMessageCorrection()) {
399				Message replacedMessage = conversation.findMessageWithRemoteIdAndCounterpart(replacementId,
400						counterpart,
401						message.getStatus() == Message.STATUS_RECEIVED,
402						message.isCarbon());
403				if (replacedMessage != null) {
404					final boolean fingerprintsMatch = replacedMessage.getAxolotlFingerprint() == null
405							|| replacedMessage.getAxolotlFingerprint().equals(message.getAxolotlFingerprint());
406					final boolean trueCountersMatch = replacedMessage.getTrueCounterpart() != null
407							&& replacedMessage.getTrueCounterpart().equals(message.getTrueCounterpart());
408					if (fingerprintsMatch && (trueCountersMatch || conversation.getMode() == Conversation.MODE_SINGLE)) {
409						Log.d(Config.LOGTAG, "replaced message '" + replacedMessage.getBody() + "' with '" + message.getBody() + "'");
410						replacedMessage.setBody(message.getBody());
411						replacedMessage.setEdited(replacedMessage.getRemoteMsgId());
412						replacedMessage.setRemoteMsgId(remoteMsgId);
413						if (replacedMessage.getStatus() == Message.STATUS_RECEIVED) {
414							replacedMessage.markUnread();
415						}
416						mXmppConnectionService.updateMessage(replacedMessage);
417						if (mXmppConnectionService.confirmMessages() && remoteMsgId != null && !isForwarded && !isTypeGroupChat) {
418							sendMessageReceipts(account, packet);
419						}
420						return;
421					} else {
422						Log.d(Config.LOGTAG,account.getJid().toBareJid()+": received message correction but verification didn't check out");
423					}
424				}
425			}
426
427			boolean checkForDuplicates = query != null
428					|| (isTypeGroupChat && packet.hasChild("delay","urn:xmpp:delay"))
429					|| message.getType() == Message.TYPE_PRIVATE;
430			if (checkForDuplicates && conversation.hasDuplicateMessage(message)) {
431				Log.d(Config.LOGTAG,"skipping duplicate message from "+message.getCounterpart().toString()+" "+message.getBody());
432				return;
433			}
434
435			if (query != null && query.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
436				conversation.prepend(message);
437			} else {
438				conversation.add(message);
439			}
440
441			if (query == null || query.getWith() == null) { //either no mam or catchup
442				if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) {
443					mXmppConnectionService.markRead(conversation);
444					if (query == null) {
445						account.activateGracePeriod();
446					}
447				} else {
448					message.markUnread();
449				}
450			}
451
452			if (query == null) {
453				mXmppConnectionService.updateConversationUi();
454			}
455
456			if (mXmppConnectionService.confirmMessages() && remoteMsgId != null && !isForwarded && !isTypeGroupChat) {
457				sendMessageReceipts(account, packet);
458			}
459
460			if (message.getStatus() == Message.STATUS_RECEIVED
461					&& conversation.getOtrSession() != null
462					&& !conversation.getOtrSession().getSessionID().getUserID()
463					.equals(message.getCounterpart().getResourcepart())) {
464				conversation.endOtrIfNeeded();
465			}
466
467			if (message.getEncryption() == Message.ENCRYPTION_NONE || mXmppConnectionService.saveEncryptedMessages()) {
468				mXmppConnectionService.databaseBackend.createMessage(message);
469			}
470			final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
471			if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) {
472				manager.createNewDownloadConnection(message);
473			} else if (!message.isRead()) {
474				if (query == null) {
475					mXmppConnectionService.getNotificationService().push(message);
476				} else if (query.getWith() == null) { // mam catchup
477					mXmppConnectionService.getNotificationService().pushFromBacklog(message);
478				}
479			}
480		} else if (!packet.hasChild("body")){ //no body
481			if (isTypeGroupChat) {
482				Conversation conversation = mXmppConnectionService.find(account, from.toBareJid());
483				if (packet.hasChild("subject")) {
484					if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
485						conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0);
486						String subject = packet.findChildContent("subject");
487						conversation.getMucOptions().setSubject(subject);
488						final Bookmark bookmark = conversation.getBookmark();
489						if (bookmark != null && bookmark.getBookmarkName() == null) {
490							if (bookmark.setBookmarkName(subject)) {
491								mXmppConnectionService.pushBookmarks(account);
492							}
493						}
494						mXmppConnectionService.updateConversationUi();
495						return;
496					}
497				}
498
499				if (conversation != null && isMucStatusMessage) {
500					for (Element child : mucUserElement.getChildren()) {
501						if (child.getName().equals("status")
502								&& MucOptions.STATUS_CODE_ROOM_CONFIG_CHANGED.equals(child.getAttribute("code"))) {
503							mXmppConnectionService.fetchConferenceConfiguration(conversation);
504						}
505					}
506				}
507			}
508		}
509
510		Element received = packet.findChild("received", "urn:xmpp:chat-markers:0");
511		if (received == null) {
512			received = packet.findChild("received", "urn:xmpp:receipts");
513		}
514		if (received != null && !packet.fromAccount(account)) {
515			mXmppConnectionService.markMessage(account, from.toBareJid(), received.getAttribute("id"), Message.STATUS_SEND_RECEIVED);
516		}
517		Element displayed = packet.findChild("displayed", "urn:xmpp:chat-markers:0");
518		if (displayed != null) {
519			if (packet.fromAccount(account)) {
520				Conversation conversation = mXmppConnectionService.find(account,counterpart.toBareJid());
521				if (conversation != null) {
522					mXmppConnectionService.markRead(conversation);
523				}
524			} else {
525				updateLastseen(timestamp, account, packet.getFrom(), true);
526				final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), displayed.getAttribute("id"), Message.STATUS_SEND_DISPLAYED);
527				Message message = displayedMessage == null ? null : displayedMessage.prev();
528				while (message != null
529						&& message.getStatus() == Message.STATUS_SEND_RECEIVED
530						&& message.getTimeSent() < displayedMessage.getTimeSent()) {
531					mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED);
532					message = message.prev();
533				}
534			}
535		}
536
537		Element event = packet.findChild("event", "http://jabber.org/protocol/pubsub#event");
538		if (event != null) {
539			parseEvent(event, from, account);
540		}
541
542		String nick = packet.findChildContent("nick", "http://jabber.org/protocol/nick");
543		if (nick != null) {
544			Contact contact = account.getRoster().getContact(from);
545			contact.setPresenceName(nick);
546		}
547	}
548
549	private void sendMessageReceipts(Account account, MessagePacket packet) {
550		ArrayList<String> receiptsNamespaces = new ArrayList<>();
551		if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) {
552			receiptsNamespaces.add("urn:xmpp:chat-markers:0");
553		}
554		if (packet.hasChild("request", "urn:xmpp:receipts")) {
555			receiptsNamespaces.add("urn:xmpp:receipts");
556		}
557		if (receiptsNamespaces.size() > 0) {
558			MessagePacket receipt = mXmppConnectionService.getMessageGenerator().received(account,
559					packet,
560					receiptsNamespaces,
561					packet.getType());
562			mXmppConnectionService.sendMessagePacket(account, receipt);
563		}
564	}
565}