Beispiel #1
0
void MessageWithAttachments::SetText(const DwString& aStr)
{
    // Create a body part and set the necessary fields

    MultipartBodyPart part;
    part.SetType(DwMime::kTypeText);
    part.SetSubtype(DwMime::kSubtypePlain);
    part.SetCte(DwMime::kCte7bit);

    // Set the string as the body of the body part

    part.SetBody(aStr);

    // Set this body part as the first one

    SetBodyPart(0, part);
}
Beispiel #2
0
void MultipartMessage::AddBodyPart(const MultipartBodyPart& aPart)
{
    DwBodyPart* part = DwBodyPart::NewBodyPart(mEmptyString, 0);

    const DwString& type     = aPart.TypeStr();
    const DwString& subtype  = aPart.SubtypeStr();
    const DwString& cte      = aPart.CteStr();
    const DwString& contDesc = aPart.ContentDescription();
    const DwString& contDisp = aPart.ContentDisposition();
    const DwString& bodyStr  = aPart.Body();

    DwHeaders& headers = part->Headers();
    if (type != "" && subtype != "") {
        headers.ContentType().SetTypeStr(type);
        headers.ContentType().SetSubtypeStr(subtype);
    }
    if (cte != "") {
        headers.Cte().FromString(cte);
    }
    if (contDesc != "") {
        headers.ContentDescription().FromString(contDesc);
    }
    if (contDisp != "") {
        headers.ContentDisposition().FromString(contDisp);
    }
    part->Body().FromString(bodyStr);

    mMessage->Body().AddBodyPart(part);
}
Beispiel #3
0
void MultipartMessage::SetBodyPart(int aIdx, const MultipartBodyPart& aPart)
{
    DwBody& body = mMessage->Body();
    int numParts = NumberOfParts();
    DwBodyPart* part = 0;
    // If indexed part exists already, just replace its values
    if (0 <= aIdx && aIdx < numParts) {
        part = body.FirstBodyPart();
        for (int curIdx=0; curIdx < aIdx; ++curIdx) {
            part = part->Next();
        }
    }
    // Otherwise, add as many new parts as necessary.
    else if (numParts <= aIdx) {
        while (numParts <= aIdx) {
            part = DwBodyPart::NewBodyPart(mEmptyString, 0);
            body.AddBodyPart(part);
            ++numParts;
        }
    }
    else /* if (aIdx < 0) */ {
        // error!
        return;
    }

    const DwString& type     = aPart.TypeStr();
    const DwString& subtype  = aPart.SubtypeStr();
    const DwString& cte      = aPart.CteStr();
    const DwString& contDesc = aPart.ContentDescription();
    const DwString& contDisp = aPart.ContentDisposition();
    const DwString& bodyStr  = aPart.Body();

    DwHeaders& headers = part->Headers();
    if (type != "" && subtype != "") {
        headers.ContentType().SetTypeStr(type);
        headers.ContentType().SetSubtypeStr(subtype);
    }
    if (cte != "") {
        headers.Cte().FromString(cte);
    }
    if (contDesc != "") {
        headers.ContentDescription().FromString(contDesc);
    }
    if (contDisp != "") {
        headers.ContentDisposition().FromString(contDisp);
    }
    part->Body().FromString(bodyStr);
}
Beispiel #4
0
void MessageWithAttachments::AttachBinaryFile(const char* aFilename,
    int aType, int aSubtype)
{
    // Get the file contents

    DwString str;
    PutFileInString(aFilename, str);
    
    // Encode using base64 encoding

    DwString encStr;
    DwEncodeBase64(str, encStr);
    
    // Create a body part and set the necessary fields

    MultipartBodyPart part;
    part.SetType(aType);
    part.SetSubtype(aSubtype);
    part.SetCte(DwMime::kCteBase64);

    // Set content-disposition to attachment, with filename parameter
    // (see RFC-1806 for information on this *experimental* header field)
    
    DwString contDisp = "attachment; filename=";
    contDisp += '\"';
    contDisp += aFilename;
    contDisp += '\"';
    part.SetContentDisposition(contDisp);

    // Set the encoded file contents as the body of the body part

    part.SetBody(encStr);

    // Make sure this is not the first part, since that is reserved for
    // the text
    
    if (NumberOfParts() == 0) {
        SetBodyPart(1, part);
    }
    else {
        AddBodyPart(part);
    }
}
Beispiel #5
0
void MultipartMessage::BodyPart(int aIdx, MultipartBodyPart& aPart)
{
    // Get the DwBodyPart for this index

    DwBodyPart* part = mMessage->Body().FirstBodyPart();
    for (int curIdx=0; curIdx < aIdx && part; ++curIdx) {
        part = part->Next();
    }

    // If the DwBodyPart was found get the header fields and body

    if (part != 0) {
        DwHeaders& headers = part->Headers();
        
        // Content-type

        if (headers.HasContentType()) {
            const DwString& type    = headers.ContentType().TypeStr();
            const DwString& subtype = headers.ContentType().SubtypeStr();
            aPart.SetTypeStr(type);
            aPart.SetSubtypeStr(subtype);
        }
        else {
            // Set to defaults
            aPart.SetTypeStr("Text");
            aPart.SetSubtypeStr("Plain");
        }

        // Content-transfer-encoding

        if (headers.HasContentTransferEncoding()) {
            const DwString& cte = headers.ContentTransferEncoding().AsString();
            aPart.SetCteStr(cte);
        }
        else {
            // Set to default
            aPart.SetCteStr("7bit");
        }

        // Content-description

        if (headers.HasContentDescription()) {
            const DwString& desc = headers.ContentDescription().AsString();
            aPart.SetContentDescription(desc);
        }
        else {
            aPart.SetContentDescription("");
        }

        // Content-disposition

        if (headers.HasContentDisposition()) {
            const DwString& disp = headers.ContentDisposition().AsString();
            aPart.SetContentDisposition(disp);
        }
        else {
            aPart.SetContentDisposition("");
        }

        // Body

        const DwString& body = part->Body().AsString();
        aPart.SetBody(body);
    }
    
    // If the body part was not found, set all MultipartBodyPart attributes
    // to empty values.  This only happens if you don't pay attention to
    // the value returned from NumberOfParts().
    else {
        aPart.SetTypeStr("");
        aPart.SetSubtypeStr("");
        aPart.SetCteStr("");
        aPart.SetContentDescription("");
        aPart.SetContentDisposition("");
        aPart.SetBody("");
    }
}