Example #1
0
  public static void main(String[] args) throws Exception {
    // Create and configure HTTPS client
    Client client = new Client(new Context(), Protocol.HTTPS);
    Series<Parameter> parameters = client.getContext().getParameters();
    parameters.add("truststorePath", "certs/client-truststore.jks");
    parameters.add("truststorePassword", "password");
    parameters.add("truststoreType", "JKS");

    // Create and configure client resource
    ClientResource clientResource =
        new ClientResource("https://localhost:8183/accounts/chunkylover53/mails/123");
    clientResource.setNext(client);

    // Preemptively configure the authentication credentials
    ChallengeResponse authentication =
        new ChallengeResponse(ChallengeScheme.HTTP_BASIC, "chunkylover53", "pwd");
    clientResource.setChallengeResponse(authentication);

    // Communicate with remote resource
    MailResource mailClient = clientResource.wrap(MailResource.class);
    Mail m = mailClient.retrieve();
    System.out.println("Subject: " + m.getSubject());
    System.out.println("Content: " + m.getContent());

    // Store HTTPS client
    client.stop();
  }
Example #2
0
 public SendEmailAsyncTask() {
   String[] toArr = {"*****@*****.**"};
   m.setTo(toArr);
   m.setFrom(sender);
   m.setSubject(subject);
   m.setBody(textMessage);
 }
 /** Test of setAttachement method, of class Mail. */
 @Test
 public void testSetAttachement() {
   System.out.println("setAttachement");
   File[] attachement = null;
   Mail instance = new Mail();
   instance.setAttachement(attachement);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
 /** Test of setDate method, of class Mail. */
 @Test
 public void testSetDate() {
   System.out.println("setDate");
   Date date = null;
   Mail instance = new Mail();
   instance.setDate(date);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
 /** Test of setTo method, of class Mail. */
 @Test
 public void testSetTo() {
   System.out.println("setTo");
   String to = "";
   Mail instance = new Mail();
   instance.setTo(to);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
Example #6
0
 public Mail createMail() {
   Mail m = new Mail(this);
   m.setFrom(m_csAddressFrom);
   for (int i = 0; i < m_arrAddressTo.size(); i++) {
     String add = m_arrAddressTo.get(i);
     m.addTo(add);
   }
   return m;
 }
 /** Test of getAttachement method, of class Mail. */
 @Test
 public void testGetAttachement() {
   System.out.println("getAttachement");
   Mail instance = new Mail();
   File[] expResult = null;
   File[] result = instance.getAttachement();
   assertArrayEquals(expResult, result);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
 /** Test of getTo method, of class Mail. */
 @Test
 public void testGetTo() {
   System.out.println("getTo");
   Mail instance = new Mail();
   String expResult = "";
   String result = instance.getTo();
   assertEquals(expResult, result);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
 /** Test of hashCode method, of class Mail. */
 @Test
 public void testHashCode() {
   System.out.println("hashCode");
   Mail instance = new Mail();
   int expResult = 0;
   int result = instance.hashCode();
   assertEquals(expResult, result);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
Example #10
0
 public static void main(String[] args) {
   Mail mail = new Mail();
   EmailBuilder emailBuilder =
       new EmailBuilder(EmailProvider.NetEase_163)
           .from(System.getenv("from"))
           .token(System.getenv("token"))
           .to(System.getenv("to"))
           .content("Say something")
           .title("Welcome Letter");
   mail.sendEmail(emailBuilder);
 }
 /** Test of equals method, of class Mail. */
 @Test
 public void testEquals() {
   System.out.println("equals");
   Object obj = null;
   Mail instance = new Mail();
   boolean expResult = false;
   boolean result = instance.equals(obj);
   assertEquals(expResult, result);
   // TODO review the generated test code and remove the default call to fail.
   fail("The test case is a prototype.");
 }
Example #12
0
  public void envoiMail() {

    mail.setCorp(
        "hi , "
            + pers.getNom()
            + " "
            + pers.getPrenom()
            + " Ask you if you like to participate in his new Event ");
    mail.setTo(pers.getMail());
    mail.send();
    FacesMessage message =
        new FacesMessage(FacesMessage.SEVERITY_INFO, "Confirmation Msg", "Invitation sent.");
    RequestContext.getCurrentInstance().showMessageInDialog(message);
  }
Example #13
0
 @Test
 public void testFindMessageByIdBad() throws MessagingException {
   Folder f = mock(Folder.class);
   target.mFolder = f;
   Message m1 = mock(Message.class);
   Message m2 = mock(Message.class);
   Message m3 = mock(Message.class);
   when(m1.getHeader(MESSAGE_ID_HEADER)).thenReturn(new String[] {"bleah"});
   when(m2.getHeader(MESSAGE_ID_HEADER)).thenReturn(new String[] {"meh"});
   when(m3.getHeader(MESSAGE_ID_HEADER)).thenReturn(new String[] {"three"});
   when(f.getMessages()).thenReturn(new Message[] {m1, m2, m3});
   Message message = target.findMessageById(WANTED_MESSAGE_ID);
   assertNull(message);
 }
Example #14
0
  public synchronized void sendMail(Mail m) throws MessagingException {

    MimeMessage message = new MimeMessage(session);
    DataHandler handler =
        new DataHandler(new ByteArrayDataSource(m.getBody().getBytes(), "text/plain"));
    message.setSender(new InternetAddress(m.getSender()));
    message.setSubject(m.getSubject());
    message.setDataHandler(handler);
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(m.getRecipient()));
    Transport tr = session.getTransport("smtp");
    tr.connect(user, password);
    tr.send(message);
    tr.close();
  }
Example #15
0
 @Override
 public void run() {
   long beforeTime = System.currentTimeMillis();
   synchronized (mail) {
     while (mail.getText() == null)
       try {
         mail.wait();
       } catch (Exception e) {
       }
   }
   String name = Thread.currentThread().getName();
   long afterTime = System.currentTimeMillis();
   System.out.format(
       "%s MailServer has got: [%s] in %d ms after start",
       name, mail.getText(), (afterTime - beforeTime));
 }
Example #16
0
  @Test
  public void testDisplayName() throws Exception {

    Properties props = System.getProperties();
    Session session = Session.getDefaultInstance(props);

    Mail mail = new Mail();
    mail.setContent("content");
    mail.setSubject("subject");
    mail.setReceipts(Arrays.asList("*****@*****.**"));

    List<Message> messages = mail.createMessages(session);
    String[] address = messages.get(0).getFrom()[0].toString().split("<");

    assertEquals("Inspector Gadget", address[0].trim());
  }
Example #17
0
 public static void main(String[] args) {
   try {
     Mail ml = new Mail();
     String rtn =
         ml.sendMailProc(
             "***@***.***",
             "テスト川テスト男",
             "***@***.***",
             "テスト山テスト子",
             "aa",
             "cc",
             "E:/github/workj/Mail.java");
     System.out.println(rtn);
   } catch (Exception e) {
     System.out.println(e.toString());
   }
 }
    @Override
    protected String doInBackground(String... params) {
      Mail m = new Mail(Secrets.senderEmail, Secrets.senderPassword);

      String address = (params[0].equals("")) ? "*****@*****.**" : params[0];

      String[] toArr = {address};
      m.setTo(toArr);
      m.setFrom(Secrets.senderEmail);
      m.setSubject("Network Traffic Log");
      m.setBody("Email body.");

      String[] attachments = {"log1.txt", "error.txt", "fail.txt"};

      try {
        for (String attachment : attachments) {
          String path = "/data/local/Warden/" + attachment;
          if (fileExists(path)) {
            m.addAttachment(path);
          } else {
            Log.e("Network Warden", "Attachment file doesn't exist: " + path);
          }
        }
        m.send();
      } catch (MessagingException e) {
        Log.e("Network Warden", "Could not send email", e);
        return "Could not send email";
      }
      return "Email sent!";
    }
Example #19
0
    @Override
    protected Boolean doInBackground(Void... params) {

      try {
        if (m.send()) {
          enviou = true;
        }
      } catch (Exception e) {
        enviou = false;
        Log.e("MainActivity", "Could not send email", e);
      }
      return null;
    }
Example #20
0
  @Test
  public void testCreateMessage() throws Exception {

    Properties props = System.getProperties();
    Session session = Session.getDefaultInstance(props);
    Mail mail = new Mail();
    mail.setContent("content");
    mail.setSubject("subject");
    mail.setReceipts(Arrays.asList("*****@*****.**"));

    List<Message> messages = mail.createMessages(session);

    assertEquals(1, messages.size());
    assertEquals(mail.getSubject(), messages.get(0).getSubject());
  }
Example #21
0
 public void startGame() {
   /*This is the method which is called by goButtonActionPerformed.
   It calls for the consturction of the Deal and Mail decks, along with the
   Board and StatWindow. It also contructs the Players, one after another,
   using a for loop to determine how many are to be created. Finally, it
   runs the game, calling takeYourTurn in player.*/
   devMode = false;
   toDeal = new Deal(this);
   toMail = new Mail(this);
   toBoard = new Board();
   // toStatWindow = new StatWindow(noOfPlayers, noOfMonths);
   System.out.println("Setting up the game...");
   toPlayer = new Player[noOfPlayers];
   for (int index = 0; index < noOfPlayers; index++) {
     toPlayer[index] = new Player(this, toBoard, index, toMail, toDeal);
   }
   toGameUI = new GameUI(noOfPlayers, this, toDeal, toMail, toBoard);
   for (int index = 0; index < noOfPlayers; index++) {
     toPlayer[index].setGameUI(toGameUI);
   }
   toDeal.updateCards(this);
   toMail.updateCards(this);
   toUIThread.setToGameUI(toGameUI);
   finished = false;
   toUIThreadsThread.start();
   toGameUI.distributeStartingMoney();
   this.passString("Setting up the game");
   index++;
   jackpot = 0;
   ready = true;
   while (!finished) {
     for (int index = 0; index < noOfPlayers; index++) {
       if (!toPlayer[index].finished) {
         toPlayer[index].takeYourTurn();
       }
     }
   }
 }
  public static void main(String[] args) throws IOException {

    System.out.println(
        (new Date()).toString()
            + " Starting RSS server on directory "
            + System.getProperty("user.dir"));

    // set time interval between RSS pulls
    long minute = 60000;
    long sleepFor = minute * 30;
    int prevHr = 25;
    int hr = 0;

    // load the rss feeds list
    String inFile = "rssFeedsList.txt";
    BufferedReader inputFile = null;
    ArrayList<String> rssFeeds = new ArrayList<String>();
    String line = "";
    inputFile = new BufferedReader(new FileReader(inFile));
    while ((line = inputFile.readLine()) != null) {
      rssFeeds.add(line);
    }
    int rssCnt = rssFeeds.size();
    inputFile.close();

    // kick off all of the RSS feed collector threads using a thread pool and get stock quotes
    try {
      while (true) {
        System.out.println((new Date()).toString() + " Generating worker threads");
        ExecutorService executor = Executors.newFixedThreadPool(NTHREDS);
        List<Future<Long>> list = new ArrayList<Future<Long>>();
        String delimiter = ",";

        String tblName = "quotes";
        HBaseTbl quotesTbl = new HBaseTbl(tblName);
        quotesTbl.getTable(tblName);

        for (String rf : rssFeeds) {
          String[] rssFeed = rf.split(delimiter);

          // create and submit an executable thread
          Callable<Long> worker = new RSSConsumer(rssFeed[0], rssFeed[1]);
          Future<Long> submit = executor.submit(worker);
          list.add(submit);
          // get a corresponding company stock quote for each rss item
          String[] lines = {"", ""};
          lines = rssFeed[0].split("-");
          String index = lines[0];
          if (index.equals("S&P500")) {
            // only get stock quotes in the S&P 500
            String quoteName = lines[1];
            try {
              Quote q = new Quote();
              int res = q.get(quoteName);
              if (res == 0) {
                q.insert(quotesTbl);
              }
            } catch (Exception e) {
              System.out.println(
                  (new Date()).toString()
                      + " Error inserting quotes "
                      + quoteName
                      + " "
                      + e.getMessage());
              // only report, try again on next pass to see if error resolves on its own
            }
          }
        }

        // get the corresponding S&P500 index and volatility quotes
        try {
          Quote q1 = new Quote();
          int res = q1.get("SPY");
          if (res == 0) {
            q1.insert(quotesTbl);
          }
          Quote q2 = new Quote();
          res = q2.get("VXX");
          if (res == 0) {
            q2.insert(quotesTbl);
          }
        } catch (Exception e) {
          System.out.println(
              (new Date()).toString() + " Error inserting Hbase quotes table" + e.getMessage());
          // only report, try again on next pass to see if error resolves on its own
        }

        // get the executor thread resulte of the RSS pulls
        System.out.println((new Date()).toString() + " Gathering worker results");
        long insertCnt = 0;
        for (Future<Long> future : list) {
          try {
            insertCnt += future.get();
          } catch (InterruptedException e) {
            e.printStackTrace();
          } catch (ExecutionException e) {
            e.printStackTrace();
          }
        }
        // System.out.println((new Date()).toString() + " " + rssCnt + " rss pulls resulted in " +
        // insertCnt + " newsItems inserts");
        // This will make the executor accept no new threads and finish all existing threads in the
        // queue
        executor.shutdown();
        // Wait for all threads are finished
        executor.awaitTermination(1, TimeUnit.SECONDS);

        // email results, row counts of the 'newsItems' table
        System.out.println((new Date()).toString() + " Emailing current newsItems counts");
        String msgTxt = "";
        // only send one e-mail per hour
        try {
          int rowCnt = 0;
          HBaseTbl tbl = new HBaseTbl("newsItems");
          tbl.getTable("newsItems");
          rowCnt = tbl.getRowCount();
          msgTxt =
              (new Date()).toString()
                  + " "
                  + rssCnt
                  + " rss pulls resulted in "
                  + insertCnt
                  + " new rows inserted into Hbase table newsItems.  \n"
                  + (new Date()).toString()
                  + " "
                  + "Current row count of HBase table newsItems is "
                  + rowCnt;
          Calendar now = Calendar.getInstance();
          hr = now.get(Calendar.MINUTE);
          System.out.println("hr = " + hr + " prevhr =  " + prevHr);
          if (hr != prevHr) {
            System.out.println((new Date()).toString() + " Emailing current newsItems counts");
            Mail sm = new Mail(args[0], args[1], args[2]);
            sm.send(msgTxt);
          } else {
            System.out.println((new Date()).toString() + " Skipping email");
          }
          prevHr = hr;
        } catch (IOException e) {
          e.printStackTrace();
        }

        System.out.println(msgTxt);
        System.out.println(
            (new Date()).toString()
                + " Finished all threads, going to sleep for "
                + (sleepFor / minute)
                + " minutes");
        Thread.sleep(sleepFor);
        System.out.println((new Date()).toString() + " Done sleeping restarting rss pull cycle");
      }
    } catch (Exception e) {
      System.out.println((new Date()).toString() + " Exception in main thread:" + e.getMessage());
    }
  }
Example #23
0
  @SuppressWarnings("unchecked")
  @Override
  public void run() {

    // 解析邮件模板配置文件,跟据mailId取得邮件模板
    Map<String, Object> map = new HashMap<String, Object>();
    // 取得模板路径
    String templatePath = StringUtils.trimToEmpty((String) map.get("location"));
    // 取得邮件默认主题
    String subject = StringUtils.trimToEmpty((String) map.get("subject"));
    // 取得邮件的发送地址
    String senderAddress = StringUtils.trimToEmpty((String) map.get("senderAddress"));
    // 取得回复地址
    String replyTo = StringUtils.trimToEmpty((String) map.get("replyTo"));
    // 取得邮件的发送人的名字
    String senderDispaly = StringUtils.trimToEmpty((String) map.get("senderDispaly"));
    mail.setSubject(StringUtils.isEmpty(mail.getSubject()) ? subject : mail.getSubject());
    mail.setSenderAddress(
        StringUtils.isEmpty(mail.getSenderAddress()) ? senderAddress : mail.getSenderAddress());
    mail.setSenderDispaly(
        StringUtils.isEmpty(mail.getSenderDispaly()) ? senderDispaly : mail.getSenderDispaly());
    mail.setReplyTo(StringUtils.isEmpty(mail.getReplyTo()) ? replyTo : mail.getReplyTo());

    // 取得内嵌资源
    Map<String, String> mapInlineResource = new HashMap<String, String>();
    // 封装内嵌资源
    if (mapInlineResource != null && !mapInlineResource.isEmpty()) {
      for (Iterator<String> it = mapInlineResource.keySet().iterator(); it.hasNext(); ) {
        // 得到内嵌资源的key
        String key = it.next();
        // 得到key对应的内嵌资源的路径
        String keyValue = mapInlineResource.get(key);
        mail.addAttachs(getMailAttachByFilePath(key, keyValue));
      }
    }
    // 取得附件资源
    Map<String, String> mapAttach = (Map<String, String>) map.get("attach");
    // 封装附件资源
    if (mapAttach != null && !mapAttach.isEmpty()) {
      for (Iterator<String> it = mapAttach.keySet().iterator(); it.hasNext(); ) {
        // 得到内嵌资源的key
        String fileName = it.next();
        // 得到key对应的内嵌资源的路径
        String filePath = mapAttach.get(fileName);
        mail.addResource(getMailAttachByFilePath(fileName, filePath));
      }
    }
    String mailContent =
        VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templatePath, "UTF-8", model);
    mail.setContent(mailContent);
    // 调用邮件处理接口
    EmailMimeMessageUtils.sendMail(mailSender, mail);
  }
Example #24
0
  /** Mail Command - Manages mail */
  @CommandID(name = "Mail", triggers = "mail", requireChannel = false)
  @CommandInfo(
      description = "Manages mail; \"/titanchat mail help\" for more info",
      usage = "mail <command> <arguments>")
  public void mail(Player player, String[] args) {
    if (args.length < 1) {
      plugin.getServer().dispatchCommand(player, "titanchat mail help");
      return;
    }

    if (args[0].equalsIgnoreCase("check")) {
      Mailbox mailbox = system.getMailbox(player.getName());

      try {
        int page = Integer.parseInt(args[1]) - 1;
        int numPages = mailbox.size() / 10;
        int start = page * 10;
        int end = start + 10;

        if (mailbox.size() % 10 != 0 && (numPages * 10) - mailbox.size() < 0) numPages++;

        if (end > mailbox.size()) end = mailbox.size();

        if (page + 1 > 0 || page + 1 <= numPages) {
          player.sendMessage(
              ChatColor.AQUA
                  + "=== TitanChat Mail System ("
                  + (page + 1)
                  + "/"
                  + numPages
                  + ") ===");
          for (int mailNum = start; mailNum < end; mailNum++) {
            Mail mail = mailbox.getMail().get(mailNum);
            String id = "ID: " + (mailNum + 1);
            String title = "Title: " + mail.getTitle();
            String sender = "Sender: " + mail.getSender();
            player.sendMessage(
                ChatColor.AQUA
                    + " "
                    + id
                    + "  "
                    + title
                    + "  "
                    + sender
                    + "  "
                    + ((mail.isRead()) ? "Read" : "Unread"));
          }

        } else {
          plugin.getServer().dispatchCommand(player, "titanchat mail check 1");
        }

      } catch (IndexOutOfBoundsException e) {
        plugin.getServer().dispatchCommand(player, "titanchat mail check 1");

      } catch (NumberFormatException e) {
        plugin.sendWarning(player, "Invalid Page Number");
      }

    } else if (args[0].equalsIgnoreCase("delete")) {
      Mailbox mailbox = system.getMailbox(player.getName());

      try {
        if (args.length < 2) throw new IndexOutOfBoundsException();

        List<Mail> selected = new ArrayList<Mail>();

        for (String arg : Arrays.copyOfRange(args, 1, args.length))
          try {
            int mail = Integer.parseInt(arg) - 1;

            if (mail >= 0 && mail < mailbox.size()) selected.add(mailbox.readMail(mail));

          } catch (NumberFormatException e) {
          }

        if (selected.size() >= 1) {
          mailbox.deleteMail(selected);
          plugin.sendInfo(player, "Successfully deleted mail");

        } else {
          plugin.sendWarning(player, "Failed to find mail");
        }

      } catch (IndexOutOfBoundsException e) {
        if (mailbox.getSelection().size() < 1) {
          plugin.sendWarning(player, "Failed to find mail");
          return;
        }

        List<Mail> selected = new ArrayList<Mail>();

        for (int mail : mailbox.getSelection()) selected.add(mailbox.readMail(mail));

        mailbox.deleteMail(selected);
        mailbox.getSelection().clear();
        plugin.sendInfo(player, "Successfully deleted mail");

      } catch (NumberFormatException e) {
        if (args[0].equalsIgnoreCase("all")) {
          mailbox.getMail().clear();
          plugin.sendInfo(player, "Successfully deleted all mail");

        } else {
          plugin.sendWarning(player, "Failed to find mail");
        }
      }

    } else if (args[0].equalsIgnoreCase("help")) {
      player.sendMessage(ChatColor.AQUA + "=== TitanChat Mail System Help ===");
      player.sendMessage(ChatColor.AQUA + "check : Checks mailbox for mail");
      player.sendMessage(ChatColor.AQUA + "delete <all/id>... : Deletes selection");
      player.sendMessage(ChatColor.AQUA + "help : Displays this help");
      player.sendMessage(ChatColor.AQUA + "read [id] : Reads the mail");
      player.sendMessage(ChatColor.AQUA + "[sel/select] [all/id]... : Selects the list of mail");
      player.sendMessage(ChatColor.AQUA + "send [target] [message] : Sends the mail to the target");
      player.sendMessage(ChatColor.AQUA + "setread <all/id>... : Sets all the mail to read");
      player.sendMessage(ChatColor.AQUA + "setunread <all/id>... : Sets all the mail to unread");
      player.sendMessage(ChatColor.AQUA + "Prepend with \"/titanchat mail \" before usage");

    } else if (args[0].equalsIgnoreCase("read")) {
      try {
        Mail mail = system.getMailbox(player.getName()).readMail(Integer.parseInt(args[1]) - 1);
        player.sendMessage(ChatColor.GREEN + "Sender: " + ChatColor.WHITE + mail.getSender());
        player.sendMessage(ChatColor.GREEN + "Date: " + ChatColor.WHITE + mail.getDateTime());
        player.sendMessage(ChatColor.GREEN + "Title: " + ChatColor.WHITE + mail.getTitle());
        player.sendMessage(ChatColor.GREEN + "Message: " + ChatColor.WHITE + mail.getMessage());
        mail.setRead(true);

      } catch (Exception e) {
        plugin.sendWarning(player, "Failed to find mail");
      }

    } else if (args[0].equalsIgnoreCase("sel") || args[0].equalsIgnoreCase("select")) {
      Mailbox mailbox = system.getMailbox(player.getName());

      List<Integer> mailList = new ArrayList<Integer>();

      for (String arg : args) {
        try {
          int mail = Integer.parseInt(arg) - 1;

          if (mail >= 0 && mail < mailbox.size()) mailList.add(mail);

        } catch (NumberFormatException e) {
        }
      }

      Collections.sort(mailList);

      mailbox.getSelection().clear();
      mailbox.getSelection().addAll(mailList);
      plugin.sendInfo(player, "You have selected " + mailList.size() + " mail");

    } else if (args[0].equalsIgnoreCase("send")) {
      if (args.length < 2) {
        plugin.sendWarning(player, "You require at least 1 word in your message");
        return;
      }

      Mailbox mailbox = system.getMailbox(args[1]);

      if (mailbox == null) {
        OfflinePlayer offline = plugin.getServer().getOfflinePlayer(args[1]);

        if (offline.hasPlayedBefore()) {
          mailbox = system.loadMailbox(offline.getName());

        } else {
          plugin.sendWarning(player, args[1] + " does not have a Mailbox");
          return;
        }
      }

      StringBuilder str = new StringBuilder();

      for (String arg : Arrays.copyOfRange(args, 1, args.length)) {
        if (str.length() > 0) str.append(" ");

        str.append(arg);
      }

      mailbox.receiveMail(player.getName(), str.toString());

      if (plugin.getPlayer(args[1]) != null) {
        Player target = plugin.getPlayer(args[0]);
        plugin.sendInfo(
            player, target.getDisplayName() + " is online, you can talk to him/her directly");
        plugin.sendInfo(target, "You received an email from " + player.getDisplayName());

        if (mailbox.getUnreadMail() > 0)
          plugin.sendInfo(target, "You have " + mailbox.getUnreadMail() + " unread mail");
      }

      plugin.sendInfo(player, "You successfully sent the message to " + args[1]);

    } else if (args[0].equalsIgnoreCase("setread")) {
      Mailbox mailbox = system.getMailbox(player.getName());

      try {
        if (args.length < 1) throw new IndexOutOfBoundsException();

        for (String arg : Arrays.copyOfRange(args, 1, args.length)) {
          try {
            int mail = Integer.parseInt(arg) - 1;

            if (mail >= 0 && mail < mailbox.size()) mailbox.readMail(mail).setRead(true);

          } catch (NumberFormatException e) {
          }
        }

        plugin.sendInfo(player, "Successfully set mail as read");

      } catch (IndexOutOfBoundsException e) {
        if (mailbox.getSelection().size() < 1) {
          plugin.sendWarning(player, "Failed to find mail");
          return;
        }

        for (int mail : mailbox.getSelection()) mailbox.readMail(mail).setRead(true);

        plugin.sendInfo(player, "Successfully set selection as read");

      } catch (NumberFormatException e) {
        if (args[0].equalsIgnoreCase("all")) {
          for (Mail mail : mailbox.getMail()) mail.setRead(true);

          plugin.sendInfo(player, "Successfully set all mail as read");

        } else {
          plugin.sendWarning(player, "Failed to find mail");
        }
      }

    } else if (args[0].equalsIgnoreCase("setunread")) {
      Mailbox mailbox = system.getMailbox(player.getName());

      try {
        if (args.length < 1) throw new IndexOutOfBoundsException();

        for (String arg : Arrays.copyOfRange(args, 1, args.length)) {
          try {
            int mail = Integer.parseInt(arg) - 1;

            if (mail >= 0 && mail < mailbox.size()) mailbox.readMail(mail).setRead(false);

          } catch (NumberFormatException e) {
          }
        }

        plugin.sendInfo(player, "Successfully set mail as read");

      } catch (IndexOutOfBoundsException e) {
        if (mailbox.getSelection().size() < 1) {
          plugin.sendWarning(player, "Failed to find mail");
          return;
        }

        for (int mail : mailbox.getSelection()) mailbox.readMail(mail).setRead(false);

        plugin.sendInfo(player, "Successfully set selection as read");

      } catch (NumberFormatException e) {
        if (args[0].equalsIgnoreCase("all")) {
          for (Mail mail : mailbox.getMail()) mail.setRead(false);

          plugin.sendInfo(player, "Successfully set all mail as read");

        } else {
          plugin.sendWarning(player, "Failed to find mail");
        }
      }

    } else {
      plugin.sendWarning(player, "Invalid Mail Command");
    }
  }