当前位置: 首页>>代码示例>>Java>>正文


Java Part.getAllHeaders方法代码示例

本文整理汇总了Java中javax.mail.Part.getAllHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java Part.getAllHeaders方法的具体用法?Java Part.getAllHeaders怎么用?Java Part.getAllHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.Part的用法示例。


在下文中一共展示了Part.getAllHeaders方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHeaders

import javax.mail.Part; //导入方法依赖的package包/类
String getHeaders(final Part part) throws MessagingException {
    StringBuilder builder = new StringBuilder();
    @SuppressWarnings("unchecked")
    final Enumeration<Header> headers = part.getAllHeaders();
    while (headers.hasMoreElements()) {
        Header next = headers.nextElement();
        builder.append(next.getName());
        builder.append(": ");
        builder.append(next.getValue());
        builder.append('\n');
        if (!headers.hasMoreElements()) {
            builder.append('\n');
        }
    }
    return builder.toString();
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:17,代码来源:MessageParser.java

示例2: onSend

import javax.mail.Part; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void onSend(SubEthaMessage msg, SendFilterContext ctx) throws MessagingException
{
	try
	{
		boolean didSomething = false;
		
		for (Part part: msg.getParts())
		{
			if (part.getContentType().startsWith(SubEthaMessage.DETACHMENT_MIME_TYPE))
			{
				Long id = (Long)part.getContent();
				String contentType = part.getHeader(SubEthaMessage.HDR_ORIGINAL_CONTENT_TYPE)[0];
				
				// remove all headers
				for (Enumeration<Header> e = part.getAllHeaders(); e.hasMoreElements();)
				{
					Header header = e.nextElement();
					part.removeHeader(header.getName());
				}
				
				String name = MailUtils.getNameFromContentType(contentType);
				String attachmentUrl = ctx.getList().getUrlBase() + "attachment/" + id + "/" + name ;
				
				part.setText("This attachment was left behind at the server:\n     " + attachmentUrl + "\n");
				part.setDisposition(Part.INLINE);
				didSomething = true;
			}
		}
		
		if (didSomething) msg.save();
	}
	catch (IOException ioex)
	{
	    log.log(Level.FINE,"Error getting message parts", ioex);
	}
}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:39,代码来源:LeaveAttachmentsOnServerFilter.java

示例3: onInject

import javax.mail.Part; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void onInject(SubEthaMessage msg, FilterContext ctx)
	throws IgnoreException, HoldException, MessagingException
{
	int maxKB = Integer.parseInt(ctx.getArgument(ARG_MAXSIZEINKB).toString());

	String msgContent = (String) ctx.getArgument(ARG_MSG);
	String expandedMsg = ctx.expand(msgContent);

	boolean changed = false;
	try 
	{
		for (Part p: msg.getParts())
		{
			if (p.getContentType().startsWith("text/") && !Part.ATTACHMENT.equals(p.getDisposition()))
				continue;
			
			if (p.getContentType().startsWith("multipart/"))
				continue;
			
			// Hopefully this means it is some sort of binary time
			if (p.getSize() > (maxKB * 1024)) 
			{
			    if (log.isLoggable(Level.FINE))
			        log.log(Level.FINE,"Stripping attachement of type: {0}", p.getContentType());		

				//remove all headers
				for (Enumeration<Header> e = p.getAllHeaders(); e.hasMoreElements();)
				{
					Header header = e.nextElement();
					p.removeHeader(header.getName());
				}

				p.setText(expandedMsg);
				changed = true;
			}
		}
		
		if (changed)
			msg.save();
	}
	catch (IOException ioex)
	{
		throw new RuntimeException(ioex);
	}
}
 
开发者ID:voodoodyne,项目名称:subetha,代码行数:48,代码来源:StripAttachmentsFilter.java

示例4: getFullContent

import javax.mail.Part; //导入方法依赖的package包/类
@Override
public InputStream getFullContent() throws IOException {
    try {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        
        // The natural way to do this would be to call email.writeTo(stream) and be done with it.
        // That works unless there is a non-text attachment, which will not be decoded correctly.
        // It looks like James sends the attachment unharmed in its original encoding
        // (i.e. Content-Transfer-Encoding: binary), but Thunderbird treats it as 8bit and
        // changes zero bytes to spaces (0x20). CR/LFs are altered, too.
        // The ugly workaround is to write out the email one part at a time (if type=multipart),
        // reencoding binary attachments to base64.
        stream.write(Util.readBytes(getHeaderContent()));
        stream.write(CRLF);
        
        if (email.isMimeType("multipart/*")) {
            String contentType = email.getContentType();
            String boundary = contentType.substring(contentType.indexOf("boundary=") + "boundary=".length());
            if (boundary.startsWith("\""))
                boundary = boundary.substring(1);
            if (boundary.endsWith("\""))
                boundary = boundary.substring(0, boundary.length()-1);
            List<Part> parts = email.getParts();
            for (int partIndex=0; partIndex<parts.size(); partIndex++) {
                Part part = parts.get(partIndex);
                stream.write("--".getBytes());
                stream.write(boundary.getBytes());
                stream.write(CRLF);
                if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
                    // write headers
                    @SuppressWarnings("unchecked")
                    Enumeration<Header> headers = part.getAllHeaders();
                    while (headers.hasMoreElements()) {
                        Header header = headers.nextElement();
                        if ("Content-Transfer-Encoding".equals(header.getName()))
                            stream.write("Content-Transfer-Encoding: base64".getBytes());
                        else {
                            stream.write(header.getName().getBytes());
                            stream.write(": ".getBytes());
                            stream.write(header.getValue().getBytes());
                        }
                        stream.write(CRLF);
                    }
                    stream.write(CRLF);
                    
                    // write content
                    byte[] contentBytes = Util.readBytes(part.getInputStream());
                    String base64Str = new String(com.lambdaworks.codec.Base64.encode(contentBytes));
                    while (base64Str.length() > 78) {
                        stream.write(base64Str.substring(0, 78).getBytes());
                        stream.write(CRLF);
                        base64Str = base64Str.substring(78);
                    }
                    if (base64Str.length() > 0) {
                        stream.write(base64Str.getBytes());
                        stream.write(CRLF);
                    }
                    stream.write(CRLF);
                }
                else
                    part.writeTo(stream);
                stream.write(CRLF);
            }
            stream.write("--".getBytes());
            stream.write(boundary.getBytes());
            stream.write("--".getBytes());
        } else
            // not a multipart email, so write the content unaltered
            stream.write(Util.readBytes(email.getRawInputStream()));
        stream.write(CRLF);
        return new ByteArrayInputStream(stream.toByteArray());
    } catch (MessagingException e) {
        throw new IOException(e);
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:76,代码来源:BoteMessage.java


注:本文中的javax.mail.Part.getAllHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。