Max message size warning feature and labeling forwarded messages by subject - Bugs: 26519 5647 - r: jefft

This commit is contained in:
rhp%netscape.com 2000-02-08 01:15:54 +00:00
Родитель 0970222b53
Коммит 8cc87b679d
13 изменённых файлов: 166 добавлений и 44 удалений

Просмотреть файл

@ -144,4 +144,7 @@
## @name NS_MSG_START_COPY_MESSAGE_FAILED
12540=Copy failed.
## @name NS_MSG_LARGE_MESSAGE_WARNING
12541=Warning! You are about to send a %d byte message. Are you sure that you want to do this?
noIdentities=You don't have any email identities yet. Create one with the Account Wizard.

Просмотреть файл

@ -34,6 +34,7 @@
#include "nsIMsgMessageService.h"
#include "nsMsgUtils.h"
#include "nsMsgPrompts.h"
#include "nsTextFormatter.h"
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
@ -424,6 +425,18 @@ FetcherURLDoneCallback(nsIURI* aURL, nsresult aStatus,
ma->m_charset = PL_strdup(aCharset);
}
if ( (!PL_strcasecmp(ma->m_real_name, "ForwardedMessage.eml")) &&
(!PL_strcasecmp(ma->m_type, MESSAGE_RFC822))
)
{
char *subject = nsMsgParseSubjectFromFile(ma->mFileSpec);
if (subject)
{
PR_FREEIF(ma->m_real_name);
ma->m_real_name = subject;
}
}
return ma->UrlExit(aStatus, aMsg);
}
else
@ -443,9 +456,9 @@ nsMsgAttachmentHandler::SnarfMsgAttachment(nsMsgCompFields *compFields)
PR_FREEIF(m_real_name);
m_real_name = PL_strdup("ForwardedMessage.eml");
PR_FREEIF(m_type);
m_type = PL_strdup("message/rfc822");
m_type = PL_strdup(MESSAGE_RFC822);
PR_FREEIF(m_override_type);
m_override_type = PL_strdup("message/rfc822");
m_override_type = PL_strdup(MESSAGE_RFC822);
if (!mFileSpec)
{
rv = NS_ERROR_FAILURE;
@ -827,24 +840,17 @@ nsMsgAttachmentHandler::UrlExit(nsresult status, const PRUnichar* aMsg)
PRBool keepOnGoing = PR_TRUE;
nsXPIDLCString turl;
PRUnichar *msg = nsnull;
char *printfString = nsnull;
char *tString = nsnull;
PRUnichar *printfString = nsnull;
msg = ComposeGetStringByID(NS_MSG_FAILURE_ON_OBJ_EMBED);
nsCAutoString cQuestionString(msg);
msg = ComposeGetStringByID(NS_MSG_FAILURE_ON_OBJ_EMBED);
if (NS_SUCCEEDED(mURL->GetSpec(getter_Copies(turl))) && (turl))
tString = nsString(turl).ToNewCString();
if ( !tString )
printfString = PR_smprintf(cQuestionString, "?");
printfString = nsTextFormatter::smprintf(msg, turl);
else
printfString = PR_smprintf(cQuestionString, tString);
printfString = nsTextFormatter::smprintf(msg, "?");
nsMsgAskBooleanQuestionByString(nsString(printfString).GetUnicode(), &keepOnGoing);
PR_smprintf_free(printfString);
nsMsgAskBooleanQuestionByString(printfString, &keepOnGoing);
PR_FREEIF(printfString);
PR_FREEIF(msg);
PR_FREEIF(tString);
if (!keepOnGoing)
{

Просмотреть файл

@ -810,7 +810,7 @@ mime_generate_attachment_headers (const char *type, const char *encoding,
PRBool sendFlowed = PR_TRUE; /* rhp - add this */
if(type && !PL_strcasecmp(type, "text/plain") && prefs)
{
prefs->GetBoolPref("mail.send_plaintext_flowed", &sendFlowed);
prefs->GetBoolPref("mailnews.send_plaintext_flowed", &sendFlowed);
if (sendFlowed)
PUSH_STRING ("; format=flowed");
// else
@ -2070,3 +2070,46 @@ DoLineEndingConJobUnicode(PRUnichar *aBuf, PRUint32 aLen)
if (aBuf[i] == CR)
aBuf[i] = LF;
}
// Simple parser to parse Subject.
// It only supports the case when the description is within one line.
char *
nsMsgParseSubjectFromFile(nsFileSpec* fileSpec)
{
nsIFileSpec *tmpFileSpec = nsnull;
char *subject = nsnull;
char buffer[1024];
char *ptr = &buffer[0];
NS_NewFileSpecWithSpec(*fileSpec, &tmpFileSpec);
if (!tmpFileSpec)
return nsnull;
if (NS_FAILED(tmpFileSpec->OpenStreamForReading()))
return nsnull;
PRBool eof = PR_FALSE;
while ( NS_SUCCEEDED(tmpFileSpec->Eof(&eof)) && (!eof) )
{
PRBool wasTruncated = PR_FALSE;
if (NS_FAILED(tmpFileSpec->ReadLine(&ptr, sizeof(buffer), &wasTruncated)))
break;
if (wasTruncated)
continue;
if (*buffer == CR || *buffer == LF || *buffer == 0)
break;
if ( !PL_strncasecmp(buffer, "Subject: ", 9) )
{
subject = nsCRT::strdup(buffer + 9);
break;
}
}
tmpFileSpec->CloseStream();
return subject;
}

Просмотреть файл

@ -119,6 +119,7 @@ char *GenerateFileNameFromURI(nsIURI *aURL);
char *nsMsgGetExtensionFromFileURL(nsString aUrl);
char *GetFolderNameFromURLString(char *aUrl);
char *nsMsgParseSubjectFromFile(nsFileSpec* fileSpec);
//
// Folder calls...

Просмотреть файл

@ -74,6 +74,7 @@
#define NS_MSG_START_COPY_MESSAGE NS_MSG_GENERATE_SUCCESS(12538)
#define NS_MSG_START_COPY_MESSAGE_COMPLETE NS_MSG_GENERATE_SUCCESS(12539)
#define NS_MSG_START_COPY_MESSAGE_FAILED NS_MSG_GENERATE_FAILURE(12540)
#define NS_MSG_LARGE_MESSAGE_WARNING NS_MSG_GENERATE_FAILURE(12541)
NS_BEGIN_EXTERN_C

Просмотреть файл

@ -198,7 +198,7 @@ nsMsgQuote::QuoteMessage(const PRUnichar *msgURI, PRBool quoteHeaders, nsIStream
NS_WITH_SERVICE(nsIStreamConverterService, streamConverterService, kIStreamConverterServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsAutoString from, to;
from = "message/rfc822";
from = MESSAGE_RFC822;
to = "text/xul";
nsCOMPtr<nsIStreamListener> convertedListener;
rv = streamConverterService->AsyncConvertData(from.GetUnicode(),

Просмотреть файл

@ -64,6 +64,7 @@
#include "mozITXTToHTMLConv.h"
#include "nsIMsgStatusFeedback.h"
#include "nsIMsgMailSession.h"
#include "nsTextFormatter.h"
// use these macros to define a class IID for our component. Our object currently
// supports two interfaces (nsISupports and nsIMsgCompose) so we want to define constants
@ -79,6 +80,7 @@ static NS_DEFINE_CID(kTXTToHTMLConvCID, MOZITXTTOHTMLCONV_CID);
#define PREF_MAIL_CONVERT_STRUCTS "mail.convert_structs"
#define PREF_MAIL_STRICTLY_MIME "mail.strictly_mime"
#define PREF_MAIL_MESSAGE_WARNING_SIZE "mailnews.message_warning_size"
#ifdef XP_MAC
#include "xp.h" // mac only
@ -190,7 +192,7 @@ nsMsgComposeAndSend::nsMsgComposeAndSend() :
mRemoteAttachmentCount = 0;
mCompFieldLocalAttachments = 0;
mCompFieldRemoteAttachments = 0;
mMessageWarningSize = 0;
// note: it is okay to return a null status feedback and not return an error
// it's possible the url really doesn't have status feedback
@ -2153,24 +2155,23 @@ nsMsgComposeAndSend::HackAttachments(const nsMsgAttachmentData *attachments,
//
// Display some feedback to user...
char *printfString = nsnull;
PRUnichar *printfString = nsnull;
PRUnichar *msg = nsnull;
msg = ComposeGetStringByID(NS_MSG_GATHERING_ATTACHMENT);
nsCAutoString cProgressString(msg);
PR_FREEIF(msg);
if (m_attachments[i].m_real_name)
printfString = PR_smprintf(cProgressString, m_attachments[i].m_real_name);
printfString = nsTextFormatter::smprintf(msg, m_attachments[i].m_real_name);
else
printfString = PR_smprintf(cProgressString, "");
printfString = nsTextFormatter::smprintf(msg, "");
if (printfString)
{
nsString formattedString(printfString);
SetStatusMessage((PRUnichar *)formattedString.GetUnicode());
PR_smprintf_free(printfString);
SetStatusMessage(printfString);
PR_FREEIF(printfString);
}
PR_FREEIF(msg);
int status = m_attachments[i].SnarfAttachment(mCompFields);
if (status < 0)
@ -2483,6 +2484,7 @@ nsMsgComposeAndSend::Init(
if (NS_SUCCEEDED(rv) && prefs)
{
rv = prefs->GetBoolPref(PREF_MAIL_STRICTLY_MIME, &strictly_mime);
rv = prefs->GetIntPref(PREF_MAIL_MESSAGE_WARNING_SIZE, (PRInt32 *) &mMessageWarningSize);
}
nsMsgMIMESetConformToStandard(strictly_mime);
@ -2592,6 +2594,39 @@ nsMsgComposeAndSend::DeliverMessage()
return SaveAsTemplate();
}
//
// Ok, we are about to send the file that we have built up...but what
// if this is a mongo email...we should have a way to warn the user that
// they are about to do something they may not want to do.
//
if ( (mMessageWarningSize > 0) && (mTempFileSpec->GetFileSize() > mMessageWarningSize) )
{
PRBool abortTheSend = PR_FALSE;
PRUnichar *msg = ComposeGetStringByID(NS_MSG_LARGE_MESSAGE_WARNING);
if (msg)
{
PRUnichar *printfString = nsTextFormatter::smprintf(msg, mTempFileSpec->GetFileSize());
PR_FREEIF(msg);
if (printfString)
{
nsMsgAskBooleanQuestionByString(printfString, &abortTheSend);
if (!abortTheSend)
{
Fail(NS_ERROR_BUT_DONT_SHOW_ALERT, printfString);
PR_FREEIF(printfString);
NotifyListenersOnStopCopy(NS_ERROR_FAILURE);
return NS_ERROR_FAILURE;
}
else
PR_FREEIF(printfString);
}
}
}
if (news_p) {
if (mail_p) {
mSendMailAlso = PR_TRUE;
@ -3531,10 +3566,9 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file,
char *envelopeLine = nsMsgGetEnvelopeLine();
PRBool folderIsLocal = PR_TRUE;
char *turi = nsnull;
char *printfString = nsnull;
PRUnichar *printfString = nsnull;
PRUnichar *msg = nsnull;
char *folderName = nsnull;
char *cProgressString = nsnull;
//
// Ok, this is here to keep track of this for 2 copy operations...
@ -3623,25 +3657,23 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file,
// Tell the user we are copying the message...
msg = ComposeGetStringByID(NS_MSG_START_COPY_MESSAGE);
cProgressString = nsString(msg).ToNewCString();
PR_FREEIF(msg);
folderName = GetFolderNameFromURLString(turi);
if (cProgressString)
if (msg)
{
folderName = GetFolderNameFromURLString(turi);
if (folderName)
printfString = PR_smprintf(cProgressString, folderName);
printfString = nsTextFormatter::smprintf(msg, folderName);
else
printfString = PR_smprintf(cProgressString, "?");
PR_FREEIF(cProgressString);
printfString = nsTextFormatter::smprintf(msg, "?");
if (printfString)
{
nsString formattedString(printfString);
SetStatusMessage((PRUnichar *)formattedString.GetUnicode());
PR_smprintf_free(printfString);
SetStatusMessage(printfString);
PR_FREEIF(printfString);
}
}
PR_FREEIF(folderName);
PR_FREEIF(msg);
if ( (envelopeLine) && (folderIsLocal) )
{
PRInt32 len = PL_strlen(envelopeLine);

Просмотреть файл

@ -336,6 +336,7 @@ public:
nsFileSpec *mTempFileSpec; // our temporary file
nsOutputFileStream *mOutputFile; // the actual output file stream
PRUint32 mMessageWarningSize; // Warn if a message is over this size!
PRBool m_dont_deliver_p; // If set, we just return the nsFileSpec of the file
// created, instead of actually delivering message.

Просмотреть файл

@ -131,7 +131,7 @@ nsURLFetcher::CanHandleContent(const char * aContentType,
PRBool * aCanHandleContent)
{
if (nsCRT::strcasecmp(aContentType, "message/rfc822") == 0)
if (nsCRT::strcasecmp(aContentType, MESSAGE_RFC822) == 0)
*aDesiredContentType = nsCRT::strdup("text/html");
// since we explicilty loaded the url, we always want to handle it!

Просмотреть файл

@ -199,7 +199,7 @@ CountTotalMimeAttachments(MimeContainer *aObj)
}
void
ValidateRealName(nsMsgAttachmentData *aAttach)
ValidateRealName(nsMsgAttachmentData *aAttach, MimeHeaders *aHdrs)
{
// Sanity.
if (!aAttach)
@ -219,7 +219,10 @@ ValidateRealName(nsMsgAttachmentData *aAttach)
if (aAttach->real_type && !nsCRT::strcasecmp(aAttach->real_type, MESSAGE_RFC822) &&
(!aAttach->real_name || *aAttach->real_name == 0))
{
mime_SACopy(&(aAttach->real_name), "ForwardedMessage.eml");
if (aHdrs->munged_subject)
mime_SACopy(&(aAttach->real_name), aHdrs->munged_subject);
else
mime_SACopy(&(aAttach->real_name), "ForwardedMessage.eml");
return;
}
@ -360,7 +363,7 @@ BuildAttachmentList(MimeObject *aChild, nsMsgAttachmentData *aAttachData,
PR_FALSE, PR_FALSE);
// Now, do the right thing with the name!
ValidateRealName(tmp);
ValidateRealName(tmp, child->headers);
}
return NS_OK;

Просмотреть файл

@ -85,6 +85,9 @@ MimeMessageClassInitialize(MimeMessageClass *clazz)
static int
MimeMessage_initialize (MimeObject *object)
{
MimeMessage *msg = (MimeMessage *)object;
msg->grabSubject = PR_FALSE;
return ((MimeObjectClass*)&MIME_SUPERCLASS)->initialize(object);
}
@ -101,9 +104,16 @@ MimeMessage_finalize (MimeObject *object)
static int
MimeMessage_parse_begin (MimeObject *obj)
{
MimeMessage *msg = (MimeMessage *)obj;
int status = ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_begin(obj);
if (status < 0) return status;
if (obj->parent)
{
msg->grabSubject = PR_TRUE;
}
/* Messages have separators before the headers, except for the outermost
message. */
return MimeObject_write_separator(obj);
@ -123,6 +133,27 @@ MimeMessage_parse_line (char *line, PRInt32 length, MimeObject *obj)
HG11013
#endif /* MOZ_SECURITY */
if (msg->grabSubject)
{
if ( (!PL_strncasecmp(line, "Subject: ", 9)) && (obj->parent) )
{
if ( (obj->headers) && (!obj->headers->munged_subject) )
{
obj->headers->munged_subject = (char *) PL_strndup(line + 9, length - 9);
char *tPtr = obj->headers->munged_subject;
while (*tPtr)
{
if ( (*tPtr == CR) || (*tPtr == LF) )
{
*tPtr = '\0';
break;
}
tPtr++;
}
}
}
}
/* If we already have a child object, then we're done parsing headers,
and all subsequent lines get passed to the inferior object without
further processing by us. (Our parent will stop feeding us lines

Просмотреть файл

@ -48,6 +48,7 @@ struct MimeMessage {
PRBool xlation_msg_signed_p; /* What the emitted xlation-stamp *says*. */
PRBool xlation_msg_xlated_p;
PRBool grabSubject; /* Should we try to grab the subject of this message */
};
#endif /* _MIMEMSG_H_ */

Просмотреть файл

@ -68,7 +68,7 @@ typedef struct MimeHeaders
the subject header, after it's been
charset-ified and stuff. Remembered so that
we can later use it to generate the
<TITLE> tag. */
<TITLE> tag. (Also works for giving names to RFC822 attachments) */
} MimeHeaders;
typedef struct MimeDisplayOptions MimeDisplayOptions;