Search in sources :

Example 1 with GoogleNewMailExtension

use of net.sf.kraken.protocols.xmpp.packet.GoogleNewMailExtension in project Openfire by igniterealtime.

the class XMPPListener method processPacket.

public void processPacket(Packet packet) {
    if (packet instanceof GoogleMailBoxPacket) {
        if (JiveGlobals.getBooleanProperty("plugin.gateway.gtalk.mailnotifications", true)) {
            GoogleMailBoxPacket mbp = (GoogleMailBoxPacket) packet;
            this.setLastGMailThreadDate(mbp.getResultTime());
            Integer newMailCount = 0;
            String mailList = "";
            for (GoogleMailThread mail : mbp.getMailThreads()) {
                newMailCount++;
                if (this.getLastGMailThreadId() == null || mail.getThreadId() > this.getLastGMailThreadId()) {
                    this.setLastGMailThreadId(mail.getThreadId());
                }
                String senderList = "";
                for (GoogleMailSender sender : mail.getSenders()) {
                    if (!senderList.equals("")) {
                        senderList += ", ";
                    }
                    String name = sender.getName();
                    if (name != null) {
                        senderList += name + " <";
                    }
                    senderList += sender.getAddress();
                    if (name != null) {
                        senderList += ">";
                    }
                }
                mailList += "\n   " + senderList + " sent " + mail.getSubject();
            }
            if (newMailCount > 0) {
                getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.gtalk.mail", "kraken", Arrays.asList(newMailCount)) + mailList, Message.Type.headline);
            }
        }
    } else if (packet instanceof IQ) {
        Log.debug("XMPP: Got google mail notification");
        GoogleNewMailExtension gnme = (GoogleNewMailExtension) packet.getExtension(GoogleNewMailExtension.ELEMENT_NAME, GoogleNewMailExtension.NAMESPACE);
        if (gnme != null) {
            Log.debug("XMPP: Sending google mail request");
            getSession().conn.sendPacket(new IQWithPacketExtension(new GoogleMailNotifyExtension()));
        }
    }
}
Also used : GoogleMailNotifyExtension(net.sf.kraken.protocols.xmpp.packet.GoogleMailNotifyExtension) GoogleMailThread(net.sf.kraken.protocols.xmpp.packet.GoogleMailThread) IQ(org.jivesoftware.smack.packet.IQ) IQWithPacketExtension(net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension) GoogleMailSender(net.sf.kraken.protocols.xmpp.packet.GoogleMailSender) GoogleMailBoxPacket(net.sf.kraken.protocols.xmpp.packet.GoogleMailBoxPacket) GoogleNewMailExtension(net.sf.kraken.protocols.xmpp.packet.GoogleNewMailExtension)

Aggregations

GoogleMailBoxPacket (net.sf.kraken.protocols.xmpp.packet.GoogleMailBoxPacket)1 GoogleMailNotifyExtension (net.sf.kraken.protocols.xmpp.packet.GoogleMailNotifyExtension)1 GoogleMailSender (net.sf.kraken.protocols.xmpp.packet.GoogleMailSender)1 GoogleMailThread (net.sf.kraken.protocols.xmpp.packet.GoogleMailThread)1 GoogleNewMailExtension (net.sf.kraken.protocols.xmpp.packet.GoogleNewMailExtension)1 IQWithPacketExtension (net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension)1 IQ (org.jivesoftware.smack.packet.IQ)1