Mrs

De Trustedbird Client Wiki
English | Français

> Documentation > Add-on: Message Remote Services

Télécharger mrs
Fonctionne avec : Trustedbird 2

ChangeLog

Comment installer dans Thunderbird


Message Remote Services is an add-on for Mozilla Thunderbird 2 which exposes remote services to external processes.

A Java API to communicate with this add-on is available. Thus, an external Java program can use a running instance of Thunderbird installed on the same OS.

Features:

  • Send emails.
  • Browse/Receive emails.


Requirements

Current version requires Trustedbird 2.

Configuration

To configure, right-click on the extension in the Add-ons window.

Configuration of MRS

  • Services can be enabled at startup. This feature can be switched off.
  • When this feature is changed, Thunderbird must be restarted.

Java API

The Message Remote Services add-on exposes services which can be called by another application.

This application uses MRS Java API to call these services.

The MRS API is composed of a JAR File (MessageRemoteServices.jar) to be included in the application. The library lib/commons-io-1.4.jar must be installed.

API initialization and services creation

import org.milimail.messageRemoteServiceAPI.init.*;
import org.milimail.messageRemoteServiceAPI.compose.*;
import org.milimail.messageRemoteServiceAPI.account.*;

public static void main(String[] args) {
  ServiceCreator serviceCreator = API.init();
  MessageComposeServiceProxy composeService = serviceCreator.createMessageComposeService();
  AccountServiceProxy accountService = serviceCreator.createAccountService();
  MessageBrowseServiceProxy browseService = serviceCreator.createBrowseService();
}

Account Service

 //Call to the running Thunderbird, Get all Accounts for the current profile
 List<Account> accounts = accountService.GetAllAccounts();
 for (Account account : accounts) {
   //Server Imap Name			
   String serverName = account.getServerHostName();
   //Account Id
   String key = account.getKey();
   System.out.println(serverName + " " + key);
 } 

Compose Service

Send a simple message to a recipient.

ServiceCreator serviceCreator = API.init();
MessageComposeServiceProxy composeService = serviceCreator.createMessageComposeService();
AccountServiceProxy accountService = serviceCreator.createAccountService();
//Simple implementation of MessageSendListener interface which print the Send status
MessageSendListener messageListener = serviceCreator

.createMessageSendListener(new MessageSendListenerServantConsole());

//Take the second Thunderbird's account for the current profile
Account account = accountService.GetAllAccounts().get(1);

//Create the message to send
Message message = new Message();
message.setSubject("Subject from API");
message.setBody("body from API");
String[] to = { "user2@test.milimail.org" };
message.setTo(to);

//Call to Thunderbird, Callback to messageListener (print status to console)
composeService.sendMessage(account, message, messageListener);	
  • Encrypt message
Security security = new Security();
security.setEncrypted(true);
message.setSecurity(security);
  • Sign message
Security security = new Security();
security.setSigned(true);
message.setSecurity(security);
  • Header
List<Header> headers = new ArrayList<Header>();
Header header0 = new Header();
header0.setKey("X-MRS-TEST-1");
header0.setValue("X-MRS-VALUE-1");
headers.add(header0);
message.setHeaders(headers);
  • MDN Read receipt
Notification notification = new Notification();
notification.setMDNReadRequested(true);
message.setNotification(notification);
  • DSN Delivery receipt
//Only with milimail (thunderbird 2.x patched)
Notification notification = new Notification();
notification.setDSNRequested(true);
DSNType type = new DSNType();
//RET=FULL else RET=HDRS
type.setReturnFullHDRRequested(true);

//You can mix the three options
type.setOnSuccessRequested(true);
type.setOnDelayRequested(true);
type.setOnFailureRequested(true);

notification.setDsnType(type);

message.setNotification(notification);
//Only with milimail (thunderbird 2.x patched)
Notification notification = new Notification();
notification.setDSNRequested(true);
DSNType type = new DSNType();
//RET=FULL else RET=HDRS
type.setReturnFullHDRRequested(false);

//NOTIFY=NEVER
type.setNeverRequested(true);

notification.setDsnType(type);

message.setNotification(notification);
  • Attachments
List<Attachment> attachments = new ArrayList<Attachment>();
Attachment attachment0 = new Attachment();
attachment0 = new Attachment();
attachment0.setDirPath("/tmp/res/");
attachment0.setFileName("attachment1.txt");
attachment0.setMimeType("text/plain");
attachments.add(attachment0);
message.setAttachments(attachments);

Browse Service

Get Inbox Folder :

ServiceCreator serviceCreator = API.init();
MessageBrowseServiceProxy browseService = serviceCreator.createBrowseService();
FolderHolder folderHolder = new FolderHolder();
browseService.getRootFolder(account, folderHolder);
Folder folder = folderHolder.getValue();
System.out.println("inbox folder name : " + folder.getName());

Get Local Folder :

FolderHolder folderHolder = new FolderHolder();
browseService.getLocalFolder(folderHolder);		
Folder folder = folderHolder.getValue();
System.out.println("local folder name : " + folder.getName());

Get all folders, children of one folder

FoldersHolder foldersHolder = new FoldersHolder();
browseService.getAllFolders(fatherFolder, foldersHolder);
Folder[] folders = foldersHolder.getValue();

Get all message handlers of a folder, the message handlers contain all important information of the messages but not their content.

MessageHandlersHolder messageHandlersHolder = new MessageHandlersHolder();
browseService.getMessageHandlers(folder, messageHandlersHolder);		
MessageHandler[] handlers = messageHandlersHolder.getValue();
for (int i = 0; i < handlers.length; i++) {
   System.out.println(handlers.getSubject());
}

Get raw Source of the message

//You have to subclass abstract class SourceListenerPOA,
//because the process to get mail from Thunderbird is asynchronous
sourceMessageListener = serviceCreator.createSourceMessageListener(new SourceListenerPOA() {
			      
				public void OnLoad(byte[] source) {
					String sourceString = new String(source);
		                        System.out.println(sourceString);
 
				}

			});
browseService.getSource(handler, sourceMessageListener);

Get Javamail MimeMessage of the message (decrypted if necessary)

//You have to subclass abstract class AbstractMimeMessageListener,
//because the process to get mail from Thunderbird is asynchronous
sourceMessageListener = serviceCreator.createSourceMessageListener(new AbstractMimeMessageListener() {
			
	@Override
	public void onLoad(MimeMessage mimeMessage) {
		//Do your job, this a Javamail MimeMessage
	}
 });
browseService.getDecryptedSource(handler, sourceMessageListener);