@Override
    public void run() {
      try {
        new MessageClientService(MessageIntentService.this)
            .sendMessageToServer(message, ScheduleMessageService.class);
        if (message.hasAttachment() && !message.isAttachmentUploadInProgress()) {
          runningTaskMap.remove(getMapKey(message));
        }
        int groupSmsDelayInSec =
            MobiComUserPreference.getInstance(MessageIntentService.this).getGroupSmsDelayInSec();
        boolean isDelayRequire =
            (groupSmsDelayInSec > 0 && message.isSentViaCarrier() && message.isSentToMany());
        if (message.getScheduledAt() == null) {
          String[] toList = message.getTo().trim().replace("undefined,", "").split(",");

          for (String tofield : toList) {
            if (isDelayRequire && !message.getTo().startsWith(tofield)) {
              new Timer()
                  .schedule(
                      new MessageSenderTimerTask(
                          new MobiComMessageService(
                              MessageIntentService.this, MessageIntentService.class),
                          message,
                          tofield),
                      groupSmsDelayInSec * 1000);
            } else {
              new MobiComMessageService(MessageIntentService.this, MessageIntentService.class)
                  .processMessage(message, tofield);
            }
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
Example #2
0
  public void route(Message m) {

    if (m.getFrom() == null) {
      // local message

      if (m_lanMessageRemoteOutbox != null) m_lanMessageRemoteOutbox.route(m);

    } else if (m.getTo() == null) {
      // remote message
      if (m_uiMessageRouter != null) m_uiMessageRouter.route(m);
    } else {
      D.out("Could not route message from=" + m.getFrom() + " to=" + m.getTo());
    }
  }
 public void receiveMsg(Message msg) {
   // System.out.println(msg.getSubject() + " : " + msg.getBody());
   String subject = msg.getSubject();
   if (subject != null) {
     if (subject.equals("online")) {
       onlineUsers.addElement(new HostItem(msg.getBody()));
       displayMessage(msg.getBody() + " : Online", onlineClientAttrSet);
     } else if (subject.equals("offline")) {
       onlineUsers.removeElement(new HostItem(msg.getBody()));
       displayMessage(msg.getBody() + " : Offline", offlineClientAttrSet);
     } else if (subject.equals("eavesdrop enabled")) {
       Object[] values = jListOnlineUsers.getSelectedValues();
       if (values == null) return;
       for (int i = 0; i < values.length; i++) {
         ((HostItem) values[i]).eavesDroppingEnabled = true;
       }
       jListOnlineUsers.updateUI();
     } else if (subject.equals("eavesdrop disabled")) {
       Object[] values = jListOnlineUsers.getSelectedValues();
       if (values == null) return;
       for (int i = 0; i < values.length; i++) {
         ((HostItem) values[i]).eavesDroppingEnabled = false;
       }
       jListOnlineUsers.updateUI();
     } else if (subject.equals("globaleavesdrop enabled")) {
       displayMessage("Global Eavesdropping Enabled", onlineClientAttrSet);
     } else if (subject.equals("globaleavesdrop disabled")) {
       displayMessage("Global Eavesdropping Disabled", offlineClientAttrSet);
     } else {
       String to = msg.getTo();
       String from = msg.getFrom() == null ? "server" : msg.getFrom();
       String body = msg.getBody() != null ? msg.getBody() : "";
       if (jTextFieldUser.getText().equals(to)) { // this message is sent to us
         displayMessage(subject, from, body, incomingMsgAttrSet);
       } else { // this is an eavesdrop message
         displayMessage(subject, to, from, body, eavesdropAttrSet);
       }
     }
   } else {
     subject = "";
     String to = msg.getTo();
     String from = msg.getFrom() == null ? "server" : msg.getFrom();
     String body = msg.getBody() != null ? msg.getBody() : "";
     if (jTextFieldUser.getText().equals(to)) { // this message is sent to us
       displayMessage(subject, from, body, incomingMsgAttrSet);
     } else { // this is an eavesdrop message
       displayMessage(subject, to, from, body, eavesdropAttrSet);
     }
   }
 }
Example #4
0
  @Override
  public void run() {
    try {
      login(scanner.nextLine());

      while (true) {
        Message m = new Message(scanner.nextLine());

        switch (m.getTyp()) {
          case Message.TYP_TO_ALL:
            server.anAlle("2::" + m.getFrom() + ":" + m.getContent() + txt_ende);
            server.liste_senden();
            break;
          case Message.TYP_TO_ONE:
            if (!server.sendAn(
                m.getTo(), "3:" + m.getTo() + ":" + m.getFrom() + ":" + m.getContent()))
              // todo fehlermeldung an sender;
              ;
            break;

          default:
            throw new MessageException("alle blöd");
        }
      }

    } catch (NoSuchElementException e) {

      try {
        client.close();
        server.anAlle("2::SERVER:" + name + " has disconnected." + txt_ende);
        Window.listenModel.removeElement(name);
        System.out.println(name + " entfernt");
        server.liste_senden();

      } catch (IOException e1) {
        e1.printStackTrace();
      }

    } catch (Exception e) {
      try {
        client.close();
        server.anAlle("2::SERVER:" + name + " has disconnected." + txt_ende);
        Window.listenModel.removeElement(name);
        System.out.println(name + " entfernt");
        server.liste_senden();
      } catch (IOException e1) {
      }
    }
  }
  @Test
  public void invalidAddressesShouldBeAllowed() throws Exception {
    String headers =
        "From: user <userdomain>\n"
            + "To: user1 <user1domain>, user2 <user2domain>\n"
            + "Cc: usercc <userccdomain>\n"
            + "Bcc: userbcc <userbccdomain>\n"
            + "Subject: test subject\n";
    MetaDataWithContent testMail =
        MetaDataWithContent.builder()
            .uid(MessageUid.of(2))
            .flags(new Flags(Flag.SEEN))
            .size(headers.length())
            .internalDate(INTERNAL_DATE)
            .content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
            .attachments(ImmutableList.of())
            .mailboxId(MAILBOX_ID)
            .messageId(MessageId.of("user|box|2"))
            .build();

    Message testee = messageFactory.fromMetaDataWithContent(testMail);

    Emailer user = Emailer.builder().name("user").email("userdomain").allowInvalid().build();
    Emailer user1 = Emailer.builder().name("user1").email("user1domain").allowInvalid().build();
    Emailer user2 = Emailer.builder().name("user2").email("user2domain").allowInvalid().build();
    Emailer usercc = Emailer.builder().name("usercc").email("userccdomain").allowInvalid().build();
    Emailer userbcc =
        Emailer.builder().name("userbcc").email("userbccdomain").allowInvalid().build();

    assertThat(testee.getFrom()).contains(user);
    assertThat(testee.getTo()).contains(user1, user2);
    assertThat(testee.getCc()).contains(usercc);
    assertThat(testee.getBcc()).contains(userbcc);
  }
 /**
  * Puts a message in the database Note: the timestamp will be stored as the current time at which
  * this method is called.
  */
 public void storeMessage(Message message) {
   con.updateDB(
       "INSERT INTO "
           + MESSAGES
           + " VALUES ( \""
           + message.getFrom()
           + "\", \""
           + message.getTo()
           + "\", \""
           + message.getBody()
           + "\", "
           + null
           + ", "
           + message.getType()
           + ")");
 }
Example #7
0
 protected void checkUser(Message message) {
   if (!message.getTo().equals(getUserName())) {
     throwNotForThisUser();
   }
 }
Example #8
0
  /** {@inheritDoc} */
  @Override
  public void send(Message msg) throws IllegalArgumentException, IOException {
    // Sanity checks
    if (msg.getTo() == null || msg.getSubject() == null || msg.getBody() == null) {
      throw new IllegalArgumentException("Message has no destination or no subject");
    }

    ArrayList<String> cmd = new ArrayList<String>();
    // mailx -b bcc -c cc -s subj to-addr to-addr
    cmd.add(mailer);
    if (msg.getBcc() != null) {
      cmd.add("-b");
      cmd.add(join(msg.getBcc(), ","));
    }
    if (msg.isHtml()) {
      cmd.add("-a");
      cmd.add("Content-type: text/html;");
    }
    if (msg.getCc() != null) {
      cmd.add("-c");
      cmd.add(join(msg.getCc(), ","));
    }
    cmd.add("-s");
    cmd.add(msg.getSubject());

    cmd.addAll(msg.getTo());

    if (msg.getSender() != null) {
      // Sender in the headers:
      cmd.add("-a");
      cmd.add(String.format("From: %s", msg.getSender()));
      // sendmail options are denoted with a double-hyphen
      cmd.add("--");
      // Envelope Sender
      cmd.add("-f");
      cmd.add(msg.getSender());
    }

    Log.i(LOG_TAG, String.format("About to send email with command: %s", cmd));
    String[] strArray = new String[cmd.size()];
    Process mailerProc = run(cmd.toArray(strArray));
    BufferedOutputStream mailerStdin = new BufferedOutputStream(mailerProc.getOutputStream());
    /* There is no such thing as a "character" in the land of the shell; there are only bytes.
     * Here, we convert the body from a Java string (consisting of characters) to a byte array
     * encoding each character with UTF-8.  Each character will be represented as between one
     * and four bytes apiece.
     */
    mailerStdin.write(msg.getBody().getBytes("UTF-8"));
    mailerStdin.flush();
    mailerStdin.close();

    int retValue;
    try {
      retValue = mailerProc.waitFor();
    } catch (InterruptedException e) {
      // ignore, but set retValue to something bogus
      retValue = -12345;
    }
    if (retValue != 0) {
      Log.e(LOG_TAG, String.format("Mailer finished with non-zero return value: %d", retValue));
      BufferedInputStream mailerStdout = new BufferedInputStream(mailerProc.getInputStream());
      StringBuilder stdout = new StringBuilder();
      int theByte;
      while ((theByte = mailerStdout.read()) != -1) {
        stdout.append((char) theByte);
      }
      Log.e(LOG_TAG, "Mailer output was: " + stdout.toString());
    } else {
      Log.v(LOG_TAG, "Mailer returned successfully.");
    }
  }