Results 1 to 11 of 11
  1. #1
    buggedup is offline Member
    Join Date
    Apr 2011
    Posts
    19
    Rep Power
    0

    Default Getting related data

    I am using the javamail api to get unread mails. I get all the recipients in the mail who are in To and Cc and their corresponding message numbers in arrays. Now another class uses this data. My problem is that how can i get recipients in To and Cc in one particular mail.

    Once run, the arrays get populated with all the recipients in To and Cc of all the messages that were unread.

    How can i find out the recipients of To and Cc in one mail as they are all separate arrays. Is there anything similar to Structure in C ?

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Getting related data

    Quote Originally Posted by buggedup View Post
    Once run ...
    Once what is run? code you wrote or a third party API?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default Re: Getting related data

    Java programming language has no structs, but you can simply create a Java bean (POJO), a class with properties and the corresponding getters and setters.

  4. #4
    buggedup is offline Member
    Join Date
    Apr 2011
    Posts
    19
    Rep Power
    0

    Default Re: Getting related data

    run is execute the code that i have written.

  5. #5
    buggedup is offline Member
    Join Date
    Apr 2011
    Posts
    19
    Rep Power
    0

    Default Re: Getting related data

    Quote Originally Posted by wsaryada View Post
    Java programming language has no structs, but you can simply create a Java bean (POJO), a class with properties and the corresponding getters and setters.
    I tried doing so i have 2 string arrays for To and Cc and an int array for the msg numbers. But how can i know that which To entry and which Cc entry belongs to which msg number?

  6. #6
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default Re: Getting related data

    Wrap your data is a simple POJO (Plain Old Java Object).

    Java Code:
    public class Message
    {
        private int messageId;
        private String to;
        private String cc;
    
        public Message() {
        }
    
        public void setMessageId(int messageId) {
            this.messageId = messageId;
        }
    
        public int getMessageId() {
            return messageId;
        }    
    
        // others property setters / getters
    }
    Then you can use it like:

    Java Code:
    public static void main(String[] args) {
        Message[] messages = new Messages[10];
    
        Message message = new Message();
        message.setMessageId(1);
        message.setTo("email@example.com");
        message.setCc("email@example.com");
        messages[0] = message;
    }

  7. #7
    buggedup is offline Member
    Join Date
    Apr 2011
    Posts
    19
    Rep Power
    0

    Default Re: Getting related data

    I think that i am not able to explain the problem here -

    I have a Class MailReader in which i get the recipientsInTo and recipientsInCc and the messageNumbers for all the unread messages. So there are four strings -

    Java Code:
    String[] recipientsTo;
    String[] recipientsCc;
    int[]    msgIDTo;
    int[]    msgIDCc;
    i have 2 strings for msgID because when i insert one mail address in the recipientsTo then i insert it's msgID in msgIDTo as well. Similar with recipientsCc. I have setters to set the instance variables.

    Suppose i have 3 unread mails. Now for each execution recipientsTo is filled with all the recipients who were in To for all the 3 messages. Similarly with recipients Cc as well. msgID also populates correspondingly.

    Now a different class calls the getters of the MailReader Class. So it gets all the recipientsTo and recipientsCc of all the 3 messages. It also gets the two msgID strings. Now to find out which occurrences of recipientsTo and recipientsCc belong to one mail, I am using the msgID strings.

    Java Code:
    for(int i=0; i<loop; i++)
    if(msgIDTo[i] == msgIDCc[i]){
        for(int j=0; j<loop; j++){
    		if(msgNumTo[j] == msgNumTo[j+1]){
    		recipientToOneMail[j] = recipientInTo[j];
    		recipientCcOneMail[j] = recipientInCc[j];
        }
    else{}
    
    }
    This is how i am thinking to get the recipientTo and recipientCc of each mails. But i am currently facing some difficulty in how to do this.
    Is my approach correct or is there any other ideal way to do this. Hope i am clearer this time.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: Getting related data

    Quote Originally Posted by wsaryada View Post
    Java programming language has no structs
    Yes it has; they're called classes.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,842
    Rep Power
    19

    Default Re: Getting related data

    Your model strikes me as being incorrect.
    Looks to me like you should be doing something similar to wsaryada's example above.

    Where are those 4 arrays coming from?
    How are they created?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    buggedup is offline Member
    Join Date
    Apr 2011
    Posts
    19
    Rep Power
    0

    Default Re: Getting related data

    I create and populate those arrays in the MailReader class by reading each mail from the inbox.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,842
    Rep Power
    19

    Default Re: Getting related data

    So you, at one point, know which mail is associated to which 'to' and 'cc'...so create a class (as suggested above) that models that.
    This is an OO language after all.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 11
    Last Post: 09-21-2012, 09:33 AM
  2. Replies: 1
    Last Post: 04-27-2012, 07:14 AM
  3. Related to ...
    By siva_vs_siva in forum New To Java
    Replies: 2
    Last Post: 09-09-2010, 05:20 PM
  4. Related to JTrees
    By swathi in forum AWT / Swing
    Replies: 1
    Last Post: 11-21-2008, 06:50 AM
  5. Jboss related.
    By CharanZ in forum Introductions
    Replies: 0
    Last Post: 10-27-2008, 10:09 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •