";
const char *url;
char *buf;
PR_ASSERT(mid);
if (!mid) return 0;
/* Internal-external-reconnect only works when going to the screen. */
if (!mid->istream)
return strdup("
");
nsCOMPtr prefBranch;
nsCOMPtr prefSvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
bool resize = true;
if (prefSvc)
prefSvc->GetBranch("", getter_AddRefs(prefBranch));
if (prefBranch)
prefBranch->GetBoolPref("mail.enable_automatic_image_resizing", &resize); // ignore return value
prefix = resize ? scaledPrefix : unscaledPrefix;
if ( (!mid->url) || (!(*mid->url)) )
url = "";
else
url = mid->url;
uint32_t buflen = strlen(prefix) + strlen(suffix) + strlen(url) + 20;
buf = (char *) PR_MALLOC (buflen);
if (!buf)
return 0;
*buf = 0;
PL_strcatn (buf, buflen, prefix);
PL_strcatn (buf, buflen, url);
PL_strcatn (buf, buflen, suffix);
return buf;
}
static int
mime_image_write_buffer(const char *buf, int32_t size, void *image_closure)
{
mime_image_stream_data *mid =
(mime_image_stream_data *) image_closure;
mime_stream_data *msd = mid->msd;
if ( ( (!msd->output_emitter) ) &&
( (!msd->pluginObj2) ) )
return -1;
return size;
}
MimeObject*
mime_get_main_object(MimeObject* obj)
{
MimeContainer *cobj;
if (!(mime_subclass_p(obj->clazz, (MimeObjectClass*) &mimeMessageClass)))
{
return obj;
}
cobj = (MimeContainer*) obj;
if (cobj->nchildren != 1) return obj;
obj = cobj->children[0];
while (obj)
{
if ( (!mime_subclass_p(obj->clazz,
(MimeObjectClass*) &mimeMultipartSignedClass)) &&
(PL_strcasecmp(obj->content_type, MULTIPART_SIGNED) != 0)
)
{
return obj;
}
else
{
if (mime_subclass_p(obj->clazz, (MimeObjectClass*)&mimeContainerClass))
{
// We don't care about a signed/smime object; Go inside to the
// thing that we signed or smime'ed
//
cobj = (MimeContainer*) obj;
if (cobj->nchildren > 0)
obj = cobj->children[0];
else
obj = nullptr;
}
else
{
// we received a message with a child object that looks like a signed
// object, but it is not a subclass of mimeContainer, so let's
// return the given child object.
return obj;
}
}
}
return nullptr;
}
static
bool MimeObjectIsMessageBodyNoClimb(MimeObject *parent,
MimeObject *looking_for,
bool *stop)
{
MimeContainer *container = (MimeContainer *)parent;
int32_t i;
char *disp;
NS_ASSERTION(stop, "NULL stop to MimeObjectIsMessageBodyNoClimb");
for (i = 0; i < container->nchildren; i++) {
MimeObject *child = container->children[i];
bool is_body = true;
// The body can't be something we're not displaying.
if (! child->output_p)
is_body = false;
else if ((disp = MimeHeaders_get (child->headers, HEADER_CONTENT_DISPOSITION,
true, false))) {
PR_Free(disp);
is_body = false;
}
else if (PL_strcasecmp (child->content_type, TEXT_PLAIN) &&
PL_strcasecmp (child->content_type, TEXT_HTML) &&
PL_strcasecmp (child->content_type, TEXT_MDL) &&
PL_strcasecmp (child->content_type, MESSAGE_NEWS) &&
PL_strcasecmp (child->content_type, MESSAGE_RFC822))
is_body = false;
if (is_body || child == looking_for) {
*stop = true;
return child == looking_for;
}
// The body could be down inside a multipart child, so search recursively.
if (mime_subclass_p(child->clazz, (MimeObjectClass*) &mimeContainerClass)) {
is_body = MimeObjectIsMessageBodyNoClimb(child, looking_for, stop);
if (is_body || *stop)
return is_body;
}
}
return false;
}
/* Should this be static in mimemult.cpp? */
bool MimeObjectIsMessageBody(MimeObject *looking_for)
{
bool stop = false;
MimeObject *root = looking_for;
while (root->parent)
root = root->parent;
return MimeObjectIsMessageBodyNoClimb(root, looking_for, &stop);
}
//
// New Stream Converter Interface
//
// Get the connnection to prefs service manager
nsIPrefBranch *
GetPrefBranch(MimeDisplayOptions *opt)
{
if (!opt)
return nullptr;
return opt->m_prefBranch;
}
// Get the text converter...
mozITXTToHTMLConv *
GetTextConverter(MimeDisplayOptions *opt)
{
if (!opt)
return nullptr;
return opt->conv;
}
MimeDisplayOptions::MimeDisplayOptions()
{
conv = nullptr; // For text conversion...
format_out = 0; // The format out type
url = nullptr;
memset(&headers,0, sizeof(headers));
fancy_headers_p = false;
output_vcard_buttons_p = false;
variable_width_plaintext_p = false;
wrap_long_lines_p = false;
rot13_p = false;
part_to_load = nullptr;
no_output_p = false;
write_html_p = false;
decrypt_p = false;
whattodo = 0 ;
default_charset = nullptr;
override_charset = false;
force_user_charset = false;
stream_closure = nullptr;
/* For setting up the display stream, so that the MIME parser can inform
the caller of the type of the data it will be getting. */
output_init_fn = nullptr;
output_fn = nullptr;
output_closure = nullptr;
charset_conversion_fn = nullptr;
rfc1522_conversion_p = false;
file_type_fn = nullptr;
passwd_prompt_fn = nullptr;
html_closure = nullptr;
generate_header_html_fn = nullptr;
generate_post_header_html_fn = nullptr;
generate_footer_html_fn = nullptr;
generate_reference_url_fn = nullptr;
generate_mailto_url_fn = nullptr;
generate_news_url_fn = nullptr;
image_begin = nullptr;
image_end = nullptr;
image_write_buffer = nullptr;
make_image_html = nullptr;
state = nullptr;
#ifdef MIME_DRAFTS
decompose_file_p = false;
done_parsing_outer_headers = false;
is_multipart_msg = false;
decompose_init_count = 0;
signed_p = false;
caller_need_root_headers = false;
decompose_headers_info_fn = nullptr;
decompose_file_init_fn = nullptr;
decompose_file_output_fn = nullptr;
decompose_file_close_fn = nullptr;
#endif /* MIME_DRAFTS */
attachment_icon_layer_id = 0;
missing_parts = false;
show_attachment_inline_p = false;
quote_attachment_inline_p = false;
notify_nested_bodies = false;
write_pure_bodies = false;
metadata_only = false;
}
MimeDisplayOptions::~MimeDisplayOptions()
{
PR_FREEIF(part_to_load);
PR_FREEIF(default_charset);
}
////////////////////////////////////////////////////////////////
// Bridge routines for new stream converter XP-COM interface
////////////////////////////////////////////////////////////////
extern "C" void *
mime_bridge_create_display_stream(
nsIMimeEmitter *newEmitter,
nsStreamConverter *newPluginObj2,
nsIURI *uri,
nsMimeOutputType format_out,
uint32_t whattodo,
nsIChannel *aChannel)
{
int status = 0;
MimeObject *obj;
mime_stream_data *msd;
nsMIMESession *stream = 0;
if (!uri)
return nullptr;
msd = new mime_stream_data;
if (!msd)
return NULL;
// Assign the new mime emitter - will handle output operations
msd->output_emitter = newEmitter;
msd->firstCheck = true;
// Store the URL string for this decode operation
nsAutoCString urlString;
nsresult rv;
// Keep a hold of the channel...
msd->channel = aChannel;
rv = uri->GetSpec(urlString);
if (NS_SUCCEEDED(rv))
{
if (!urlString.IsEmpty())
{
msd->url_name = ToNewCString(urlString);
if (!(msd->url_name))
{
delete msd;
return NULL;
}
nsCOMPtr msgUrl = do_QueryInterface(uri);
if (msgUrl)
msgUrl->GetOriginalSpec(&msd->orig_url_name);
}
}
msd->format_out = format_out; // output format
msd->pluginObj2 = newPluginObj2; // the plugin object pointer
msd->options = new MimeDisplayOptions;
if (!msd->options)
{
delete msd;
return 0;
}
// memset(msd->options, 0, sizeof(*msd->options));
msd->options->format_out = format_out; // output format
msd->options->m_prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv))
{
delete msd;
return nullptr;
}
// Need the text converter...
rv = CallCreateInstance(MOZ_TXTTOHTMLCONV_CONTRACTID, &(msd->options->conv));
if (NS_FAILED(rv))
{
msd->options->m_prefBranch = nullptr;
delete msd;
return nullptr;
}
//
// Set the defaults, based on the context, and the output-type.
//
MIME_HeaderType = MimeHeadersAll;
msd->options->write_html_p = true;
switch (format_out)
{
case nsMimeOutput::nsMimeMessageSplitDisplay: // the wrapper HTML output to produce the split header/body display
case nsMimeOutput::nsMimeMessageHeaderDisplay: // the split header/body display
case nsMimeOutput::nsMimeMessageBodyDisplay: // the split header/body display
msd->options->fancy_headers_p = true;
msd->options->output_vcard_buttons_p = true;
break;
case nsMimeOutput::nsMimeMessageSaveAs: // Save As operations
case nsMimeOutput::nsMimeMessageQuoting: // all HTML quoted/printed output
case nsMimeOutput::nsMimeMessagePrintOutput:
msd->options->fancy_headers_p = true;
break;
case nsMimeOutput::nsMimeMessageBodyQuoting: // only HTML body quoted output
MIME_HeaderType = MimeHeadersNone;
break;
case nsMimeOutput::nsMimeMessageAttach: // handling attachment storage
msd->options->write_html_p = false;
break;
case nsMimeOutput::nsMimeMessageRaw: // the raw RFC822 data (view source) and attachments
case nsMimeOutput::nsMimeMessageDraftOrTemplate: // Loading drafts & templates
case nsMimeOutput::nsMimeMessageEditorTemplate: // Loading templates into editor
case nsMimeOutput::nsMimeMessageFilterSniffer: // generating an output that can be scan by a message filter
break;
case nsMimeOutput::nsMimeMessageDecrypt:
msd->options->decrypt_p = true;
msd->options->write_html_p = false;
break;
}
////////////////////////////////////////////////////////////
// Now, get the libmime prefs...
////////////////////////////////////////////////////////////
MIME_WrapLongLines = true;
MIME_VariableWidthPlaintext = true;
msd->options->force_user_charset = false;
if (msd->options->m_prefBranch)
{
msd->options->m_prefBranch->GetBoolPref("mail.wrap_long_lines", &MIME_WrapLongLines);
msd->options->m_prefBranch->GetBoolPref("mail.fixed_width_messages", &MIME_VariableWidthPlaintext);
//
// Charset overrides takes place here
//
// We have a bool pref (mail.force_user_charset) to deal with attachments.
// 1) If true - libmime does NO conversion and just passes it through to raptor
// 2) If false, then we try to use the charset of the part and if not available,
// the charset of the root message
//
msd->options->m_prefBranch->GetBoolPref("mail.force_user_charset", &(msd->options->force_user_charset));
msd->options->m_prefBranch->GetBoolPref("mail.inline_attachments", &(msd->options->show_attachment_inline_p));
msd->options->m_prefBranch->GetBoolPref("mail.reply_quote_inline", &(msd->options->quote_attachment_inline_p));
msd->options->m_prefBranch->GetIntPref("mailnews.display.html_as", &(msd->options->html_as_p));
}
/* This pref is written down in with the
opposite sense of what we like to use... */
MIME_VariableWidthPlaintext = !MIME_VariableWidthPlaintext;
msd->options->wrap_long_lines_p = MIME_WrapLongLines;
msd->options->headers = MIME_HeaderType;
// We need to have the URL to be able to support the various
// arguments
status = mime_parse_url_options(msd->url_name, msd->options);
if (status < 0)
{
PR_FREEIF(msd->options->part_to_load);
PR_Free(msd->options);
delete msd;
return 0;
}
if (msd->options->headers == MimeHeadersMicro &&
(msd->url_name == NULL || (strncmp(msd->url_name, "news:", 5) != 0 &&
strncmp(msd->url_name, "snews:", 6) != 0)) )
msd->options->headers = MimeHeadersMicroPlus;
msd->options->url = msd->url_name;
msd->options->output_init_fn = mime_output_init_fn;
msd->options->output_fn = mime_output_fn;
msd->options->whattodo = whattodo;
msd->options->charset_conversion_fn = mime_convert_charset;
msd->options->rfc1522_conversion_p = true;
msd->options->file_type_fn = mime_file_type;
msd->options->stream_closure = msd;
msd->options->passwd_prompt_fn = 0;
msd->options->image_begin = mime_image_begin;
msd->options->image_end = mime_image_end;
msd->options->make_image_html = mime_image_make_image_html;
msd->options->image_write_buffer = mime_image_write_buffer;
msd->options->variable_width_plaintext_p = MIME_VariableWidthPlaintext;
// If this is a part, then we should emit the HTML to render the data
// (i.e. embedded images)
if (msd->options->part_to_load && msd->options->format_out != nsMimeOutput::nsMimeMessageBodyDisplay)
msd->options->write_html_p = false;
obj = mime_new ((MimeObjectClass *)&mimeMessageClass, (MimeHeaders *) NULL, MESSAGE_RFC822);
if (!obj)
{
delete msd->options;
delete msd;
return 0;
}
obj->options = msd->options;
msd->obj = obj;
/* Both of these better not be true at the same time. */
PR_ASSERT(! (obj->options->decrypt_p && obj->options->write_html_p));
stream = PR_NEW(nsMIMESession);
if (!stream)
{
delete msd->options;
delete msd;
PR_Free(obj);
return 0;
}
ResetMsgHeaderSinkProps(uri);
memset (stream, 0, sizeof (*stream));
stream->name = "MIME Conversion Stream";
stream->complete = mime_display_stream_complete;
stream->abort = mime_display_stream_abort;
stream->put_block = mime_display_stream_write;
stream->data_object = msd;
status = obj->clazz->initialize(obj);
if (status >= 0)
status = obj->clazz->parse_begin(obj);
if (status < 0)
{
PR_Free(stream);
delete msd->options;
delete msd;
PR_Free(obj);
return 0;
}
return stream;
}
//
// Emitter Wrapper Routines!
//
nsIMimeEmitter *
GetMimeEmitter(MimeDisplayOptions *opt)
{
mime_stream_data *msd = (mime_stream_data *)opt->stream_closure;
if (!msd)
return NULL;
nsIMimeEmitter *ptr = (nsIMimeEmitter *)(msd->output_emitter);
return ptr;
}
mime_stream_data *
GetMSD(MimeDisplayOptions *opt)
{
if (!opt)
return nullptr;
mime_stream_data *msd = (mime_stream_data *)opt->stream_closure;
return msd;
}
bool
NoEmitterProcessing(nsMimeOutputType format_out)
{
if ( (format_out == nsMimeOutput::nsMimeMessageDraftOrTemplate) ||
(format_out == nsMimeOutput::nsMimeMessageEditorTemplate))
return true;
else
return false;
}
extern "C" nsresult
mimeEmitterAddAttachmentField(MimeDisplayOptions *opt, const char *field, const char *value)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
return emitter->AddAttachmentField(field, value);
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterAddHeaderField(MimeDisplayOptions *opt, const char *field, const char *value)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
return emitter->AddHeaderField(field, value);
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterAddAllHeaders(MimeDisplayOptions *opt, const char *allheaders, const int32_t allheadersize)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
return emitter->AddAllHeaders(Substring(allheaders,
allheaders + allheadersize));
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterStartAttachment(MimeDisplayOptions *opt, const char *name, const char *contentType, const char *url,
bool aIsExternalAttachment)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
return emitter->StartAttachment(nsDependentCString(name), contentType, url,
aIsExternalAttachment);
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterEndAttachment(MimeDisplayOptions *opt)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
if (emitter)
return emitter->EndAttachment();
else
return NS_OK;
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterEndAllAttachments(MimeDisplayOptions *opt)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
if (emitter)
return emitter->EndAllAttachments();
else
return NS_OK;
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterStartBody(MimeDisplayOptions *opt, bool bodyOnly, const char *msgID, const char *outCharset)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
return emitter->StartBody(bodyOnly, msgID, outCharset);
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterEndBody(MimeDisplayOptions *opt)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
return emitter->EndBody();
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterEndHeader(MimeDisplayOptions *opt, MimeObject *obj)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
nsCString name;
if (msd->format_out == nsMimeOutput::nsMimeMessageSplitDisplay ||
msd->format_out == nsMimeOutput::nsMimeMessageHeaderDisplay ||
msd->format_out == nsMimeOutput::nsMimeMessageBodyDisplay ||
msd->format_out == nsMimeOutput::nsMimeMessageSaveAs ||
msd->format_out == nsMimeOutput::nsMimeMessagePrintOutput) {
if (obj->headers) {
nsMsgAttachmentData attachment;
attIndex = 0;
nsresult rv = GenerateAttachmentData(obj, msd->url_name, opt, false,
0, &attachment);
if (NS_SUCCEEDED(rv))
name.Assign(attachment.m_realName);
}
}
MimeHeaders_convert_header_value(opt, name, false);
return emitter->EndHeader(name);
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterUpdateCharacterSet(MimeDisplayOptions *opt, const char *aCharset)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
return emitter->UpdateCharacterSet(aCharset);
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeEmitterStartHeader(MimeDisplayOptions *opt, bool rootMailHeader, bool headerOnly, const char *msgID,
const char *outCharset)
{
// Check for draft processing...
if (NoEmitterProcessing(opt->format_out))
return NS_OK;
mime_stream_data *msd = GetMSD(opt);
if (!msd)
return NS_ERROR_FAILURE;
if (msd->output_emitter)
{
nsIMimeEmitter *emitter = (nsIMimeEmitter *)msd->output_emitter;
return emitter->StartHeader(rootMailHeader, headerOnly, msgID, outCharset);
}
return NS_ERROR_FAILURE;
}
extern "C" nsresult
mimeSetNewURL(nsMIMESession *stream, char *url)
{
if ( (!stream) || (!url) || (!*url) )
return NS_ERROR_FAILURE;
mime_stream_data *msd = (mime_stream_data *)stream->data_object;
if (!msd)
return NS_ERROR_FAILURE;
char *tmpPtr = strdup(url);
if (!tmpPtr)
return NS_ERROR_OUT_OF_MEMORY;
PR_FREEIF(msd->url_name);
msd->url_name = tmpPtr;
return NS_OK;
}
#define MIME_URL "chrome://messenger/locale/mime.properties"
extern "C"
char *
MimeGetStringByID(int32_t stringID)
{
nsCOMPtr stringBundleService =
mozilla::services::GetStringBundleService();
nsCOMPtr stringBundle;
stringBundleService->CreateBundle(MIME_URL, getter_AddRefs(stringBundle));
if (stringBundle)
{
nsString v;
if (NS_SUCCEEDED(stringBundle->GetStringFromID(stringID, getter_Copies(v))))
return ToNewUTF8String(v);
}
return strdup("???");
}
extern "C"
char *
MimeGetStringByName(const char16_t *stringName)
{
nsCOMPtr stringBundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
nsCOMPtr stringBundle;
stringBundleService->CreateBundle(MIME_URL, getter_AddRefs(stringBundle));
if (stringBundle)
{
nsString v;
if (NS_SUCCEEDED(stringBundle->GetStringFromName(stringName, getter_Copies(v))))
return ToNewUTF8String(v);
}
return strdup("???");
}
void
ResetChannelCharset(MimeObject *obj)
{
if (obj->options && obj->options->stream_closure &&
obj->options->default_charset && obj->headers )
{
mime_stream_data *msd = (mime_stream_data *) (obj->options->stream_closure);
char *ct = MimeHeaders_get (obj->headers, HEADER_CONTENT_TYPE, false, false);
if ( (ct) && (msd) && (msd->channel) )
{
char *ptr = strstr(ct, "charset=");
if (ptr)
{
// First, setup the channel!
msd->channel->SetContentType(nsDependentCString(ct));
// Second, if this is a Save As operation, then we need to convert
// to override the output charset!
mime_stream_data *msd = GetMSD(obj->options);
if ( (msd) && (msd->format_out == nsMimeOutput::nsMimeMessageSaveAs) )
{
// Extract the charset alone
char *cSet = nullptr;
if (*(ptr+8) == '"')
cSet = strdup(ptr+9);
else
cSet = strdup(ptr+8);
if (cSet)
{
char *ptr2 = cSet;
while ( (*cSet) && (*cSet != ' ') && (*cSet != ';') &&
(*cSet != '\r') && (*cSet != '\n') && (*cSet != '"') )
ptr2++;
if (*cSet) {
PR_FREEIF(obj->options->default_charset);
obj->options->default_charset = strdup(cSet);
obj->options->override_charset = true;
}
PR_FREEIF(cSet);
}
}
}
PR_FREEIF(ct);
}
}
}
////////////////////////////////////////////////////////////
// Function to get up mail/news fontlang
////////////////////////////////////////////////////////////
nsresult GetMailNewsFont(MimeObject *obj, bool styleFixed, int32_t *fontPixelSize,
int32_t *fontSizePercentage, nsCString& fontLang)
{
nsresult rv = NS_OK;
nsIPrefBranch *prefBranch = GetPrefBranch(obj->options);
if (prefBranch) {
MimeInlineText *text = (MimeInlineText *) obj;
nsAutoCString charset;
// get a charset
if (!text->initializeCharset)
((MimeInlineTextClass*)&mimeInlineTextClass)->initialize_charset(obj);
if (!text->charset || !(*text->charset))
charset.Assign("us-ascii");
else
charset.Assign(text->charset);
nsCOMPtr charSetConverterManager2;
nsCOMPtr langGroupAtom;
nsAutoCString prefStr;
ToLowerCase(charset);
charSetConverterManager2 = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
if ( NS_FAILED(rv))
return rv;
// get a language, e.g. x-western, ja
rv = charSetConverterManager2->GetCharsetLangGroup(charset.get(), getter_AddRefs(langGroupAtom));
if (NS_FAILED(rv))
return rv;
rv = langGroupAtom->ToUTF8String(fontLang);
if (NS_FAILED(rv))
return rv;
// get a font size from pref
prefStr.Assign(!styleFixed ? "font.size.variable." : "font.size.fixed.");
prefStr.Append(fontLang);
rv = prefBranch->GetIntPref(prefStr.get(), fontPixelSize);
if (NS_FAILED(rv))
return rv;
nsCOMPtr prefDefBranch;
nsCOMPtr prefSvc(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
if(prefSvc)
rv = prefSvc->GetDefaultBranch("", getter_AddRefs(prefDefBranch));
if(!prefDefBranch)
return rv;
// get original font size
int32_t originalSize;
rv = prefDefBranch->GetIntPref(prefStr.get(), &originalSize);
if (NS_FAILED(rv))
return rv;
// calculate percentage
*fontSizePercentage = originalSize ?
(int32_t)((float)*fontPixelSize / (float)originalSize * 100) : 0;
}
return NS_OK;
}
/**
* This function synchronously converts an HTML document (as string)
* to plaintext (as string) using the Gecko converter.
*
* @param flags see nsIDocumentEncoder.h
*/
nsresult
HTML2Plaintext(const nsString& inString, nsString& outString,
uint32_t flags, uint32_t wrapCol)
{
nsCOMPtr utils =
do_GetService(NS_PARSERUTILS_CONTRACTID);
return utils->ConvertToPlainText(inString, flags, wrapCol, outString);
}
/**
* This function synchronously sanitizes an HTML document (string->string)
* using the Gecko nsTreeSanitizer.
*/
nsresult
HTMLSanitize(const nsString& inString, nsString& outString)
{
// If you want to add alternative sanitization, you can insert a conditional
// call to another sanitizer and an early return here.
uint32_t flags = nsIParserUtils::SanitizerCidEmbedsOnly |
nsIParserUtils::SanitizerDropForms;
nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
bool dropPresentational = true;
bool dropMedia = false;
prefs->GetBoolPref(
"mailnews.display.html_sanitizer.drop_non_css_presentation",
&dropPresentational);
prefs->GetBoolPref(
"mailnews.display.html_sanitizer.drop_media",
&dropMedia);
if (dropPresentational)
flags |= nsIParserUtils::SanitizerDropNonCSSPresentation;
if (dropMedia)
flags |= nsIParserUtils::SanitizerDropMedia;
nsCOMPtr utils = do_GetService(NS_PARSERUTILS_CONTRACTID);
return utils->Sanitize(inString, flags, outString);
}