/**
* Processes the message packet
*/
public void processPacket(Packet message) {
final Message packet = (Message) message;
verifiedFlag = false;
decryptedFlag = false;
if (packet.getType() != Message.Type.CHAT
&& packet.getType() != Message.Type.HEADLINE
&& packet.getType() != Message.Type.NORMAL)
return;
if (!started) {
com.valhalla.Logger.debug("Message received, adding to queue.");
messageQueue.add(message);
return;
}
if (packet.getType() == Message.Type.NORMAL) {
if (packet.getBody() == null)
return;
PacketExtension ex = packet.getExtension("x",
"http://jabber.org/protocol/muc#user");
if (ex != null)
return;
ex = packet.getExtension("x", "jabber:x:conference");
if (ex != null)
return;
ParsedBuddyInfo info = new ParsedBuddyInfo(packet.getFrom());
String userId = info.getUserId().toLowerCase();
if (!Settings.getInstance().getBoolean("showAgentMessages")
&& userId.indexOf("@") == -1)
return;
if (BuddyList.getInstance().getBlockedUsers().containsKey(userId)) {
com.valhalla.Logger.debug("Blocking user: " + userId);
return;
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MessagePanel window = new MessagePanel();
window.receiveMessage(packet);
}
});
return;
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
String from = packet.getFrom();
//check to see if it's a private message
if (BuddyList.getInstance().getTabFrame() != null
&& BuddyList.getInstance().getTabFrame().isRoomOpen(
from.replaceAll("\\/.*", ""))) {
ChatRoomPanel window = BuddyList.getInstance()
.getTabFrame().getChatPanel(
from.replaceAll("\\/.*", ""));
if (window != null)
initiatePMSession(window, packet);
return;
}
if (from != null) {
ParsedBuddyInfo info = new ParsedBuddyInfo(from);
String userId = info.getUserId().toLowerCase();
String resource = info.getResource();
String server = info.getServer();
from = info.getBareAddress();
BuddyStatus buddy = BuddyList.getInstance().getBuddyStatus(
userId);
if (BuddyList.getInstance().getBlockedUsers().containsKey(
userId)) {
com.valhalla.Logger.debug("Blocking user: " + userId);
return;
}
String messageSbj = packet.getSubject();
String messageBody = packet.getBody();
GnuPG gnupg = new GnuPG();
decryptedFlag = false;
verifiedFlag = false;
final SecureExtension xEncryptedExtension = (SecureExtension) packet
.getExtension("x", "jabber:x:encrypted");
if (xEncryptedExtension != null
&& Settings.getInstance().getProperty(
"gnupgSecretKeyID") != null) {
String decryptedMessageBody = gnupg
.decryptExtension(xEncryptedExtension.getData());
if (decryptedMessageBody != null) {
messageBody = decryptedMessageBody;
decryptedFlag = true;
} else {
messageBody = "[ "
+ resources
.getString("gnupgErrorDecrypting")
+ ". "
+ resources.getString("reason")
+ ":\n "
+ gnupg.getErrorString().replaceAll("\n",
" ") + " ]";
}
}
final SecureExtension xSignedExtension = (SecureExtension) packet
.getExtension("x", "jabber:x:signed");
if (xSignedExtension != null) {
String verifiedMessageId = gnupg.verifyExtension(
xSignedExtension.getData(), messageBody);
if (verifiedMessageId != null) {
verifiedMessageId = verifiedMessageId.replaceAll(
"\n$", "");
}
if ((verifiedMessageId != null)
&& (buddy.getPubKey() != null)
&& (buddy.getPubKey()
.endsWith(verifiedMessageId))) {
verifiedFlag = true;
}
}
if (!BuddyList.getInstance().checkConnection())
return;
// we don't want null messages to be displayed.
if ((messageBody == null))
return;
if (!Settings.getInstance().getBoolean("showAgentMessages")
&& userId.indexOf("@") == -1)
return;
RosterEntry entry = ConnectorThread.getInstance()
.getRoster().getEntry(from);
if (entry != null)
userId = entry.getName();
if (buddy.getName() != null)
userId = buddy.getName();
if (buddy.getConversation() == null) {
if (packet.getType() == Message.Type.HEADLINE) {
buddy.setConversation(new HeadlinesPanel(buddy));
} else {
buddy.setConversation(new ChatPanel(buddy));
}
}
Date date = null;
String append = "";
DelayInformation inf = (DelayInformation) packet
.getExtension("x", "jabber:x:delay");
if (inf != null
&& buddy.getConversation() instanceof ChatPanel) {
append = " (" + resources.getString( "offline" ).toLowerCase();