Package net.rim.blackberry.api.mail

Examples of net.rim.blackberry.api.mail.Folder


        //add the file to the multipart
        mp.addBodyPart(tbp);
        mp.addBodyPart(sap);

        //create a message in the sent items folder
        Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);

        Message message = new Message(folders[0]);
        Address toAdd = new Address(email,"my email");
        Address toAdds[] = new Address[1];
        toAdds[0] = toAdd;
View Full Code Here


                                                _listenerHash.put(emailService, _vec);
                                          }// end if (_listenerHash.get(emailService)==null)

                                            Store store = session.getStore();
                                            Folder[] folders = store.list(Folder.INBOX);
                                            Folder inbox = folders[0];
                                            inbox.addFolderListener(_listener);
                                           
                                           // callback.invoke(null, new Object[] { "added listener" });
                                      }// end if (session != null)
                                    }//end if (sc != null)
View Full Code Here

        }

        boolean bFound = false;
        int size = v.size();
        for( int i = 0; i < size; ++i ) {
            Folder folder = (Folder) v.elementAt( i );
            if( folder.getId() == f.getId() ) {
                String f1 = folder.getFullName();
                String f2 = f.getFullName();
                if( f1.equals( f2 ) ) {
                    bFound = true;
                    break;
                }
View Full Code Here

         *
         * @see ScriptableFunctionBase#execute(Object, Object[])
         */
        public Object execute( Object thiz, Object[] innerArgs ) throws Exception {
            if( _message == null ) {
                Folder folderNew = getFirstFolder( MessageUtility.folderIdToFolderType( _outer.getFolder() ) );

                if( folderNew == null ) {
                    throw new FolderNotFoundException( "" );
                }

                _message = new Message( folderNew );
            }

            // toRecipients, ccRecipients, bccRecipients
            _message.removeAllRecipients( Message.RecipientType.TO );
            _message.removeAllRecipients( Message.RecipientType.CC );
            _message.removeAllRecipients( Message.RecipientType.BCC );

            String value = (String) _outer.getField( MessageObject.FIELD_TORECIPIENTS );
            Address[] addresses = MessageUtility.stringToAddresses( value );
            if( addresses.length > 0 ) {
                _message.addRecipients( Message.RecipientType.TO, addresses );
            }

            value = (String) _outer.getField( MessageObject.FIELD_CCRECIPIENTS );
            addresses = MessageUtility.stringToAddresses( value );
            if( addresses.length > 0 ) {
                _message.addRecipients( Message.RecipientType.CC, addresses );
            }

            value = (String) _outer.getField( MessageObject.FIELD_BCCRECIPIENTS );
            addresses = MessageUtility.stringToAddresses( value );
            if( addresses.length > 0 ) {
                _message.addRecipients( Message.RecipientType.BCC, addresses );
            }

            // subject, body
            value = (String) _outer.getField( MessageObject.FIELD_SUBJECT );
            _message.setSubject( value );

            value = (String) _outer.getField( MessageObject.FIELD_BODY );
            _message.setContent( value );

            // priority
            int priority = _outer.getPriority();
            byte p = MessageUtility.JSPriorityToMessagePriority( priority );
            _message.setPriority( p );

            Folder folder = _message.getFolder();
            folder.appendMessage( _message );

            // from and replyTo
            String from = _serviceConfig.getEmailAddress();
            _outer.setValue( MessageObject.FIELD_FROM, from );
            _outer.setValue( MessageObject.FIELD_REPLYTO, from );
View Full Code Here

            if( _message == null ) {
                throw new MessagingException( "Message item not found." );
            }

            Folder folder = _message.getFolder();
            folder.deleteMessage( _message );
            _message = null;

            return UNDEFINED;
        }
View Full Code Here

            for( int i = folders.length - 1; i >= 0; --i ) {
                if( s != null && folders[ i ].getFullName().indexOf( ServiceConfiguration.NO_SERVICE_BOOK ) != -1 ) {
                    continue;
                }

                Folder folder = folders[ i ];
                Message[] messages = folder.getMessages();

                for( int j = 0; j < messages.length; j++ ) {
                    Message m = messages[ j ];
                    MessageObject message = new MessageObject( m, s );
                    if( testable != null ) {
View Full Code Here

     *         null: item is silently ignored (with status 200 to the server)
     * @throws DataAccessException
     */
    public Record setRecord(Record record, boolean modify) throws DataAccessException {
       
        Folder folder = null;
        char type = ' '; // [I]nbox [O]utbox [D]raft [T]rash [S]ent
        String locURI = record.getKey();
        String mail = record.getUid();
      
        try {
            // Get mail message store for the default inistance
            Store store = Session.getDefaultInstance().getStore();
            if (locURI.startsWith("I/")) {
                Folder[] folders = store.list(Folder.INBOX);
                printFolderInfo(folders);
                folder = folders[0];
                type = 'I';
            }
            else if (locURI.startsWith("O/")) {
                Folder[] folders = store.list(Folder.OUTBOX);
                printFolderInfo(folders);
                folder = folders[0];
                type = 'O';
            }
            else if (locURI.startsWith("D/")) {
                Folder[] folders = store.list(Folder.DRAFT);
                printFolderInfo(folders);
                folder = folders[0];
                type ='D';
            }
            else if (locURI.startsWith("S/")) {
                Folder[] folders = store.list(Folder.SENT);
                printFolderInfo(folders);
                folder = folders[0];
                type = 'S';
            }
            else if (locURI.startsWith("T/")) {
                StaticDataHelper.log("[INFO] Trash message: discard it.");
                type ='T';
                // invalidate the key: the record is discarded
                record.setKey(null);
                return record;
            }
            else if (locURI.startsWith("ROOT/")){
                StaticDataHelper.log("[INFO] Folder info from server: not managed at the moment.");
                // invalidate the key: the record is discarded
                record.setKey(null);
                return record;
            }
            else {
                StaticDataHelper.log("[ERROR] Invalid folder Id from server: " + locURI);
                throw new DataAccessException("Invalid folder Id from server");
            }
        }
        catch (Exception e) {
            StaticDataHelper.log("[EMAIL]Exception in MailDataStore.setRecord(:Record, :boolean): " + e.toString());
            throw new DataAccessException(e);
        }

        // What if the server id contains another '/' ?
        //String[] messageID = new StringUtil().split(locURI, "/");
        String messageID = locURI.substring(2);
       
        MessageIDStore messageIDStore = new MessageIDStore();
       
        if (! (messageIDStore.checkIsDataThere(locURI) ||
               checkIsDataThere(messageID, Constants.ITEMSKEY)) ) {
              
            Message msg = mailParser.parseMessage(mail, locURI);

            // Set the message flags depending on the message type
            switch(type) {
                case 'I':       // Inbox
                    /*
                     * Sets the message status as an inbound (received) message:
                     * without using this method, the incoming message is shown
                     * in the Outbox instead of the Inbox
                     */
                    msg.setInbound(true);
                   
                    /*
                     * Indicates that the message has been received successfully
                     */
                    msg.setStatus(Message.Status.RX_RECEIVED, 1);
                   
                    /*
                     * This lets the user to answer to the message
                     */
                    msg.setFlag(Message.Flag.REPLY_ALLOWED, true);
                    break;
                case 'S':       // Sent
                    msg.setStatus(Message.Status.TX_SENT, 1);
                    break;
                case 'D':       // Draft
                    msg.setFlag(Message.Flag.SAVED_THEN_ORPHANED, true);
                    break;
                case 'T':       // Trash
                    // FIXME: is it possible to store a message in the trash?
                    //        Shall we just silently discard this?
                    break;
            }
            // Save the message to the correct folder
            folder.appendMessage(msg);
            // XXX: why this conversion?
            Integer msgId = new Integer(msg.getMessageId());
            String key = new String(type + "/" + msgId.toString());
            // Set record key
            record.setKey(key);
View Full Code Here

     * Delete a record from the folder.
     * @param record
     * @throws DataAccessException
     */
    public void deleteRecord(Record record) throws DataAccessException {
        Folder folder = null;
        String locURI = record.getKey();
                       
        String[] serverMessageID = new StringUtil().split(locURI,"/");
                   
        MessageIDStore messageIDStore = new MessageIDStore();
   
        int messageID;
   
        String messageIDfromRS = messageIDStore.getClientId(locURI);
   
        if (messageIDfromRS == null) {
            messageID = Integer.parseInt(serverMessageID[1]);
        } else {
            messageID = Integer.parseInt(messageIDfromRS);
            messageIDStore.delete(locURI);
        }
       
        Message todelete = Store.getMessage(messageID);
       
        if (todelete != null) {
            folder = todelete.getFolder();
            folder.deleteMessage(todelete);
            deleteData(new Integer(todelete.getMessageId()).toString(),Constants.ITEMSKEY);
        } else {
            try {
                Store store = Session.getDefaultInstance().getStore();
                Folder[] folders = store.list();
           
                for (int index = 0; index < folders.length; index++) {
                    Folder f = folders[index];
                    Message[] mailMsg = f.getMessages();
                   
                    if (mailMsg != null) {
                        for (int i=0; i < mailMsg.length; i++) {
                            if ( mailMsg[i].getMessageId() ==  messageID) {
                                f.deleteMessage(mailMsg[i])
                            }
                        }  
                    }
                }
            } catch (Exception e) {
View Full Code Here

       
        final Message mailMessage = e.getMessage();
        StaticDataHelper.log("\n[MSG]Properties of this message:");
        MailDataStore.printMessageInfo(mailMessage);
       
        Folder folder = mailMessage.getFolder();
        int folderType = folder.getType();
        MailDataStore.printFolderInfo(folder);
       
        switch (mailMessage.getStatus()) {
            // If it's composing, it's a draft
            case Message.Status.TX_COMPOSING:           
View Full Code Here

            inSynchronize = true;       
            removeMailListener();
            StaticDataHelper.log("Message Removed");
           
            Message mailMessage = e.getMessage();
            Folder folder = mailMessage.getFolder();
               
            try {   
                StaticDataHelper.log("[DELMAIL]Starting Message Processing Thread");
                String strFolder = null;
               
                if (mailMessage.isSet(Message.Flag.SAVED_THEN_ORPHANED)) {
                    strFolder = "D";
                } else {
                    if(folder.getFullName().indexOf("Outbox") >= 0) {
                        strFolder = "O";
                    }
                    else if (folder.getFullName().indexOf("Inbox") >= 0) {
                        strFolder = "I";
                    }
                }
               
                DataStore dataStore = DataStore.getDataStore(Configuration.mailSourceUri);
View Full Code Here

TOP

Related Classes of net.rim.blackberry.api.mail.Folder

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.