Exemple #1
0
 private void showMessage() {
   final Token idToken = getArguments().get(0);
   final int id = validateId(idToken);
   final Message message = getInbox().get(id);
   println(String.format("Id: %d", id));
   println(String.format("From: %s", message.getFrom().toString()));
   println(String.format("Body: %s", message.getBody()));
   println();
   message.markAsRead();
 }
Exemple #2
0
 private String formatMessage(final Message message, final int id) {
   final StringBuilder buffer = new StringBuilder();
   buffer.append(formatId(id));
   buffer.append(formatUnread(message));
   buffer.append(formatFrom(message));
   buffer.append(message.getBody());
   return buffer.toString();
 }
Exemple #3
0
  private void answerMessage() {
    final Token idToken = getArguments().get(0);
    final int id = validateId(idToken);
    final Message message = getInbox().get(id);
    final Token messageBodyToken = getArguments().get(1);
    final Message answer =
        Messaging.newTextMessage(newLocalAddress(), message.getFrom(), messageBodyToken.asString());

    try {
      Messaging.newSender().send(answer);
    } catch (IOException ex) {
      throw new CommandRuntimeException(
          String.format("Can't send message to %s!", message.getFrom()), ex);
    }

    answer.markAsRead();
    getApplicationContext().getOutbox().put(answer);
  }
Exemple #4
0
 private String formatFrom(Message message) {
   return StringUtils.rightPad(message.getFrom().toString(), THIRD_COLUMN_PAD);
 }
Exemple #5
0
 private String formatUnread(final Message message) {
   final String unread = message.isUnread() ? "yes" : "no";
   return StringUtils.rightPad(unread, SECOND_COLUMN_PAD);
 }