Ejemplo n.º 1
0
bool SmsClient::addMail(const QMailMessage& mail)
{
    QList<QMailAddress> smsRecipients = separateSmsAddresses(mail.recipients());
    Q_ASSERT(smsRecipients.count() > 0);

    QString smsBody = formatOutgoing(mail.subject(),mail.body().data());

    foreach (const QMailAddress& recipient, smsRecipients)
    {
        if(smsAddress(recipient))
        {
            if(!validSmsAddress(recipient))
            {
                QString temp = "<qt>" + tr("Invalid SMS recipient specified for\n "
                   "mail with subject:\n%1\n"
                   "NO mail has been sent.")
                .arg( mail.subject() ) + "</qt>";

                emit errorOccurred(0,temp);
                return false;
            }
            else
            {
                //address is valid, queue for sending

                // Extract the phone number from the e-mail address.
                RawSms msg;
                msg.msgId = mail.id();
                msg.number = QPhoneNumber::resolveLetters( recipient.address() );
                msg.body = smsBody;
                if (mail.contentType().content().toLower() == "text/x-vcard")
                    msg.mimetype = QLatin1String("text/x-vCard");
                else
                    msg.mimetype = QLatin1String("text/plain");
                smsList.append( msg );
            }
        }
    }

    return true;
}
/**
 * Calculates and returns numberofDataSegments of the Message.
 */
int CSmsPlatformServiceS60Impl::getSmsDataSegments(const int aMsgType,
        const int aLength,
        const int aHostPort,
        const char* aHostAddress,
        const char* aData)
{
    JELOG2(EWMA);
    int numberOfSegments =0;
    TBool PortAddressing = EFalse;
    TInt receiveIntoPort = 0;
    if (mUri.find(L"sms://:") != std::wstring::npos)
    {
        receiveIntoPort = java::util::JavaCommonUtils::wstringToInt(
                              mUri.substr(KPortFieldStartIndex));
    }
    else
    {
        // It is a client connection, Nothing to do
    }
    TRAPD(error,
    {
        HBufC* smsData = convertToDes(aData,aMsgType,aLength);
        CleanupStack::PushL(smsData);
        std::auto_ptr<HBufC> smsAddress(stringToDes(aHostAddress));
        // The sms message takes ownership of the buffer
        CSmsBuffer* buffer = CSmsBuffer::NewL();
        CleanupStack::PushL(buffer);
        delete mSendMessage;
        mSendMessage = 0;
        RFs fileServer;
        mSendMessage = CSmsMessage::NewL(fileServer,CSmsPDU::ESmsSubmit,buffer);
        CleanupStack::Pop(buffer);
        if (smsAddress->Length()> 0)
        {
            // set the destination address
            mSendMessage->SetToFromAddressL((const TPtrC&)*smsAddress);
            // Set SMS port addresing
            if (aHostPort != 0)
            {
                PortAddressing = ETrue;
            }
            else
            {
                PortAddressing = EFalse;
            }
            (mSendMessage->SmsPDU()).SetApplicationPortAddressingL(
                PortAddressing,aHostPort,receiveIntoPort,KUse16BitPortAddressing);
        }
        else
        {
            // Nothing to do
        }

        // Get the encoding for the message that is to be sent
        TSmsDataCodingScheme::TSmsAlphabet smsEncoding = getEncodingSchemeL(
                    *smsData,aMsgType,fileServer);
        // sets the encoding

        (mSendMessage->SmsPDU()).SetAlphabet(smsEncoding);
        (mSendMessage->SmsPDU()).SetTextCompressed(EFalse);
        (mSendMessage->SmsPDU()).SetTextConcatenatedL(ETrue,ETrue);

        (mSendMessage->Buffer()).Reset();
        (mSendMessage->Buffer()).InsertL(0,*smsData);

        mSendMessage->OptimizeSettingsL(CSmsMessage::
                                        ESmsFlagOptimizeConcatenation16BitReference);
        // calculate the number of message PDUs required to send this message
        numberOfSegments = (int)mSendMessage->NumMessagePDUsL();
        LOG2(EWMA, EInfo,"SMS :number of segments %d data length %d",
             numberOfSegments, aLength);
        CleanupStack::PopAndDestroy(smsData);
    });