2009-06-16 19:03:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008-2009 Marc Blank
|
|
|
|
* Licensed to The Android Open Source Project.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2009-07-31 01:17:52 +00:00
|
|
|
package com.android.exchange;
|
2009-06-16 19:03:45 +00:00
|
|
|
|
2009-07-23 22:31:28 +00:00
|
|
|
import com.android.email.provider.EmailContent.HostAuth;
|
|
|
|
import com.android.email.provider.EmailContent.Mailbox;
|
|
|
|
import com.android.email.provider.EmailContent.Message;
|
|
|
|
import com.android.email.provider.EmailContent.MessageColumns;
|
2009-07-05 19:54:49 +00:00
|
|
|
import com.android.exchange.utility.Rfc822Formatter;
|
2009-06-16 19:03:45 +00:00
|
|
|
|
|
|
|
import android.content.ContentUris;
|
|
|
|
import android.content.ContentValues;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
2009-07-23 22:31:28 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
2009-07-05 19:54:49 +00:00
|
|
|
public class EasOutboxService extends EasSyncService {
|
2009-06-16 19:03:45 +00:00
|
|
|
|
2009-06-24 00:50:42 +00:00
|
|
|
public EasOutboxService(Context _context, Mailbox _mailbox) {
|
2009-06-16 19:03:45 +00:00
|
|
|
super(_context, _mailbox);
|
|
|
|
mContext = _context;
|
2009-06-24 00:50:42 +00:00
|
|
|
HostAuth ha = HostAuth.restoreHostAuthWithId(mContext, mAccount.mHostAuthKeyRecv);
|
2009-06-16 19:03:45 +00:00
|
|
|
mHostAddress = ha.mAddress;
|
|
|
|
mUserName = ha.mLogin;
|
|
|
|
mPassword = ha.mPassword;
|
|
|
|
}
|
|
|
|
|
2009-07-05 19:54:49 +00:00
|
|
|
public void run() {
|
2009-06-16 19:03:45 +00:00
|
|
|
mThread = Thread.currentThread();
|
2009-07-17 23:29:35 +00:00
|
|
|
String uniqueId = android.provider.Settings.Secure.getString(mContext.getContentResolver(),
|
|
|
|
android.provider.Settings.Secure.ANDROID_ID);
|
2009-06-16 19:03:45 +00:00
|
|
|
try {
|
2009-06-24 00:50:42 +00:00
|
|
|
Cursor c = mContext.getContentResolver().query(Message.CONTENT_URI,
|
2009-07-17 23:29:35 +00:00
|
|
|
Message.CONTENT_PROJECTION, MessageColumns.MAILBOX_KEY + '=' + mMailbox.mId,
|
2009-07-05 19:54:49 +00:00
|
|
|
null, null);
|
2009-06-16 19:03:45 +00:00
|
|
|
try {
|
2009-07-05 19:54:49 +00:00
|
|
|
while (c.moveToNext()) {
|
2009-06-24 00:50:42 +00:00
|
|
|
Message msg = new Message().restore(c);
|
2009-06-16 19:03:45 +00:00
|
|
|
if (msg != null) {
|
|
|
|
String data = Rfc822Formatter
|
2009-07-05 19:54:49 +00:00
|
|
|
.writeEmailAsRfc822String(mContext, mAccount, msg, uniqueId);
|
2009-06-16 19:03:45 +00:00
|
|
|
HttpURLConnection uc = sendEASPostCommand("SendMail&SaveInSent=T", data);
|
|
|
|
int code = uc.getResponseCode();
|
|
|
|
if (code == HttpURLConnection.HTTP_OK) {
|
2009-07-05 19:54:49 +00:00
|
|
|
userLog("Deleting message...");
|
2009-06-16 19:03:45 +00:00
|
|
|
mContext.getContentResolver().delete(ContentUris.withAppendedId(
|
2009-06-24 00:50:42 +00:00
|
|
|
Message.CONTENT_URI, msg.mId), null, null);
|
2009-06-16 19:03:45 +00:00
|
|
|
} else {
|
|
|
|
ContentValues cv = new ContentValues();
|
|
|
|
cv.put("uid", 1);
|
2009-07-17 23:29:35 +00:00
|
|
|
Message.update(mContext, Message.CONTENT_URI, msg.mId, cv);
|
2009-06-16 19:03:45 +00:00
|
|
|
}
|
2009-07-05 19:54:49 +00:00
|
|
|
// TODO How will the user know that the message sent or not?
|
2009-06-16 19:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
c.close();
|
|
|
|
}
|
2009-07-05 19:54:49 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
userLog("Caught IOException");
|
|
|
|
mExitStatus = EXIT_IO_ERROR;
|
|
|
|
} catch (Exception e) {
|
|
|
|
mExitStatus = EXIT_EXCEPTION;
|
|
|
|
} finally {
|
|
|
|
userLog(mMailbox.mDisplayName + ": sync finished");
|
|
|
|
SyncManager.done(this);
|
2009-06-16 19:03:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|