1 5 package org.exoplatform.services.communication.message.impl; 6 7 import java.util.Date ; 8 import org.exoplatform.commons.exception.ExoMessageException; 9 import org.exoplatform.services.communication.message.*; 10 15 public class StandaloneMessageProtocolPlugin extends BaseMessageProtocolPlugin { 16 17 public StandaloneMessageProtocolPlugin(MessageService mservice) { 18 super(mservice) ; 19 } 20 21 public String getProtocol() { return MessageService.STANDALONE_PROTOCOL ; } 22 23 public void sendMessage(Account account, Message message) throws Exception { 24 String [] tmp = message.getTo().split("#") ; 25 if(tmp.length != 2) { 26 Object [] args = {message.getTo()} ; 27 throw new ExoMessageException("MessageService.invalid-standalone-message-address", args) ; 28 } 29 String user = tmp[0] ; 30 String accountName = tmp[1] ; 31 Account receiverAccount = mservice_.getAccount(user, accountName) ; 32 if(receiverAccount == null) { 33 Object [] args = {message.getTo()} ; 34 throw new ExoMessageException("MessageService.address-not-found", args) ; 35 } 36 Folder folder = mservice_.getFolder(receiverAccount, MessageService.INBOX_FOLDER) ; 37 message.setFrom(formatEmail(account.getReplyToAddress())) ; 38 message.setReceivedDate(new Date ()) ; 39 message.addFlag(MessageHeader.RECENT_FLAG) ; 40 mservice_.createMessage(account, folder, message) ; 41 saveSentMessage(account, message) ; 42 } 43 44 public void synchronize(Account account) throws Exception { 45 46 } 47 } 48 | Popular Tags |