*/
public boolean sendBuddyMessage(String text) {
String to = buddy.getUser();
int sel = resourceBox.getSelectedIndex();
SecureExtension secureExtension = new SecureExtension();
SecureExtension signedExtension = new SecureExtension("signed");
// if they've selected a resource, send to it
if (sel != 0 && sel != 1 && sel != -1) {
to += "/" + (String) resourceBox.getSelectedItem();
}
ArrayList send = new ArrayList();
if (sel != 1 || resourceBox.getItemCount() <= 2) {
send.add(to);
}
// if they've selected to send to all resources, send to all
else {
Set keys = buddy.keySet();
Iterator i = keys.iterator();
while (i.hasNext()) {
String key = (String) i.next();
if (!key.equals("N/A")) {
send.add(buddy.getUser() + "/" + key);
}
}
}
String gnupgSecurityVariant = Settings.getInstance().getProperty(
"gnupgSecurityVariant");
String gnupgSecretKey = Settings.getInstance().getProperty(
"gnupgSecretKeyID");
String gnupgPublicKey = buddy.getPubKey();
if (JBotherLoader.isGPGEnabled() &&
// BuddyList.getInstance().isEncrypting()
buddy.isEncrypting() && (gnupgSecretKey != null)
&& (gnupgPublicKey != null)) {
GnuPG gnupg = new GnuPG();
String encryptedData = null;
String signedData = null;
if (gnupgSecurityVariant == null) {
gnupgSecurityVariant = "0";
Settings.getInstance().setProperty("gnupgSecurityVariant", "0");
}
if ((gnupgSecurityVariant.equals("0"))
|| (gnupgSecurityVariant.equals("1"))) {
encryptedData = gnupg.encryptExtension(text, gnupgSecretKey,
gnupgPublicKey);
if (encryptedData != null) {
secureExtension.setData(encryptedData);
}
}
if ((gnupgSecurityVariant.equals("0"))
|| (gnupgSecurityVariant.equals("2"))) {
signedData = gnupg.signExtension(text, gnupgSecretKey);
if (signedData != null) {
signedExtension.setData(signedData);
}
}
if ((encryptedData == null) && (signedData == null)) {
buddy.isEncrypting(false);
encryptButton.setIcon(Standard.getIcon("images/buttons/ssl_no.png"));
Standard.warningMessage(null,
resources.getString("gnupgError"), resources.getString("gnupgErrorEncrypting")
+ ".\n\n"
+ resources.getString("reason")
+ ":\n\n"
+ gnupg.getResult()
+ gnupg.getErrorString()
+ "\n"
+ resources.getString("gnupgTryOrSendUnencrypted")
+ ".");
return false;
}
}
for (int i = 0; i < send.size(); i++) {
Chat chat = null;
if (buddy instanceof MUCBuddyStatus) {
MultiUserChat muc = ((MUCBuddyStatus) buddy).getMUC();
chat = muc.createPrivateChat(buddy.getUser());
} else {
chat = (Chat) chats.get((String) send.get(i));
}
if (chat == null) {
chat = BuddyList.getInstance().getConnection().createChat(
(String) send.get(i));
chats.put((String) send.get(i), chat);
}
Message message = chat.createMessage();
if (secureExtension.getData() != null) {
message.setBody("[This message is encrypted]");
message.addExtension(secureExtension);
} else {
message.setBody(text);
}
if (signedExtension.getData() != null) {
message.addExtension(signedExtension);
}
if (buddy.isAskForDelivered()) {