MCPcopy Create free account
hub / github.com/M66B/FairEmail / MimeUtility

Class MimeUtility

app/src/main/java/javax/mail/internet/MimeUtility.java:132–1624  ·  view source on GitHub ↗

This is a utility class that provides various MIME related functionality. There are a set of methods to encode and decode MIME headers as per RFC 2047. Note that, in general, these methods are not needed when using methods such as setSubject and setRecipient

Source from the content-addressed store, hash-verified

130 */
131
132public class MimeUtility {
133
134 // This class cannot be instantiated
135 private MimeUtility() { }
136
137 public static final int ALL = -1;
138
139 // cached map of whether a charset is compatible with ASCII
140 // Map<String,Boolean>
141 private static final Map<String, Boolean> nonAsciiCharsetMap
142 = new HashMap<>();
143
144 private static final boolean decodeStrict =
145 PropUtil.getBooleanSystemProperty("mail.mime.decodetext.strict", true);
146 private static final boolean encodeEolStrict =
147 PropUtil.getBooleanSystemProperty("mail.mime.encodeeol.strict", false);
148 private static final boolean ignoreUnknownEncoding =
149 PropUtil.getBooleanSystemProperty(
150 "mail.mime.ignoreunknownencoding", false);
151 private static final boolean allowUtf8 =
152 PropUtil.getBooleanSystemProperty("mail.mime.allowutf8", false);
153 /*
154 * The following two properties allow disabling the fold()
155 * and unfold() methods and reverting to the previous behavior.
156 * They should never need to be changed and are here only because
157 * of my paranoid concern with compatibility.
158 */
159 private static final boolean foldEncodedWords =
160 PropUtil.getBooleanSystemProperty("mail.mime.foldencodedwords", false);
161 private static final boolean foldText =
162 PropUtil.getBooleanSystemProperty("mail.mime.foldtext", true);
163
164
165 /**
166 * Get the Content-Transfer-Encoding that should be applied
167 * to the input stream of this DataSource, to make it mail-safe. <p>
168 *
169 * The algorithm used here is: <br>
170 * <ul>
171 * <li>
172 * If the DataSource implements {@link EncodingAware}, ask it
173 * what encoding to use. If it returns non-null, return that value.
174 * <li>
175 * If the primary type of this datasource is "text" and if all
176 * the bytes in its input stream are US-ASCII, then the encoding
177 * is "7bit". If more than half of the bytes are non-US-ASCII, then
178 * the encoding is "base64". If less than half of the bytes are
179 * non-US-ASCII, then the encoding is "quoted-printable".
180 * <li>
181 * If the primary type of this datasource is not "text", then if
182 * all the bytes of its input stream are US-ASCII, the encoding
183 * is "7bit". If there is even one non-US-ASCII character, the
184 * encoding is "base64".
185 * </ul>
186 *
187 * @param ds the DataSource
188 * @return the encoding. This is either "7bit",
189 * "quoted-printable" or "base64"

Callers

nothing calls this directly

Calls 6

loadMappingsMethod · 0.95
getResourceAsStreamMethod · 0.45
closeMethod · 0.45
isEmptyMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected