Search in sources :

Example 1 with GoogleMailNotifyExtension

use of net.sf.kraken.protocols.xmpp.packet.GoogleMailNotifyExtension 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)

Example 2 with GoogleMailNotifyExtension

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

the class XMPPSession method logIn.

/**
     * @see net.sf.kraken.session.TransportSession#logIn(net.sf.kraken.type.PresenceType, String)
     */
@Override
public void logIn(PresenceType presenceType, String verboseStatus) {
    final org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence(org.jivesoftware.smack.packet.Presence.Type.available);
    if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".avatars", true) && getAvatar() != null) {
        Avatar avatar = getAvatar();
        // Same thing in this case, so lets go ahead and set them.
        avatar.setLegacyIdentifier(avatar.getXmppHash());
        VCardUpdateExtension ext = new VCardUpdateExtension();
        ext.setPhotoHash(avatar.getLegacyIdentifier());
        presence.addExtension(ext);
    }
    final Presence.Mode pMode = ((XMPPTransport) getTransport()).convertGatewayStatusToXMPP(presenceType);
    if (pMode != null) {
        presence.setMode(pMode);
    }
    if (verboseStatus != null && verboseStatus.trim().length() > 0) {
        presence.setStatus(verboseStatus);
    }
    setPendingPresenceAndStatus(presenceType, verboseStatus);
    if (!this.isLoggedIn()) {
        listener = new XMPPListener(this);
        presenceHandler = new XMPPPresenceHandler(this);
        runThread = new Thread() {

            @Override
            public void run() {
                String userName = generateUsername(registration.getUsername());
                conn = new XMPPConnection(config);
                try {
                    conn.getSASLAuthentication().registerSASLMechanism("DIGEST-MD5", MySASLDigestMD5Mechanism.class);
                    if (getTransport().getType().equals(TransportType.facebook) && registration.getUsername().equals("{PLATFORM}")) {
                        conn.getSASLAuthentication().registerSASLMechanism("X-FACEBOOK-PLATFORM", FacebookConnectSASLMechanism.class);
                        conn.getSASLAuthentication().supportSASLMechanism("X-FACEBOOK-PLATFORM", 0);
                    }
                    Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
                    conn.connect();
                    conn.addConnectionListener(listener);
                    try {
                        conn.addPacketListener(presenceHandler, new PacketTypeFilter(org.jivesoftware.smack.packet.Presence.class));
                        // Use this to filter out anything we don't care about
                        conn.addPacketListener(listener, new OrFilter(new PacketTypeFilter(GoogleMailBoxPacket.class), new PacketExtensionFilter(GoogleNewMailExtension.ELEMENT_NAME, GoogleNewMailExtension.NAMESPACE)));
                        conn.login(userName, registration.getPassword(), xmppResource);
                        // send initial presence.
                        conn.sendPacket(presence);
                        conn.getChatManager().addChatListener(listener);
                        conn.getRoster().addRosterListener(listener);
                        if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".avatars", !TransportType.facebook.equals(getTransport().getType())) && getAvatar() != null) {
                            new Thread() {

                                @Override
                                public void run() {
                                    Avatar avatar = getAvatar();
                                    VCard vCard = new VCard();
                                    try {
                                        vCard.load(conn);
                                        vCard.setAvatar(Base64.decode(avatar.getImageData()), avatar.getMimeType());
                                        vCard.save(conn);
                                    } catch (XMPPException e) {
                                        Log.debug("XMPP: Error while updating vcard for avatar change.", e);
                                    } catch (NotFoundException e) {
                                        Log.debug("XMPP: Unable to find avatar while setting initial.", e);
                                    }
                                }
                            }.start();
                        }
                        setLoginStatus(TransportLoginStatus.LOGGED_IN);
                        syncUsers();
                        if (getTransport().getType().equals(TransportType.gtalk) && JiveGlobals.getBooleanProperty("plugin.gateway.gtalk.mailnotifications", true)) {
                            conn.sendPacket(new IQWithPacketExtension(generateFullJID(getRegistration().getUsername()), new GoogleUserSettingExtension(null, true, null), IQ.Type.SET));
                            conn.sendPacket(new IQWithPacketExtension(generateFullJID(getRegistration().getUsername()), new GoogleMailNotifyExtension()));
                            mailCheck = new MailCheck();
                            timer.schedule(mailCheck, timerInterval, timerInterval);
                        }
                    } catch (XMPPException e) {
                        Log.debug(getTransport().getType() + " user's login/password does not appear to be correct: " + getRegistration().getUsername(), e);
                        setFailureStatus(ConnectionFailureReason.USERNAME_OR_PASSWORD_INCORRECT);
                        sessionDisconnectedNoReconnect(LocaleUtils.getLocalizedString("gateway.xmpp.passwordincorrect", "kraken"));
                    }
                } catch (XMPPException e) {
                    Log.debug(getTransport().getType() + " user is not able to connect: " + getRegistration().getUsername(), e);
                    setFailureStatus(ConnectionFailureReason.CAN_NOT_CONNECT);
                    sessionDisconnected(LocaleUtils.getLocalizedString("gateway.xmpp.connectionfailed", "kraken"));
                }
            }
        };
        runThread.start();
    }
}
Also used : FacebookConnectSASLMechanism(net.sf.kraken.protocols.xmpp.mechanisms.FacebookConnectSASLMechanism) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) GoogleMailBoxPacket(net.sf.kraken.protocols.xmpp.packet.GoogleMailBoxPacket) VCardUpdateExtension(net.sf.kraken.protocols.xmpp.packet.VCardUpdateExtension) Presence(org.jivesoftware.smack.packet.Presence) VCard(org.jivesoftware.smackx.packet.VCard) GoogleUserSettingExtension(net.sf.kraken.protocols.xmpp.packet.GoogleUserSettingExtension) MySASLDigestMD5Mechanism(net.sf.kraken.protocols.xmpp.mechanisms.MySASLDigestMD5Mechanism) GoogleMailNotifyExtension(net.sf.kraken.protocols.xmpp.packet.GoogleMailNotifyExtension) Presence(org.jivesoftware.smack.packet.Presence) org.jivesoftware.smack(org.jivesoftware.smack) IQWithPacketExtension(net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) OrFilter(org.jivesoftware.smack.filter.OrFilter) Avatar(net.sf.kraken.avatars.Avatar) PacketExtensionFilter(org.jivesoftware.smack.filter.PacketExtensionFilter)

Aggregations

GoogleMailBoxPacket (net.sf.kraken.protocols.xmpp.packet.GoogleMailBoxPacket)2 GoogleMailNotifyExtension (net.sf.kraken.protocols.xmpp.packet.GoogleMailNotifyExtension)2 IQWithPacketExtension (net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension)2 Avatar (net.sf.kraken.avatars.Avatar)1 FacebookConnectSASLMechanism (net.sf.kraken.protocols.xmpp.mechanisms.FacebookConnectSASLMechanism)1 MySASLDigestMD5Mechanism (net.sf.kraken.protocols.xmpp.mechanisms.MySASLDigestMD5Mechanism)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 GoogleUserSettingExtension (net.sf.kraken.protocols.xmpp.packet.GoogleUserSettingExtension)1 VCardUpdateExtension (net.sf.kraken.protocols.xmpp.packet.VCardUpdateExtension)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 org.jivesoftware.smack (org.jivesoftware.smack)1 OrFilter (org.jivesoftware.smack.filter.OrFilter)1 PacketExtensionFilter (org.jivesoftware.smack.filter.PacketExtensionFilter)1 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)1 IQ (org.jivesoftware.smack.packet.IQ)1 Presence (org.jivesoftware.smack.packet.Presence)1 VCard (org.jivesoftware.smackx.packet.VCard)1 NotFoundException (org.jivesoftware.util.NotFoundException)1