0

So I've been working on a programm to use postmark to send emails through a GUI. What my issue is it works and all, but I have a SubscribedList and an unsubbedList.

What I'm trying to achieve is to scan the subbed and unsubbed and then send a string of the emails containing the unsubbed removed from the subbed and send it to another variable. I've half achieved this by:

public static void getEmail() throws Exception{

File Emailpath = new File(EmailListPath);
File Unsubpath = new File("c:\\test\\PostMark\\unsubbedEmailList.txt");
FileInputStream fis = new FileInputStream(Emailpath);
InputStreamReader isr = new InputStreamReader(fis);

FileInputStream unsubInput = new FileInputStream(Unsubpath);
InputStreamReader unsubisr = new InputStreamReader(unsubInput);

Scanner readEmail = new Scanner(Emailpath);
Scanner readUnsub = new Scanner(Unsubpath);
int i = 0;
System.err.println("Subbed List: ");
while (readEmail.hasNext()) {
    //i++;
    String line = readEmail.nextLine();
    System.err.println(line);
    EmailAddress = EmailAddress+","+line; 
}
System.err.println("\nUnsubbed List: ");
while (readUnsub.hasNext()) {
    //i++;
    String line = readUnsub.nextLine();
    System.err.println(line);
    unsubbedEmailAddress = unsubbedEmailAddress+","+line; 
}
//System.err.println("\n"+EmailAddress);
unsubbedEmailAddress=unsubbedEmailAddress.substring(1, unsubbedEmailAddress.length());
EmailAddress=EmailAddress.substring(1, EmailAddress.length());
EmailAddress = EmailAddress.replaceAll(unsubbedEmailAddress,"");
System.err.println("Subbed:\n"+EmailAddress);
System.err.println("Unsubbed:\n"+unsubbedEmailAddress);
System.err.println("\nSending to:\n"+EmailAddress);

The last couple of lines half does what I want, but the unsubbed have to be in a specific order to properly remove from the subbed string.

so I was thinking something like this? Instead the String would be read in from a file but basically do the same job...

String subbed = "aaronjoyce2@gmail.com,aaronjoyce09@gmail.com,aaronscallyjoyce@gmail.com",
                unsubbed = "aaronjoyce09@gmail.com";
        String[] subbedArray, unsubbedArray, sendArray = null;

    subbedArray = subbed.split(",");
    for(int i = 0;i<=subbedArray.length -1;i++){
        //System.err.println("Subbed:");
        System.out.println(subbedArray[i]);
    }   
    System.err.println("\n");
    unsubbedArray=unsubbed.split(",");
    for(int i = 0;i<=unsubbedArray.length-1;i++){

        System.out.println(unsubbedArray[i]);
    }
    System.err.println("\n");
    for(int i = 0;i<=unsubbedArray.length-1;i++){
        int j=0;
        if(subbedArray[i].equals(unsubbedArray[j]))
            sendArray[i]= unsubbedArray[i];
        else
            for(j = 0;j<=unsubbedArray.length-1;j++){
                if(subbedArray[i].equals(unsubbedArray[j]))
                    sendArray[i]= unsubbedArray[i];
            }
        System.out.println(sendArray[i]);
    }
XtremeBaumer
  • 5,158
  • 1
  • 15
  • 44
  • so you have 2 files. one contains subbed and one unsubbed emails, but in the subbed are also the unsubbed ones and you want to remove them? – XtremeBaumer Jan 31 '17 at 13:00
  • no not remove them but send or create a new string of the subbed with unsubbed removed.. but the unsubbed remain within the sub file also think of it like vlid users but the unsubbed dont want promotional offers and newsletters etc.. – Aaron Joyce Jan 31 '17 at 14:01
  • okay here is my idea. build 2 arrays from the files. one is subbed other one unsubbed. now remove every entry from the subbed one which is contained in unsubbed one – XtremeBaumer Jan 31 '17 at 14:19
  • so i was thinking something like this ? instead the String would be read in from a file but basically do the same job.. – Aaron Joyce Jan 31 '17 at 15:50

1 Answers1

0
String subbed = "aaronjoyce2@gmail.com,aaronjoyce09@gmail.com,aaronscallyjoyce@gmail.com",
           unsubbed = "aaronjoyce09@gmail.com";
    ArrayList<String> subbedArray=new ArrayList<String>();
    ArrayList<String> unsubbedArray=new ArrayList<String>();
    ArrayList<String> sendArray=new ArrayList<String>();

    subbedArray = Arrays.asList(subbed.split(","));
    unsubbedArray =Arrays.asList(unsubbed.split(","));
    for(int i = 0;i<unsubbedArray.size();i++){
      for(int j=0;j<subbedArray.size();j++){
          if(unsubbedArray.get(i).equals(subbedArray.get(j))){
            subbedArray.remove(j);
          }
       }
    }
    sendArray=subbedArray;

this might work, but i cant test it. take it as a idea and work with it

XtremeBaumer
  • 5,158
  • 1
  • 15
  • 44