⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postmessagemethod.java

📁 一个接收基于WebDav邮件的开源项目
💻 JAVA
字号:
/*
 *  This file is part of the JDAVMail package
 *  Copyright (C) 2002-2003 Luc Claes. All rights reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
 *  SHALL THE JDAVMail AUTHORS OR THE PROJECT CONTRIBUTORS BE LIABLE
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 *  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 *  SUCH DAMAGE. See the GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA 02111-1307, USA
 *
 *  For questions, suggestions, bug-reports, enhancement-requests etc.
 *  I may be contacted at:
 *
 *  luc@posisoft.com
 *
 *  The JDAVMail's home page is located at:
 *
 *  http://jdavmail.sourceforge.net
 *
 */
package com.posisoft.jdavmail;

import java.io.IOException;

import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.httpclient.methods.PostMethod;

/**
 */
public class PostMessageMethod extends PostMethod {
	/**
	 */
	public PostMessageMethod(FolderProxy folder) throws URIException {
		super(folder.getURI().getEscapedPath());

		setRequestHeader("User-Agent", JDAVMail.DEFAULT_UA);
		setRequestHeader("content-type", "message/rfc821");
		setRequestHeader("SAVEINSENT", "t");
		setRequestHeader("Translate", "t");
		setRequestHeader("Cache-Control", "no-cache");
	}

	/**
	 * Set the 'Cookie' header as required by the server (i.e. all cookies are to be concatened)
	 */
	protected void addCookieRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException {
		 // Clean up the cookie headers
		 removeRequestHeader("cookie");

		 CookieSpec matcher = CookiePolicy.getSpecByPolicy(state.getCookiePolicy());
		 Cookie[] cookies = matcher.match(conn.getHost(), conn.getPort(),
			 getPath(), conn.isSecure(), state.getCookies());
		 if ((cookies != null) && (cookies.length > 0)) {
			 // In strict mode put all cookies on the same header
			 getRequestHeaderGroup().addHeader(matcher.formatCookieHeader(cookies));
		 }
	 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -