使用claros inTouch 2.2的那些事之部署

最近由于项目需要一个web的邮件客户端,小生去网上找了一圈,最后被claros inTouch所吸引(界面挺好看的)。偷笑

环境:

tomact6

jdk1.6

claros inTouch 2.2

从官网http://claros.org/web/home.do下载解压之后找到intouch2.war。把它放入tomact6下启动之后(建立数据库,根据数据库不同选择相应的sql即可,刚下载的claros inTouch 2.2包中有sql文件)一切准备完之后访问正常情况会出现如下页面:


claros inTouch 2.2支持POP3和IMAP,如果你想正常登陆,需要对config.xml进行配置(路径为\src\intouch2\WebRoot\WEB-INF\config)

下面是小生配置的demo,大家可以根据自身需要进行配置(重要的配置是server和数据库的连接)。

<?xml version="1.0" encoding="UTF-8"?>
<claros-config>
	<!-- Common parameters -->
	<common-params>
		<!-- 
			Default character encoding for the encoding of the pages. You probably won't need 
			to change this. 
		 -->
		<charset>utf-8</charset>
		<!-- 
			This settting has no effect as of version 2.2
		 -->
		<server-timezone>Europe/Istanbul</server-timezone>
		<!-- 
			This is the folder where users will be uploading the attachments temporarily. 
			Please make sure the user running the application server process can read/write 
			to this folder. Do no put / at the right side.
			
			Examples: /tmp,  c:/temp  
		 -->
		<tmp-dir>/tmp</tmp-dir>
		<!-- 
			This is the maximum MB's of a single attachment the users can send. 
		 -->
		<max-attachment-size>5</max-attachment-size>
		<!-- 
			This is the maximum MB's of a single mail can be. 
		 -->
		<max-mail-size>10</max-mail-size>
		<title>Claros inTouch 2.2</title>
		<!-- 
			On the fly spam checking is unique feature of Claros inTouch but this dramatically
			drops the performance. So please use spamassasin. 
		 -->
		<spam-check-enabled>false</spam-check-enabled>
		<!-- 
			The default language users will see when they first see the login page. 
			
			Possible values are : 
			Danish: da, German: de, English: en, Spanish: es, French: fr, 
			Italian: it, Polish: pl, Brazilian Portuguese: pt_br, Slovak: sk
			Turkish: tr, Vietnamese: vi, Simplified Chinese: zh_cn_utf8
			Traditional Chinese: zh_tw_utf8
		 -->
		<default-lang>zh_cn_utf8</default-lang>
		<!-- 
			This is the default RSS feed for the users. 
		 -->
		<rss-feed>http://rss.cnn.com/rss/cnn_topstories.rss</rss-feed>
		<!-- 
			For performance reasons not all the e-mail headers are shown at the mailbox view. 
			This is because of limitations of the HTML browser, network transfer and the usability. 
			
			This setting enhances performance extremely if used with the server side imap 
			sorting setting below. 
			
			Please type how many e-mail headers you wish to see in each mailbox page. 
		 -->
		<mailbox-page-size>50</mailbox-page-size>
		<!-- 
			 Server Side IMAP sort enhances performance a lot. So keep the 
			 following variable to false if there is no exceptional case. Please note that
			 server side sorting is completely dependent on your IMAP server implementation
			 and if there are problems with sorting the accented characters etc... please 
			 consult the IMAP server vendor. If this method doesn't work for you change 
			 the following variable to true and Claros will do the sorting depending on your
			 locale settings. (slower but better).
			 
			 This setting has no effect if you are using the pop3 protocol.
		-->
		<disable-imap-sort>false</disable-imap-sort>
		<!-- 
			INBOX is pinged transparently for the arrival of new e-mail periodically. 
			Please indicate how many seconds each check should occur. 
			
			The smaller the number, more responsive the INBOX but will make a higher load
			on the server. 
			
			Caution! do not make it below 10 seconds for a stable system. 
		 -->
		<mail-check-interval>20</mail-check-interval>
		
		<!-- 
			Appending the server signature. If this option is enabled you 
			can edit server_signature.txt
			
			Values: true or false  
		-->
		<append-signature>false</append-signature>
	</common-params>

	<!-- 
		Claros inTouch will create some IMAP/Pop3 folders prior to their 
		first login. You can set the names of the folders which will be created
		in their profiles. Please do not use accented characters.
	 -->
	<mail-folder-names>
		<folder-junk>Junk Mail</folder-junk>
		<folder-sent>Sent Mail</folder-sent>
		<folder-drafts>Drafts</folder-drafts>
		<folder-trash>Trash</folder-trash>
	</mail-folder-names>

	<!-- 
		Claros inTouch's chat module can connect with other Jabber transports
		if they are installed on the server side. 
		
		If you have any of the following transports you can set the URL's of the
		transports. If you don't know what those means, leave them as is. 
	 -->
	<chat>
		<default-domain>claros.org</default-domain>
		<msn-transport>msn.claros.org</msn-transport>
		<yahoo-transport>yahoo.claros.org</yahoo-transport>
		<icq-transport>icq.claros.org</icq-transport>
		<aol-transport>aol.claros.org</aol-transport>
	</chat>
	
	<!--
		Please configure ONLY ONE server setting below. 
		Claros inTouch supports many protocols including 
		imap, pop3, imaps, pop3s, smtp, smtps
		
		The following sample configurations can help you move faster. The fields below means: 
	 
	 	shortname: name anything you want.
	 	fetch-server: imap or pop3 server's hostname/ip you will be using.
	 	fetch-server-port: imap: 143 pop3: 110 imaps: 993 pop3s: 995  
	 	fetch-protocol: imap or pop3
	 	fetch-ssl: if your imap or pop3 server supports SSL(imaps or pop3s) 
	 			   set this to true else false.
	 	smtp-server: smtp server's hostname/ip you will be using.
	 	smtp-server-port: smtp: 25 smtps: 465
	 	smtp-authenticated: if your smtp server uses auth to prevent spammers set this to true.
	 	smtp-ssl: if your smtp server supports SSL(smtps) set this to true
	 	folder-namespace: some imap implementations have folder names like INBOX.Trash, 
	 					  INBOX.Drafts etc... So your folder namespace is INBOX. For example: 
	 					  Courier and Cyrus Imap servers are using such namespaces. But dovecot
	 					  probably doesn't. Please do not forget the . at the rightmost side. 
	 					  If your imap server is not using folder namespaces or you are using the
	 					  pop3 mode, leave this field blank. Such as <folder-namespace></folder-namespace>   

		These are samples: 
		
		POP3S sample Using as a GMAIL Client
		<server>
			<shortname>gmail</shortname>
			<fetch-server>pop.gmail.com</fetch-server>
			<fetch-server-port>995</fetch-server-port>
			<fetch-protocol>pop3</fetch-protocol>
			<fetch-ssl>true</fetch-ssl>
			<smtp-server>smtp.gmail.com</smtp-server>
			<smtp-server-port>465</smtp-server-port>
			<smtp-authenticated>true</smtp-authenticated>
			<smtp-ssl>true</smtp-ssl>
			<folder-namespace></folder-namespace>
		</server>

		IMAP sample with a folder namespace
		<server>
			<shortname>localhost</shortname>
			<fetch-server>localhost</fetch-server>
			<fetch-server-port>143</fetch-server-port>
			<fetch-protocol>imap</fetch-protocol>
			<fetch-ssl>false</fetch-ssl>
			<smtp-server>localhost</smtp-server>
			<smtp-server-port>25</smtp-server-port>
			<smtp-authenticated>true</smtp-authenticated>
			<smtp-ssl>false</smtp-ssl>
			<folder-namespace>INBOX.</folder-namespace>
		</server>

		IMAP sample without a folder namespace
		<server>
			<shortname>localhost</shortname>
			<fetch-server>localhost</fetch-server>
			<fetch-server-port>143</fetch-server-port>
			<fetch-protocol>imap</fetch-protocol>
			<fetch-ssl>false</fetch-ssl>
			<smtp-server>localhost</smtp-server>
			<smtp-server-port>25</smtp-server-port>
			<smtp-authenticated>true</smtp-authenticated>
			<smtp-ssl>false</smtp-ssl>
			<folder-namespace></folder-namespace>
		</server>
		
		CHANGE THE FOLLOWING DETAILS
	-->
	<servers>
		<server>
			<shortname>qq.com</shortname>
			<fetch-server>pop.qq.com</fetch-server>
			<fetch-server-port>995</fetch-server-port>
			<fetch-protocol>pop3</fetch-protocol>
			<fetch-ssl>true</fetch-ssl>
			<smtp-server>smtp.qq.com</smtp-server>
			<smtp-server-port>465</smtp-server-port>
			<smtp-authenticated>true</smtp-authenticated>
			<smtp-ssl>true</smtp-ssl>
			<folder-namespace></folder-namespace>
		</server>
		<server>
			<shortname>163.com</shortname>
			<fetch-server>pop.163.com</fetch-server>
			<fetch-server-port>995</fetch-server-port>
			<fetch-protocol>pop3</fetch-protocol>
			<fetch-ssl>true</fetch-ssl>
			<smtp-server>smtp.163.com</smtp-server>
			<smtp-server-port>994</smtp-server-port>
			<smtp-authenticated>true</smtp-authenticated>
			<smtp-ssl>true</smtp-ssl>
			<folder-namespace></folder-namespace>
		</server>
<!-- 		<server> -->
<!-- 			<shortname>163.com</shortname> -->
<!-- 			<fetch-server>imap.163.com</fetch-server> -->
<!-- 			<fetch-server-port>993</fetch-server-port> -->
<!-- 			<fetch-protocol>imap</fetch-protocol> -->
<!-- 			<fetch-ssl>true</fetch-ssl> -->
<!-- 			<smtp-server>smtp.163.com</smtp-server> -->
<!-- 			<smtp-server-port>994</smtp-server-port> -->
<!-- 			<smtp-authenticated>true</smtp-authenticated> -->
<!-- 			<smtp-ssl>true</smtp-ssl> -->
<!-- 			<folder-namespace></folder-namespace> -->
<!-- 		</server> -->
	</servers>

	<!--
		You need to configure a valid user account for the server configured above.
		This will be the e-mail settings who will be sending e-mail reminders
		to users.
		
		Please keep this file in a safe place!
	 -->
	<calendar-smtp>
		<mail-from-name>Calendar</mail-from-name>
		<mail-from-address>reminder@your.domain.com</mail-from-address>
		<username>username</username>
		<password>CHANGE THIS</password>
	</calendar-smtp>

	<webdisk>
		<!-- 
			All webdisk are stored in a folder structure starting from the following directory. 
			Make sure the user running the application server has permission to
			read/write to this directory and its contents. 
			
			Do not put a / at the right side. Windows users can use right slashes too.
			Examples: /tmp,  c:/temp, /home/users  
		 -->
		<home-base>/homes</home-base>
		<!-- 
			The limit of the file user can upload to his/her webdisk in MB's. 
		 -->
		<upload-limit-size>5</upload-limit-size>
		<!-- 
			Webdisk can show thumbnails for images. But there should be a limit. 
			Webdisk will not show thumbnails for images greater than the size of the
			following setting. The setting is in kilobytes. 
		 -->
		<img-preview-size>100</img-preview-size>
		<!-- 
			All users will have an upload directory with the name of the following setting.
			This folder will not be deletable and will be used for uploading files to their
			webdisks. Afterwards they can move the file to any folder they like.
		 -->
		 <upload-dir-name>My Uploads</upload-dir-name>
	</webdisk>

	<!-- 
		Database connection parameters.
		You have to create the database tables before you continue. 
		The database tables can be created with the script provided at the
		SQL directory of the distribution.
		
		Please DO NOT change the term file at the "id" field.
	 -->
	<db-config>
		<!-- Sample MySQL setting -->
		<db>
			<id>file</id>
			<database>jdbc:mysql://localhost:3306/intouch</database>
			<driver>com.mysql.jdbc.Driver</driver>
			<login>root</login>
			<password>root</password>
		</db>
		<!-- Sample Postgresql setting -->
		<!--
		<db>
			<id>file</id>
			<database>jdbc:postgresql:intouch</database>
			<driver>org.postgresql.Driver</driver>
			<login>postgres</login>
			<password>CHANGE THIS</password>
		</db>
		-->
	</db-config>
</claros-config>
小生在配置文件中配置了两个server(163和QQ的),那么是不是就可以分别登陆163邮箱和QQ邮箱了啊。答案是现在还不能(不会识别你登陆的哪个邮箱),因为是开源的所以我们可以进行稍稍修改,首先找到LoginService.java(可以使用eclipse开发工具新建一个项目把刚下载包中src/intouch2下所有文件拷到项目下,找到LoginService.java修改)然后你可以在eclipse当中添加tomact直接运行发布或重新把项目打成war包再发布到tomact下就OK了。

修改成如下:

package org.claros.intouch.profiling.services;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.claros.commons.auth.MailAuth;
import org.claros.commons.auth.exception.LoginInvalidException;
import org.claros.commons.auth.models.AuthProfile;
import org.claros.commons.exception.SystemException;
import org.claros.commons.mail.exception.ServerDownException;
import org.claros.commons.mail.models.ConnectionMetaHandler;
import org.claros.commons.mail.models.ConnectionProfile;
import org.claros.commons.mail.models.ConnectionProfileList;
import org.claros.intouch.webmail.controllers.FolderController;
import org.claros.intouch.webmail.factory.FolderControllerFactory;

public class LoginService extends HttpServlet {
	private static final long serialVersionUID = -7565470602365037845L;
	private static Log log = LogFactory.getLog(LoginService.class);

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setHeader("Expires","-1");
		response.setHeader("Pragma","no-cache");
		response.setHeader("Cache-control","no-cache");
		response.setHeader("Content-Type", "text/html; charset=utf-8");

		PrintWriter out = response.getWriter();

		log.debug("Fetching the server profile from the config.xml file");
		
		try {
			HashMap map = ConnectionProfileList.getConList();
			if (map != null) {
				Set set = map.keySet();
				if (set == null) {
					log.fatal("Mail server profile is not accessable. Can't continue. :( Sorry. Please check your config.xml file.1");
					throw new SystemException();
				}
				Object arr[] = set.toArray();
				if (arr == null || arr.length <= 0) {
					log.fatal("Mail server profile is not accessable. Can't continue. :( Sorry. Please check your config.xml file.2");
					throw new SystemException();
				}
				
				String username = request.getParameter("username");
				String password = request.getParameter("password");
				if(username.indexOf("@")==-1){
					out.print("no") ;
				}
				System.out.println(username.substring(username.indexOf("@")+1,username.length())) ;
				ConnectionProfile profile = ConnectionProfileList.getProfileByShortName(username.substring(username.indexOf("@")+1,username.length()));
				if (profile == null) {
					log.fatal("Mail server profile is not accessable. Can't continue. :( Sorry. Please check your config.xml file.3");
					throw new SystemException();
				}
				log.debug("I've got the mail server profile. Keep on... " + profile.toString());
				
				if (username != null && password != null) {
					AuthProfile auth = new AuthProfile();
					auth.setUsername(username);
					auth.setPassword(password);
					ConnectionMetaHandler handler = (ConnectionMetaHandler)request.getSession().getAttribute("handler");
					log.debug("Starting authentication");

					try {
						handler = MailAuth.authenticate(profile, auth, handler);
						if (handler != null) {
							log.debug("Authentication was successful... :) Good news!");
							
							request.getSession().setAttribute("handler", handler);
							request.getSession().setAttribute("auth", auth);
							request.getSession().setAttribute("profile", profile);

							// create default mailboxes if not exists
							try {
								log.debug("Trying to create default mailbox folders if they don't exist.");

								FolderControllerFactory factory = new FolderControllerFactory(auth, profile, handler);
								FolderController foldCont = factory.getFolderController();
								foldCont.createDefaultFolders();
							} catch (Exception e) {
								log.error("unable to create default folders!!!! It will probably fail but giving a try", e);
							}

							log.debug("Everything was fine. Sending an OK signal to the UI");
							out.print("ok");
						} else {
							log.debug("Can't authenticate. username and password is most probably wrong.1");
							out.print("no");
						}
					} catch (LoginInvalidException e) {
						log.debug("Can't authenticate. username and password is most probably wrong.3");
						out.print("no");
					} catch (ServerDownException e) {
						log.error("Can't reach the server. Please make sure everything is fine at config.xml file and server is up and running.");
						out.print("system");
					}
				} else {
					log.debug("Can't authenticate. username and password is most probably wrong.2");
					out.print("no");
				}
			} else {
				throw new SystemException();
			}
		} catch (SystemException e) {
			log.error("Can't get mail server list. Please make sure everything is fine at config.xml file.", e);
			out.print("system");
		} catch (Throwable e) {
			log.error("Unknown error. Please check logs for more information. ", e);
			out.print("system");
		}
	}
}
修改完之后就可以登陆qq和163的邮箱 了。如果你还想登陆其它的邮箱,那么只需在config.xml中加一个server即可。

登陆成功之后如下图所示:

这一次小生讲的只是如何登陆和发布,其实小生用完之后还是发现了claros inTouch2.2当中的各种bug。如收件箱使用POP3加密方法时无法发送邮件,收邮箱时已读未读傻傻分不清楚 等问题。

下次小生再一一把这种BUG的解决办法写出来。

第一次写,如大神遇过,别嘲笑。可怜


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值