Fix inbox command
This commit is contained in:
parent
a9c4465a24
commit
e30359652c
@ -11,6 +11,7 @@ import java.security.spec.X509EncodedKeySpec;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import at.ac.tuwien.dsg.orvell.Shell;
|
import at.ac.tuwien.dsg.orvell.Shell;
|
||||||
@ -324,34 +325,34 @@ public class MessageClient implements IMessageClient, Runnable {
|
|||||||
|
|
||||||
@Command
|
@Command
|
||||||
@Override
|
@Override
|
||||||
public void inbox() throws BadPaddingException, IllegalBlockSizeException {
|
public void inbox() {
|
||||||
|
LinkedList<String> inboxMessages = new LinkedList<>();
|
||||||
String message;
|
String message;
|
||||||
logger.info("Received 'inbox' command");
|
logger.info("Received 'inbox' command");
|
||||||
message = "list";
|
message = "list";
|
||||||
this.dmapOut.println(getAesCiphertext(message));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String response = getAesPlaintext(this.dmapIn.readLine());
|
this.dmapOut.println(getAesCiphertext(message));
|
||||||
if (response.equals("ok DMAP2.0") || response.equals("ok DMAP")) {
|
String response;
|
||||||
this.dmapOut.println(getAesCiphertext(message));
|
while (!(response = getAesPlaintext(this.dmapIn.readLine())).startsWith("ok")) {
|
||||||
response = getAesPlaintext(this.dmapIn.readLine());
|
if (response.startsWith("You do not have any messages at the moment!")) {
|
||||||
|
this.shell.out().println(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
inboxMessages.add(response.split("\\s+")[0]); // Get IDs
|
||||||
}
|
}
|
||||||
String [] temp = response.split("\\s+");
|
StringBuilder result = new StringBuilder();
|
||||||
String [] help = new String[temp.length / 3];
|
for (String id : inboxMessages) {
|
||||||
int count = 0;
|
result.append("\n");
|
||||||
for (int i = 0; i < help.length; i++) {
|
this.dmapOut.println(getAesCiphertext("show " + id));
|
||||||
help[i] = temp[count];
|
result.append(getAesPlaintext(this.dmapIn.readLine()));
|
||||||
count = count + 3;
|
|
||||||
}
|
}
|
||||||
String result = "";
|
this.shell.out().println("Your Mailbox:" + result);
|
||||||
for (int i = 0; i < help.length; i++) {
|
} catch (IllegalBlockSizeException | BadPaddingException e) {
|
||||||
message = "show " + help[i];
|
logger.severe("Error during encryption/decryption");
|
||||||
this.dmapOut.println(getAesCiphertext(message));
|
e.printStackTrace();
|
||||||
result = getAesPlaintext(this.dmapIn.readLine() + "\n");
|
|
||||||
}
|
|
||||||
System.out.println("Your Mailbox: \n" + result);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("IO Exception " + e.getMessage());
|
logger.severe("Could not connect to MailboxHost " + this.mailboxHost + " on port " + this.mailboxPort);
|
||||||
|
shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user