Back to index

lightning-sunbird  0.9+nobinonly
mimetext.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _MIMETEXT_H_
00039 #define _MIMETEXT_H_
00040 
00041 #include "mimeleaf.h"
00042 
00043 /* The MimeInlineText class is the superclass of all handlers for the
00044    MIME text/ content types (which convert various text formats to HTML,
00045    in one form or another.)
00046 
00047    It provides two services:
00048 
00049      =  if ROT13 decoding is desired, the text will be rotated before
00050            the `parse_line' method it called;
00051 
00052         =  text will be converted from the message's charset to the "target"
00053         charset before the `parse_line' method is called.
00054 
00055    The contract with charset-conversion is that the converted data will
00056    be such that one may interpret any octets (8-bit bytes) in the data
00057    which are in the range of the ASCII characters (0-127) as ASCII
00058    characters.  It is explicitly legal, for example, to scan through
00059    the string for "<" and replace it with "&lt;", and to search for things
00060    that look like URLs and to wrap them with interesting HTML tags.
00061 
00062    The charset to which we convert will probably be UTF-8 (an encoding of
00063    the Unicode character set, with the feature that all octets with the
00064    high bit off have the same interpretations as ASCII.)
00065 
00066    #### NOTE: if it turns out that we use JIS (ISO-2022-JP) as the target
00067         encoding, then this is not quite true; it is safe to search for the
00068               low ASCII values (under hex 0x40, octal 0100, which is '@') but it
00069               is NOT safe to search for values higher than that -- they may be
00070               being used as the subsequent bytes in a multi-byte escape sequence.
00071               It's a nice coincidence that HTML's critical characters ("<", ">",
00072               and "&") have values under 0x40...
00073  */
00074 
00075 typedef struct MimeInlineTextClass MimeInlineTextClass;
00076 typedef struct MimeInlineText      MimeInlineText;
00077 
00078 struct MimeInlineTextClass {
00079   MimeLeafClass   leaf;
00080   int (*rot13_line) (MimeObject *obj, char *line, PRInt32 length);
00081   int (*convert_line_charset) (MimeObject *obj, char *line, PRInt32 length);
00082   int (*initialize_charset) (MimeObject *obj);
00083 };
00084 
00085 extern MimeInlineTextClass mimeInlineTextClass;
00086 
00087 #define DAM_MAX_BUFFER_SIZE 8*1024      
00088 #define DAM_MAX_LINES  1024
00089 
00090 struct MimeInlineText {
00091   MimeLeaf leaf;                   /* superclass variables */
00092   char *charset;                   /* The charset from the content-type of this
00093                                                             object, or the caller-specified overrides
00094                                                             or defaults. */
00095   PRBool charsetOverridable; 
00096   PRBool needUpdateMsgWinCharset; 
00097   char *cbuffer;                   /* Buffer used for charset conversion. */
00098   PRInt32 cbuffer_size;
00099   
00100   nsCOMPtr<nsIUnicodeDecoder> inputDecoder;
00101   nsCOMPtr<nsIUnicodeEncoder> utf8Encoder;
00102 
00103   PRBool  inputAutodetect;
00104   PRBool  initializeCharset;
00105   PRInt32 lastLineInDam;
00106   PRInt32 curDamOffset;
00107   char *lineDamBuffer;
00108   char **lineDamPtrs;
00109 };
00110 
00111 #endif /* _MIMETEXT_H_ */