14fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/**************************************************************** 24fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Licensed to the Apache Software Foundation (ASF) under one * 34fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * or more contributor license agreements. See the NOTICE file * 44fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * distributed with this work for additional information * 54fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * regarding copyright ownership. The ASF licenses this file * 64fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * to you under the Apache License, Version 2.0 (the * 74fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * "License"); you may not use this file except in compliance * 84fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * with the License. You may obtain a copy of the License at * 94fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * * 104fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * http://www.apache.org/licenses/LICENSE-2.0 * 114fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * * 124fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Unless required by applicable law or agreed to in writing, * 134fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * software distributed under the License is distributed on an * 144fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 154fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * KIND, either express or implied. See the License for the * 164fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * specific language governing permissions and limitations * 174fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * under the License. * 184fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy ****************************************************************/ 194fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 204fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypackage org.apache.james.mime4j.field; 214fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 224fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 234fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 244fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy/** 254fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Represents a <code>Content-Transfer-Encoding</code> field. 264fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 274fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 284fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @version $Id: ContentTransferEncodingField.java,v 1.2 2004/10/02 12:41:11 ntherning Exp $ 294fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 304fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedypublic class ContentTransferEncodingField extends Field { 314fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 324fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The <code>7bit</code> encoding. 334fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 344fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public static final String ENC_7BIT = "7bit"; 354fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 364fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The <code>8bit</code> encoding. 374fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 384fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public static final String ENC_8BIT = "8bit"; 394fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 404fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The <code>binary</code> encoding. 414fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 424fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public static final String ENC_BINARY = "binary"; 434fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 444fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The <code>quoted-printable</code> encoding. 454fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 464fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public static final String ENC_QUOTED_PRINTABLE = "quoted-printable"; 474fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 484fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * The <code>base64</code> encoding. 494fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 504fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public static final String ENC_BASE64 = "base64"; 514fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 524fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy private String encoding; 534fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 544fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy protected ContentTransferEncodingField(String name, String body, String raw, String encoding) { 554fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy super(name, body, raw); 564fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy this.encoding = encoding; 574fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 584fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 594fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 604fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Gets the encoding defined in this field. 614fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 624fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @return the encoding or an empty string if not set. 634fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 644fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public String getEncoding() { 654fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy return encoding; 664fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 674fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 684fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy /** 694fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * Gets the encoding of the given field if. Returns the default 704fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * <code>7bit</code> if not set or if 714fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * <code>f</code> is <code>null</code>. 724fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * 734fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy * @return the encoding. 744fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy */ 754fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public static String getEncoding(ContentTransferEncodingField f) { 764fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy if (f != null && f.getEncoding().length() != 0) { 774fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy return f.getEncoding(); 784fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 794fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy return ENC_7BIT; 804fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 814fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy 824fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public static class Parser implements FieldParser { 834fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy public Field parse(final String name, final String body, final String raw) { 844fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy final String encoding = body.trim().toLowerCase(); 854fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy return new ContentTransferEncodingField(name, body, raw, encoding); 864fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 874fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy } 884fa0a3295bcacbdcd6a9e7709cf17aa5adb90356Scott Kennedy} 89