Package net.sf.jml

Examples of net.sf.jml.MsnMessenger


  System.out.println("to:"+in0);
  System.out.println("message:"+in1);   
 
    try{
      final Vector bLogin = new Vector();
      MsnMessenger messenger = null;
     
      if(!loggingin){
        if(messenger==null || !messenger.isLogIncoming()){
          messenger = MsnMessengerFactory.createMsnMessenger(msnUserId, password);
              messenger.login();             
              loggingin = true;             
              messenger.addListener(new MsnAdapter(){
            public void loginCompleted(MsnMessenger messenger) {
              bLogin.add("");
              loggingin = false;
            }
          });
        }else
          bLogin.add("");
      }
            
      final String toEMailAddress = in0;
      final String messageContent = in1;
     
      boolean bSuccess = false;     
     
   
      for(int i=0; i<loginRetryCnt && bLogin.size()==0; i++){ //wait for msn login
        System.out.println("trying logging in...");
        Thread.sleep(5000);
     

      if(bLogin.size()==0){
       
        loggingin = false;
        throw new Exception("Couldn't log in the MSN.");
      }
     
      int retry=0;
     
      while(!bSuccess && retry < messageSendingRetryCnt){
        String friendLoginName = toEMailAddress;
        Email friendMail=Email.parseStr(friendLoginName);
        messenger.sendText(friendMail, messageContent);               
              
                System.out.println("Success");               
                bSuccess=true;
              
        try{
View Full Code Here


    @Override
    protected void messageReceived(final MsnSession session) {
        super.messageReceived(session);

        final MsnSwitchboard switchboard = session.getSwitchboard();
        final MsnMessenger messenger = session.getMessenger();
        if (isLoginSuccess()) {
//            log.debug("MSNDEBUG: We have a successful login USR packet!");
            if (isLoginIntoSB()) { //login success to SB
                if (switchboard != null) {
                    ((AbstractMessenger) messenger)
                            .fireSwitchboardStarted(switchboard);
                }
            } else { //login success to NS
                MsnOwnerImpl owner = (MsnOwnerImpl) messenger.getOwner();
                owner.setVerified(isVerified());
                owner.fSetDisplayName(getDisplayName());
                ((AbstractMessenger) messenger).fireLoginCompleted();

                // obtaining contact list with syn packet has been dropped after
                // MSN13
                if(protocol.before(MsnProtocol.MSNP13))
                {
                    OutgoingSYN message = new OutgoingSYN(protocol);
                    message.setCachedVersion(messenger.getContactList()
                            .getVersion());
                    messenger.send(message);
                }
                else
                {
                    // call for contact list
                    session.getContactList().dispatch();
                }
            }
        } else { //auth
//            log.debug("MSNDEBUG: We are doing auth, opening a thread to handle it");
            //SSL is slow, open new thread to do this
            new Thread() {

                private String getPassportUrlSlow() throws IOException {
//                    log.debug("MSNDEBUG: Lets ask the nexus what passport url to use");
                    HttpsURLConnection conn = null;
                    try {
                        conn = (HttpsURLConnection) new URL(
                                "https://nexus.passport.com/rdr/pprdr.asp")
                                .openConnection();
                        conn.setUseCaches(false);
//                        log.debug("MSNDEBUG: Got password urls: "+conn.getHeaderField("PassportURLs"));
                        Matcher matcher = passportUrlPattern.matcher(conn
                                .getHeaderField("PassportURLs"));
                        if (matcher.matches()) {
//                            log.debug("MSNDEBUG: We're going to use url: "+matcher.group(1));
                            return "https://" + matcher.group(1);
                        }
//                        log.debug("MSNDEBUG: Crap, no url found?!");
                        return null;
                    } finally {
                        if (conn != null)
                            conn.disconnect();
                    }
                }

                private String getPassportUrl() throws IOException {
//                    log.debug("MSNDEBUG: Retrieving passport url");
                    if (JmlConstants.FAST_SSL_LOGIN)
                        return "https://login.live.com/login2.srf";
                    return getPassportUrlSlow();
                }

                private String getLoginTicket(String visitUrl, String passport,
                        String password, String challengeStr)
                        throws IOException {
//                    log.debug("MSNDEBUG: Retrieving the login ticket from url "+visitUrl+" and passport "+passport);
                    HttpsURLConnection conn = null;
                    try {
                        conn = (HttpsURLConnection) new URL(visitUrl)
                                .openConnection();
                        conn.setUseCaches(false);
//                        log.debug("MSNDEBUG: Setting request property");
                        conn.setRequestProperty("Authorization",
//                                "Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in="
                                "Passport1.4 OrgVerb=GET,OrgURL="
                                        + StringUtils.urlEncode(visitUrl)
                                        + ",sign-in="
                                        + StringUtils.urlEncode(passport)
                                        + ",pwd="
                                        + StringUtils.urlEncode(password) + ","
                                        + challengeStr);
//                        log.debug("MSNDEBUG: Request property is "+conn.getRequestProperty("Authorization"));
                        switch (conn.getResponseCode()) {
                            case 200: //success
//                                log.debug("MSNDEBUG: Response code is 200, success!");
                                Matcher matcher = ticketPattern.matcher(conn
                                        .getHeaderField("Authentication-Info"));
                                if (matcher.matches()) {
                                    return matcher.group(1);
                                }
                                return null;
                            case 302: //redirect
//                                log.debug("MSNDEBUG: Response code is 302, being redirected!");
                                visitUrl = conn.getHeaderField("Location");
//                                log.debug("MSNDEBUG: Redirect to "+visitUrl);
                                return getLoginTicket(visitUrl, passport, password,
                                        challengeStr);
                            case 401: //failed
//                                log.debug("MSNDEBUG: Response code is 401, we failed?");
                                return null;
                            default:
//                                log.debug("MSNDEBUG: Response code (unknown) was "+conn.getResponseCode());
                        }
                    } finally {
                        if (conn != null) {
                            conn.disconnect();
                        }
                    }
                    return null;
                }

                @Override
                public void run()
                {
                    try
                    {
                        if(protocol.before(MsnProtocol.MSNP13))
                        {
                            OutgoingUSRAuthNS outgoing = new OutgoingUSRAuthNS(
                                    protocol);
                            //log.debug("MSNDEBUG: Time to request the login ticket for auth");
                            String ticket = getLoginTicket(getPassportUrl(),
                                    messenger.getOwner().getEmail()
                                            .getEmailAddress(),
                                    ((MsnOwnerImpl) messenger.getOwner())
                                            .getPassword(), getAuthStr());
                            if (ticket == null) {
                                ((AbstractMessenger) messenger)
                                        .fireExceptionCaught(new IncorrectPasswordException());
                                return;
                            }
                            outgoing.setTicket(ticket);
                            messenger.send(outgoing);
                        }
                        else
                        {
                            String nonce = getNonce();
                            String policy = getPolicy();

                            // must logout and throw exception or something
                            if(nonce == null)
                            {
                                ((AbstractMessenger)messenger).
                                    fireExceptionCaught(
                                        new LoginException(
                                            "Login Failed, nonce is missing!"));
                                ((AbstractMessenger)messenger).logout();

                                return;
                            }

                            MsnOwner owner = session.getMessenger().getOwner();

                            if(!(owner instanceof MsnOwnerImpl))
                                return;

                            String username = owner.getEmail().getEmailAddress();
                            String pass = ((MsnOwnerImpl)owner).getPassword();

                            SSO sso = session.createSSO(username, pass, policy, nonce);

                            String ticket = sso.getTicket();

                             // must logout and throw exception or something
                            if(ticket == null)
                            {
                                ((AbstractMessenger)messenger).
                                    fireExceptionCaught(
                                        new LoginException(
                                            "Login Failed, error making ticket!"));
                                ((AbstractMessenger)messenger).logout();
                                return;
                            }

                            MsnMessenger messenger = session.getMessenger();

                            OutgoingUSRAuthNS outgoing = new OutgoingUSRAuthNS(
                                    protocol);

                            if (ticket == null)
                            {
                                ((AbstractMessenger) messenger)
                                        .fireExceptionCaught(new IncorrectPasswordException());
                                return;
                            }
                            outgoing.setTicket(ticket);
                            messenger.send(outgoing);
                        }

                    } catch (IOException e)
                    {
                        ((AbstractMessenger) messenger).fireExceptionCaught(e);
                        messenger.logout();
                    }
                }
            }.start();
        }
    }
View Full Code Here

    protected void initMessenger(MsnMessenger messenger) {
    }

    public void start() {
        //create MsnMessenger instance
        MsnMessenger messenger = MsnMessengerFactory.createMsnMessenger(email,
                password);

        //MsnMessenger support all protocols by default
        //messenger.setSupportedProtocol(new MsnProtocol[] { MsnProtocol.MSNP8 });

        //default init status is online,
        //messenger.getOwner().setInitStatus(MsnUserStatus.BUSY);

        //log incoming message
        messenger.setLogIncoming(true);

        //log outgoing message
        messenger.setLogOutgoing(true);

        initMessenger(messenger);
        messenger.login();
    }
View Full Code Here

    @Override
  protected void messageReceived(MsnSession session) {
        super.messageReceived(session);

        MsnMessenger messenger = session.getMessenger();
        MsnMimeMessage message = null;
        try {
            message = MsnMimeMessageFactory.parseMessage(getContent());
        } catch (Exception e) {
            ((AbstractMessenger) messenger).fireExceptionCaught(e);
        }

        if (message != null) {
            MsnContactImpl contact = (MsnContactImpl) messenger
                    .getContactList().getContactByEmail(getEmail());
            if (contact == null) {
                contact = new MsnContactImpl(messenger.getContactList());
                contact.setEmail(getEmail());
                contact.setDisplayName(getDisplayName());
            }
            message.messageReceived(session, contact);
        }
View Full Code Here

  protected void messageReceived(MsnSession session) {
        super.messageReceived(session);

        MsnSwitchboard switchboard = session.getSwitchboard();
        if (switchboard != null) {
            MsnMessenger messenger = session.getMessenger();
            MsnContactImpl contact = (MsnContactImpl) messenger
                    .getContactList().getContactByEmail(getEmail());
            if (contact == null) {
                contact = new MsnContactImpl(messenger.getContactList());
                contact.setEmail(getEmail());
            }

            ((AbstractSwitchboard) switchboard).removeContact(contact);
            ((AbstractMessenger) messenger).fireContactLeaveSwitchboard(
View Full Code Here

    @Override
  protected void messageReceived(MsnSession session) {
        super.messageReceived(session);

        MsnMessenger messenger = session.getMessenger();
        MsnContactListImpl contactList = (MsnContactListImpl) messenger
                .getContactList();
        String version = getVersion();

        if (version.equals(contactList.getVersion())) {
            ((AbstractMessenger) messenger).fireContactListSyncCompleted();
        } else {
            int groupCount = getGroupCount();
            if (!protocol.before(MsnProtocol.MSNP10)) {
                groupCount++; //In MSNP8/MSNP9 will return default group
            }
            contactList.setVersion(version);
            contactList.setGroupCount(groupCount);
            contactList.setContactCount(getContactCount());
        }

       
        if (protocol.before(MsnProtocol.MSNP13)){
            //session.getContactList().processInit();
            //AbstractMessenger messenger = (AbstractMessenger)session.getMessenger();
            MsnProtocol protocol = messenger.getActualMsnProtocol();
            messenger.getOwner().setDisplayName(messenger.getOwner().getDisplayName());
           
            if (protocol.after(MsnProtocol.MSNP9)){
                OutgoingUUX uuxmessage = new OutgoingUUX(protocol);
                uuxmessage.setPersonalMessage(messenger.getOwner().getPersonalMessage());
                uuxmessage.setMachineGuid("{F26D1F07-95E2-403C-BC18-D4BFED493428}");
                messenger.send(uuxmessage);
            }
           
            OutgoingCHG message = new OutgoingCHG(protocol);
            message.setStatus(messenger.getOwner().getInitStatus());
            message.setClientId(messenger.getOwner().getClientId());
            message.setDisplayPicture(messenger.getOwner().getDisplayPicture());
            message.setFirstSend(true);
            messenger.send(message);
        }
       
    }
View Full Code Here

        if (buffer.remaining() < 3)
            return null;
        String charSequence = Charset.decode((ByteBuffer) buffer.limit(buffer
                .position() + 3));

        MsnMessenger messenger = ((MsnSession) session.getAttachment())
                .getMessenger();
        String key = charSequence.substring(0, 3);
        Class<? extends MsnIncomingMessage> c = normalMappingMap.get(key);

        MsnMessage message;
        if (c != null)
            message = getMessageInstance(c, messenger);
        else if (NumberUtils.isDigits(key))
            message = getMessageInstance(IncomingError.class, messenger);
        else
            //don't know how to parse this msg, just skip one line
            message = new IncomingUnknown(messenger.getActualMsnProtocol());

        return new WrapperMessage(message);
    }
View Full Code Here

    @Override
  protected void messageReceived(MsnSession session) {
        super.messageReceived(session);

        MsnMessenger messenger = session.getMessenger();
        MsnContactList contactList = messenger.getContactList();
        MsnMessageChain incoming = messenger.getIncomingMessageChain();
        MsnContact contact = null;

        for (MsnMessageIterator iter = incoming.iterator(); iter.hasPrevious();) {
            MsnMessage message = iter.previous();
            if (message instanceof IncomingBPR)
View Full Code Here

        if (ByteBufferUtils.indexOf(buffer, SPLIT) < 0)
            return null;
        if (buffer.remaining() < 3)
            return null;

        MsnMessenger messenger = ((MsnFileTransfer) session.getAttachment())
                .getMessenger();
        final MsnMessage message;

        byte start = buffer.get(buffer.position());
        if (start == 0 || start == 1) { //is msnftpContent
            message = new MsnftpContent(messenger.getActualMsnProtocol());
        } else {
            String key = Charset.decode((ByteBuffer) buffer.limit(buffer
                    .position() + 3));
            Class<? extends MsnftpMessage> c = mappingMap.get(key);
            if (c == null) {
View Full Code Here

    @Override
  protected void messageReceived(MsnSession session) {
        super.messageReceived(session);
        MsnSwitchboard switchboard = session.getSwitchboard();
        if (switchboard != null) {
            MsnMessenger messenger = session.getMessenger();
            MsnContactList contactList = messenger.getContactList();
            MsnContactImpl contact = (MsnContactImpl) contactList
                    .getContactByEmail(getEmail());
            if (contact == null) {
                contact = new MsnContactImpl(contactList);
                contact.setEmail(getEmail());
View Full Code Here

TOP

Related Classes of net.sf.jml.MsnMessenger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.