Back to index

lightning-sunbird  0.9+nobinonly
mimemapl.cpp
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 #include "nsCOMPtr.h"
00039 #include "mimemapl.h"
00040 #include "prmem.h"
00041 #include "plstr.h"
00042 #include "nsMimeStringResources.h"
00043 #include "mimemoz2.h"
00044 #include "nsMimeTypes.h"
00045 #include "nsCRT.h"                
00046 
00047 #define MIME_SUPERCLASS mimeMultipartClass
00048 MimeDefClass(MimeMultipartAppleDouble, MimeMultipartAppleDoubleClass,
00049                       mimeMultipartAppleDoubleClass, &MIME_SUPERCLASS);
00050 
00051 static int MimeMultipartAppleDouble_parse_begin (MimeObject *);
00052 static PRBool MimeMultipartAppleDouble_output_child_p(MimeObject *,
00053                                                                                               MimeObject *);
00054 
00055 static int
00056 MimeMultipartAppleDoubleClassInitialize(MimeMultipartAppleDoubleClass *clazz)
00057 {
00058   MimeObjectClass    *oclass = (MimeObjectClass *)    clazz;
00059   MimeMultipartClass *mclass = (MimeMultipartClass *) clazz;
00060 
00061   NS_ASSERTION(!oclass->class_initialized, "mime class not initialized");
00062   oclass->parse_begin    = MimeMultipartAppleDouble_parse_begin;
00063   mclass->output_child_p = MimeMultipartAppleDouble_output_child_p;
00064   return 0;
00065 }
00066 
00067 static int
00068 MimeMultipartAppleDouble_parse_begin (MimeObject *obj)
00069 {
00070   /* #### This method is identical to MimeExternalObject_parse_begin
00071         which kinda s#$%s...
00072    */
00073   int status;
00074 
00075   status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_begin(obj);
00076   if (status < 0) return status;
00077 
00078   /* If we're writing this object, and we're doing it in raw form, then
00079         now is the time to inform the backend what the type of this data is.
00080    */
00081   if (obj->output_p &&
00082          obj->options &&
00083          !obj->options->write_html_p &&
00084          !obj->options->state->first_data_written_p)
00085        {
00086          status = MimeObject_output_init(obj, 0);
00087          if (status < 0) return status;
00088          NS_ASSERTION(obj->options->state->first_data_written_p, "first data not written");
00089        }
00090 
00091 #if defined(XP_MAC) || defined(XP_MACOSX)
00092   if (obj->options && obj->options->state) 
00093   {
00094 //     obj->options->state->separator_suppressed_p = PR_TRUE;
00095        goto done;
00096   }
00097   /*
00098    * It would be nice to not showing the resource fork links
00099    * if we are displaying inline. But, there is no way we could
00100    * know ahead of time that we could display the data fork and
00101    * the data fork is always hidden on MAC platform.
00102    */
00103 #endif
00104   /* If we're writing this object as HTML, then emit a link for the
00105         multipart/appledouble part (both links) that looks just like the
00106         links that MimeExternalObject emits for external leaf parts.
00107    */
00108   if (obj->options &&
00109          obj->output_p &&
00110          obj->options->write_html_p &&
00111          obj->options->output_fn)
00112        {
00113          char *id = 0;
00114          char *id_url = 0;
00115          char *id_imap = 0;
00116 
00117          id = mime_part_address (obj);
00118          if (! id) return MIME_OUT_OF_MEMORY;
00119          if (obj->options->missing_parts)
00120               id_imap = mime_imap_part_address (obj);
00121 
00122       if (obj->options && obj->options->url)
00123               {
00124                 const char *url = obj->options->url;
00125                 if (id_imap && id)
00126                 {
00127                      /* if this is an IMAP part. */
00128                      id_url = mime_set_url_imap_part(url, id_imap, id);
00129                 }
00130                 else
00131                 {
00132                      /* This is just a normal MIME part as usual. */
00133                      id_url = mime_set_url_part(url, id, PR_TRUE);
00134                 }
00135                 if (!id_url)
00136                      {
00137                        PR_Free(id);
00138                        return MIME_OUT_OF_MEMORY;
00139                      }
00140               }
00141 
00142 /**********************8
00143 RICHIE SHERRY
00144          if (!nsCRT::strcmp (id, "0"))
00145               {
00146                 PR_Free(id);
00147                 id = MimeGetStringByID(MIME_MSG_ATTACHMENT);
00148               }
00149          else
00150               {
00151                 const char *p = "Part ";  
00152                 char *s = (char *)PR_MALLOC(nsCRT::strlen(p) + nsCRT::strlen(id) + 1);
00153                 if (!s)
00154                      {
00155                        PR_Free(id);
00156                        PR_Free(id_url);
00157                        return MIME_OUT_OF_MEMORY;
00158                      }
00159                 PL_strcpy(s, p);
00160                 PL_strcat(s, id);
00161                 PR_Free(id);
00162                 id = s;
00163               }
00164 
00165          if (all_headers_p &&
00166                 // Don't bother showing all headers on this part if it's the only
00167                      // part in the message: in that case, we've already shown these
00168                      // headers. 
00169                 obj->options->state &&
00170                 obj->options->state->root == obj->parent)
00171               all_headers_p = PR_FALSE;
00172 
00173          newopt.fancy_headers_p = PR_TRUE;
00174          newopt.headers = (all_headers_p ? MimeHeadersAll : MimeHeadersSome);
00175 
00176 //
00177 RICHIE SHERRY
00178 GOTTA STILL DO THIS FOR QUOTING!
00179      status = MimeHeaders_write_attachment_box (obj->headers, &newopt,
00180                                                  obj->content_type,
00181                                                  obj->encoding,
00182                                                  id_name? id_name : id, id_url, 0
00183 //
00184 *********************************************************************************/
00185 
00186 //     FAIL:
00187          PR_FREEIF(id);
00188          PR_FREEIF(id_url);
00189          PR_FREEIF(id_imap);
00190          if (status < 0) return status;
00191        }
00192 
00193 #if defined(XP_MAC) || defined(XP_MACOSX)
00194 done:
00195 #endif
00196 
00197   return 0;
00198 }
00199 
00200 static PRBool
00201 MimeMultipartAppleDouble_output_child_p(MimeObject *obj, MimeObject *child)
00202 {
00203   MimeContainer *cont = (MimeContainer *) obj;
00204 
00205   /* If this is the first child, and it's an application/applefile, then
00206         don't emit a link for it.  (There *should* be only two children, and
00207         the first one should always be an application/applefile.)
00208    */
00209 
00210   if (cont->nchildren >= 1 && cont->children[0] == child && child->content_type &&
00211       !nsCRT::strcasecmp(child->content_type, APPLICATION_APPLEFILE))
00212   {
00213 #if defined(XP_MAC) || defined(XP_MACOSX)
00214     if (obj->output_p && obj->options && obj->options->write_html_p) //output HTML
00215       return PR_FALSE;
00216 #else
00217     /* if we are not on a Macintosh, don't emitte the resources fork at all. */
00218     return PR_FALSE;
00219 #endif
00220   }
00221   
00222   return PR_TRUE;
00223 }