home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / EUROSET.ZIP / AAREAD.ME next >
Text File  |  1994-01-27  |  10KB  |  287 lines

  1.                  =====================================
  2.  
  3.                   HANDLING EUROPEAN CHARACTER SETS IN
  4.                     USENET NEWS AND ELECTRONIC MAIL
  5.  
  6.                             Gisle Hannemyr
  7.                              Oslonett A.S.
  8.                               Version 1.0
  9.  
  10.                               1994 Jan 21
  11.  
  12.                  =====================================
  13.  
  14.  
  15. Introduction
  16. ============
  17.  
  18. This note is written as part of an effort to get authors of mail and
  19. newsreaders to treat European character sets with some dignity.
  20.  
  21.  
  22. Manifest
  23. ========
  24.  
  25. AAREAD.ME    -- this file
  26. Makefile    -- to make the demo application
  27. demo.c        -- a simple demo of how you can use the fold library
  28. fold.c        -- the fold library
  29. fold.h          -- header file to the fold library
  30. iso8859-1.ps    -- a postscript file showing ISO latin 1 encoding
  31.                    (print this on a PostScript printer to see it)
  32.  
  33.  
  34.  
  35. Background
  36. ==========
  37.  
  38. In the beginning, there was US-ASCII. US-ASCII defined a standard
  39. binding of numeric codes to graphical representations of characters.
  40. The US-ASCII system used the codes from 33 to 126 (inclusive) for its
  41. graphical symbols.  This makes room for 94 graphical symbols, and may
  42. comfortably be encoded by 7 bits. Later, the US-ASCII representation
  43. was made into an international standard, which was given the name
  44. ISO-646-IRV (IRV stands for "International Reference Version).
  45.  
  46. Unfortunately, 94 graphical symbols are too few for all the weird and
  47. wonderful charcters used in miscellaneous European languages.  There
  48. was several attempts to court the European market by given us products
  49. with our own characters.  IBM and Microsoft, in particular, made a lot
  50. of effort, and created in the process a whole maze of twisty little
  51. encodings, all different.  These are known as "codepages" (CPs).  A
  52. number of other computer manufacturers also created their own
  53. encodings.
  54.  
  55. The one thing that was constant in this process was the encodings of
  56. the 94 graphical characters that was defined in US-ASCII, but the
  57. encodings between 128 and 255 was a mess.
  58.  
  59. Enter the ISO (International Standards Organization).  ISO, with good
  60. help from the international community, created the ISO 8859-series.
  61. This is a series of standards defining mappings between 8-bit
  62. character codes and graphical symbols.  Each part of the series is
  63. designed to serve the needs of a particular geographic area.
  64.  
  65. The first part of this series (ISO 8859/1, also known as "ISO Latin
  66. alphabet no. 1", or simply "ISO Latin 1") quickly gained wide
  67. acceptance in Scandinavia, Western Europe, and also among several
  68. major US manufacturers (DEC, SCO, Sun, HP). It is was subsequently
  69. adopted by X/Open as the preferred character set for Unix
  70. workstations, and it also appears to be the preferred character set in
  71. X.11 and the default character set used by MicroSoft Windows
  72. applications, plus a number of others.  It has also become the default
  73. character set used when transmitting messages containing European
  74. characters on Usenet.
  75.  
  76. While Microsoft's _Windows_ defaults to ISO Latin 1, Microsoft's
  77. _MS-DOS_ does not.  There is a DOS codepage (CP 850 multi- lingual)
  78. that contains all the graphical symbols of ISO Latin 1, but with
  79. different encoding.
  80.  
  81. Therefore, in order to succesfully transmit messages between a MS-DOS
  82. system and Usenet/Internet, some conversion of character encodings are
  83. required to prevent the message from becoming grabled.  When
  84. transmitting mail between Apple MacIntosh and Usenet similar problems
  85. arise.
  86.  
  87.  
  88. Briefly, what should be done?
  89. =============================
  90.  
  91. When shipping messages between systems which use different character
  92. set encodings, codings need to be converted.
  93.  
  94. 1) You need to find out what encoding is used on the system you
  95.    implement your reader on, but usually, the following is the case:
  96.  
  97.       Unix/X.11:  ISO 8859/1
  98.       MS Windows: ISO 8859/1
  99.       Amiga:      ISO 8859/1
  100.       MS-DOS:     IBM CP 850 (or something very similar)
  101.       Macintosh:  MacIntosh character set
  102.  
  103. 2) When importing messages, you need to find out what encoding is
  104.    used in the message (this dies not distinguish between mail and
  105.    news, because there is no need to):
  106.  
  107.    - If the message has a MIME header, parse the MIME header fields
  108.      to determine the actual encoding used.
  109.  
  110.    - If the message does not have a MIME header, check whether the
  111.      body contains codes in the range 160-255 (decimal).
  112.      If no, assume:
  113.         Content-Type: TEXT/PLAIN; charset=US-ASCII
  114.         Content-Transfer-Encoding: 7bit
  115.      If yes, assume:
  116.         Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  117.         Content-Transfer-Encoding: 8BIT
  118.  
  119.     You then need to decode the message according to the information
  120.     (actual or assumed) found in these headers.
  121.  
  122.     (Don't worry about what stuff like "Content-Type" etc. actually
  123.     mean at this stage, it will be explained below.)
  124.  
  125. 3) When exporting messages, you need to treat news and mail
  126.    different.
  127.  
  128.    NEWS: Check whether the user has actually used any characters
  129.    outside the range of US-ASCII in the body of text.
  130.  
  131.    If, no, ship it unchanged.
  132.  
  133.    If yes, use my fold library to translate the characters from
  134.    whatever your system uses to ISO 8859/1.  Add the following 3
  135.    lines to the header, and ship it:
  136.         MIME-Version 1.0
  137.         Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  138.         Content-Transfer-Encoding: 8BIT
  139.  
  140.  
  141.    MAIL: Check whether the user has actually used any characters
  142.    outside the range of US-ASCII in the body of text.
  143.  
  144.    If, no, add the following 3 lines to the header, and ship it:
  145.         MIME-Version 1.0
  146.         Content-Type: TEXT/PLAIN; charset=US-ASCII
  147.         Content-Transfer-Encoding: 7bit
  148.  
  149.    If yes, you need to use my fold library to translate the characters
  150.    from whatever your system uses to ISO 8859/1, and then encode the
  151.    body according to RFC 1341.  You then add the following 3 lines to
  152.    the header, and ship it: 
  153.         MIME-Version 1.0
  154.         Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  155.         Content-Transfer-Encoding: QUOTED-PRINTABLE
  156.  
  157.  
  158.  
  159. MIME
  160. ====
  161.  
  162. MIME specify 3 header fields of particular interest to us:
  163.  
  164. 1) The MIME-Version header field.
  165.  
  166.    This tells us that the message contains headers complient with
  167.    RFC 1341.
  168.  
  169. 2) The Content-Type header field.
  170.  
  171.    This describe the data contained in the body part and has the
  172.    following syntax:
  173.  
  174.       type "/" subtype *[ ";" parameter ]
  175.  
  176.    We are not going to do a full MIME implementation, so we shall
  177.    just handle a single type (TEXT) and a single subtype (PLAIN).
  178.    Everything else is UNKNOWN.
  179.  
  180.    The interesting thing here is the parameter.  We shall look for
  181.    a parameter named "charset", and its value.  RFC 1341 defines
  182.    the following values:
  183.  
  184.        US-ASCII
  185.        ISO-8859-x  (where x refer to a specific part of the
  186.                     ISO-8859 set of standards).
  187.  
  188.    The only value of ISO-8859 handled by my fold library is so far
  189.    ISO-8859-1.
  190.    
  191.  
  192. 3) The Content-Transfer-Encoding header field.
  193.  
  194.    This field tells us how the body is encoded.  We consider 3
  195.    different values for this field:
  196.  
  197.       QUOTED-PRINTABLE
  198.       8BIT
  199.       7BIT
  200.  
  201.    Both 8BIT and 7BIT indicate that the body is _not_ encoded.
  202.    QUOTED-PRINTABLE tells us that the body is encoded according
  203.    to the scheme described in section 5.1 of RFC 1341.
  204.  
  205.  
  206. SAMPLES
  207. =======
  208.  
  209. Below is some sample headers snarfed up by grepping my mailbox and our
  210. news/spool. This is the sort of thing your program should handle.
  211. Assuming your program is running on a MS-DOS computer using CP-850,
  212. and that your message is contained in char *MsgBuffer, this is the
  213. appropriate calls to my folding library to import these correctly:
  214.  
  215.  
  216. 1) 7bit US-ASCII
  217. ----------------
  218.    Content-Type: text/plain; charset=US-ASCII.
  219.    Content-Transfer-Encoding: 7bit
  220.  
  221.         /* do nothing */
  222.  
  223.  
  224. 2) Unencoded ISO Latin 1
  225. ------------------------
  226.    Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-1
  227.    Content-Transfer-Encoding: 8BIT
  228.  
  229.         initfold(ISOL1, CP850);   /* set up iso-8859-1 -> CP 850 */
  230.         foldbuffer(MsgBuffer);    /* iso-8859-1 -> CP 850 */
  231.  
  232.  
  233. 3) Encoded ISO Latin 1
  234. ------------------------
  235.    Content-Type: text/plain; charset="iso-8859-1"
  236.    Content-Transfer-Encoding: quoted-printable
  237.  
  238.         unmimebuffer(MsgBuffer);  /* MIME -> iso-8859-1          */
  239.         initfold(ISOL1, CP850);   /* set up iso-8859-1 -> CP 850 */
  240.         foldbuffer(MsgBuffer);    /* iso-8859-1 -> CP 850 */
  241.  
  242.  
  243. 4) 7 bit Norwegian ISO-IR-60
  244. ----------------------------
  245.    Content-Type: text/plain; charset=x-iso-ir-60
  246.    Content-Transfer-Encoding: 7bit
  247.  
  248.         initfold(ISO646N, CP850); /* set up iso-or-60 -> CP 850 */
  249.         foldbuffer(MsgBuffer);    /* iso-8859-1 -> CP 850 */
  250.  
  251.    X-iso-ir-60 is a private value strictly outside the scope of
  252.    RFC-1341 (but RFC-1341 explictly allows private values provided
  253.    they start with an "X").  This value is used in Norway, and it
  254.    will be appreciated if your software recognizes it.
  255.  
  256.  
  257. A&Q
  258. ===
  259.  
  260. Q1: All this is about the message body.  What about using European
  261.     characters in headers?
  262. A1: Don't do it.  There is an RFC on it (RFC-1342), but in my experience,
  263.     such headers tend to mess up mail- and newsreaders.  When exporting
  264.     messages use the "stripbuffer" function in the library to make
  265.     sure that headers are US-ASCII, 7BIT.
  266.  
  267. Q2: What are these RFC thingies?
  268. A2: The RFCs are Internet standards socuments available by anonymous
  269.     FTP from any decent archive site.  If you're really stuck, try:
  270.          ds.internic.net:rfc/*
  271.     Those of particular interest in this context are:
  272.     - RFC-822  : mail format
  273.     - RFC-1036 : news format
  274.     - RFC-1341 : MIME encoding
  275.     - RFC-1342 : MIME encoding of headers
  276.  
  277. Q3: Why is there a 8BIT Content-Transfer-Encoding, when there are no
  278.     standardized Internet transports for which it is legitimate to
  279.     include unencoded 8-bit data.
  280. A3: Because people use it, and it works.
  281.     Cd to your mail spool, into almost any international group
  282.     with some volume, and type:
  283.           % fgrep -i content-transfer-encoding * | grep 8
  284.     See?
  285.  
  286. ========================================================================
  287.