aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/async/pop/MCPOPAsyncSession.h1
-rw-r--r--src/async/pop/MCPOPDeleteMessagesOperation.cc1
-rw-r--r--src/core/pop/MCPOPSession.cc1
-rw-r--r--src/core/rfc822/MCAttachment.cc86
-rw-r--r--src/core/rfc822/MCAttachment.h1
-rw-r--r--tests/main.mm2
6 files changed, 90 insertions, 2 deletions
diff --git a/src/async/pop/MCPOPAsyncSession.h b/src/async/pop/MCPOPAsyncSession.h
index fe713c4e..606a277d 100644
--- a/src/async/pop/MCPOPAsyncSession.h
+++ b/src/async/pop/MCPOPAsyncSession.h
@@ -59,6 +59,7 @@ namespace mailcore {
virtual POPFetchMessageOperation * fetchMessage(unsigned int index);
+ // Will disconnect.
virtual POPOperation * deleteMessages(Array * indexes);
// private
diff --git a/src/async/pop/MCPOPDeleteMessagesOperation.cc b/src/async/pop/MCPOPDeleteMessagesOperation.cc
index b655ab59..d96789f8 100644
--- a/src/async/pop/MCPOPDeleteMessagesOperation.cc
+++ b/src/async/pop/MCPOPDeleteMessagesOperation.cc
@@ -47,5 +47,6 @@ void POPDeleteMessagesOperation::main()
return;
}
}
+ session()->session()->disconnect();
}
diff --git a/src/core/pop/MCPOPSession.cc b/src/core/pop/MCPOPSession.cc
index 0ae28a9d..26a0c868 100644
--- a/src/core/pop/MCPOPSession.cc
+++ b/src/core/pop/MCPOPSession.cc
@@ -155,6 +155,7 @@ void POPSession::body_progress(size_t current, size_t maximum, void * context)
void POPSession::setup()
{
mPop = mailpop3_new(0, NULL);
+ mailpop3_set_progress_callback(mPop, POPSession::body_progress, this);
}
void POPSession::unsetup()
diff --git a/src/core/rfc822/MCAttachment.cc b/src/core/rfc822/MCAttachment.cc
index e41339a8..91b8fde3 100644
--- a/src/core/rfc822/MCAttachment.cc
+++ b/src/core/rfc822/MCAttachment.cc
@@ -4,18 +4,102 @@
#include "MCMessagePart.h"
#include "MCMessageHeader.h"
#include "MCMessageConstants.h"
+#include "MCLog.h"
#include <stdlib.h>
#include <string.h>
using namespace mailcore;
+static char * findBlank(const char * str)
+{
+ char * p = (char *) str;
+ while (!((* p == ' ') || (* p == '\t'))) {
+ if (* p == 0)
+ return NULL;
+ p ++;
+ }
+ return p;
+}
+
+HashMap * Attachment::readMimeTypesFile(String * filename)
+{
+ HashMap * result = HashMap::hashMap();
+
+ char line[512];
+ FILE * f = fopen(filename->fileSystemRepresentation(), "r");
+ if (f == NULL) {
+ return result;
+ }
+
+ while (fgets(line, sizeof(line), f)) {
+ char * p;
+ String * mimeType;
+
+ if (line[0] == '#') {
+ continue;
+ }
+
+ while ((p = strchr(line, '\r')) != NULL) {
+ * p = 0;
+ }
+ while ((p = strchr(line, '\n')) != NULL) {
+ * p = 0;
+ }
+
+ p = findBlank(line);
+ if (p == NULL) {
+ continue;
+ }
+
+ * p = 0;
+ p ++;
+ mimeType = String::stringWithUTF8Characters(line);
+
+ while (1) {
+ while ((* p == ' ') || (* p == '\t')) {
+ p ++;
+ }
+
+ char * ext_end = findBlank(p);
+ if (ext_end == NULL) {
+ String * ext = String::stringWithUTF8Characters(p);
+ result->setObjectForKey(ext, mimeType);
+ break;
+ }
+ else {
+ * ext_end = 0;
+ String * ext = String::stringWithUTF8Characters(p);
+ result->setObjectForKey(ext, mimeType);
+ p = ext_end + 1;
+ }
+ }
+ }
+
+ fclose(f);
+
+ return result;
+}
+
String * Attachment::mimeTypeForFilename(String * filename)
{
-#warning read from a file
+ static HashMap * mimeTypes = NULL;
+ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+ pthread_mutex_lock(&lock);
+ if (mimeTypes == NULL) {
+ mimeTypes = readMimeTypesFile(MCSTR("/etc/apache2/mime.types"));
+ mimeTypes->retain();
+ }
+ pthread_mutex_unlock(&lock);
+
String * ext;
+ String * result;
ext = filename->pathExtension()->lowercaseString();
+ result = (String *) mimeTypes->objectForKey(ext);
+ if (result != NULL)
+ return result;
+
if (ext->isEqual(MCSTR("jpg"))) {
return MCSTR("image/jpeg");
}
diff --git a/src/core/rfc822/MCAttachment.h b/src/core/rfc822/MCAttachment.h
index b96dfd2b..225c6b00 100644
--- a/src/core/rfc822/MCAttachment.h
+++ b/src/core/rfc822/MCAttachment.h
@@ -20,6 +20,7 @@ namespace mailcore {
static Attachment * attachmentWithSingleMIME(struct mailmime * mime);
static MessagePart * attachmentWithMessageMIME(struct mailmime * mime);
static Encoding encodingForMIMEEncoding(struct mailmime_mechanism * mechanism, int defaultMimeEncoding);
+ static HashMap * readMimeTypesFile(String * filename);
public:
static String * mimeTypeForFilename(String * filename);
diff --git a/tests/main.mm b/tests/main.mm
index 93bb81d5..c0b494e8 100644
--- a/tests/main.mm
+++ b/tests/main.mm
@@ -284,7 +284,7 @@ void testAll()
//testIMAP();
//testPOP();
//testAsyncSMTP(data);
- testAsyncIMAP();
+ //testAsyncIMAP();
//testAsyncPOP();
MCLog("pool release");