Remove Delivery function from store.
This commit is contained in:
@@ -207,161 +207,6 @@ StoreProcessDocument(StoreClient *client,
|
||||
return result;
|
||||
}
|
||||
|
||||
/* deliver message to a mailbox
|
||||
msgfile must be an open file whose file pointer set to the start of the file.
|
||||
|
||||
Implementation: this delivers mail straight into the store. Previously it wrote to
|
||||
an 'incoming' file, leading to long wait selecting a store when lots of mail is waiting.
|
||||
*/
|
||||
|
||||
// can return: DELIVER_QUOTA_EXCEEDED DELIVER_FAILURE DELIVER_TRY_LATER
|
||||
// [LOCKING] Write(X) => RwLock(X)
|
||||
// X above is the containing collection the new document will go into
|
||||
NMAPDeliveryCode
|
||||
DeliverMessageToMailbox(StoreClient *client,
|
||||
char *sender, char *authSender, char *recipient, char *mbox,
|
||||
FILE *msgfile, unsigned long scmsID, size_t msglen,
|
||||
unsigned long flags)
|
||||
{
|
||||
StoreObject collection;
|
||||
StoreObject newmail;
|
||||
FILE *tmp = NULL;
|
||||
const char *storeRoot;
|
||||
char tmppath[XPL_MAX_PATH+1];
|
||||
char path[XPL_MAX_PATH+1];
|
||||
char mailbox[XPL_MAX_PATH+1];
|
||||
unsigned char timeBuffer[80];
|
||||
char buffer[1024];
|
||||
LogicalLockType lock=LLOCK_NONE;
|
||||
|
||||
if (scmsID || msglen) {
|
||||
// FIXME : SCMS isn't implemented this way any more.
|
||||
// can we get rid of msglen also?
|
||||
}
|
||||
|
||||
if (SetupStore(recipient, &storeRoot, path, sizeof(path))) {
|
||||
return DELIVER_TRY_LATER;
|
||||
}
|
||||
|
||||
memset(&newmail, 0, sizeof(StoreObject));
|
||||
|
||||
if (mbox == NULL)
|
||||
mbox = "INBOX";
|
||||
|
||||
snprintf(mailbox, XPL_MAX_PATH, "/mail/%s", mbox);
|
||||
mailbox[XPL_MAX_PATH] = '\0';
|
||||
|
||||
if (StoreObjectFindByFilename(client, mailbox, &collection)) {
|
||||
// couldn't find the wanted folder;
|
||||
return DELIVER_FAILURE;
|
||||
}
|
||||
|
||||
MaildirTempDocument(client, collection.guid, tmppath, sizeof(tmppath));
|
||||
tmp = fopen(tmppath, "w");
|
||||
if (tmp == NULL)
|
||||
return DELIVER_TRY_LATER;
|
||||
|
||||
// write out the mail headers
|
||||
if (authSender && authSender[0] != '-') {
|
||||
fprintf(tmp, "X-Auth-OK: %s\r\n", authSender);
|
||||
} else {
|
||||
fprintf(tmp, "X-Auth-No: \r\n");
|
||||
}
|
||||
|
||||
MsgGetRFC822Date(-1, 0, timeBuffer);
|
||||
fprintf(tmp, "Received: from %d.%d.%d.%d [%d.%d.%d.%d] by %s\r\n\twith Store (%s); %s\r\n",
|
||||
client->conn->socketAddress.sin_addr.s_net,
|
||||
client->conn->socketAddress.sin_addr.s_host,
|
||||
client->conn->socketAddress.sin_addr.s_lh,
|
||||
client->conn->socketAddress.sin_addr.s_impno,
|
||||
|
||||
client->conn->socketAddress.sin_addr.s_net,
|
||||
client->conn->socketAddress.sin_addr.s_host,
|
||||
client->conn->socketAddress.sin_addr.s_lh,
|
||||
client->conn->socketAddress.sin_addr.s_impno,
|
||||
|
||||
StoreAgent.agent.officialName,
|
||||
AGENT_NAME,
|
||||
timeBuffer);
|
||||
fprintf(tmp, "Return-Path: <%s>\r\n", sender);
|
||||
|
||||
// now try to append the mail content itself.
|
||||
while (!feof(msgfile)) {
|
||||
unsigned int count;
|
||||
|
||||
count = fread(buffer, sizeof(char), sizeof(buffer), msgfile);
|
||||
if (count > 0) {
|
||||
if (count != fwrite(buffer, sizeof(char), count, tmp)) {
|
||||
goto ioerror;
|
||||
}
|
||||
} else if (ferror(msgfile)) {
|
||||
goto ioerror;
|
||||
}
|
||||
}
|
||||
|
||||
// all done
|
||||
newmail.size = (uint64_t) ftell(tmp);
|
||||
|
||||
if (fsync(fileno(tmp)) != 0) {
|
||||
goto ioerror;
|
||||
}
|
||||
|
||||
fclose(tmp);
|
||||
tmp = NULL;
|
||||
|
||||
// try to create store object.
|
||||
newmail.type = STORE_DOCTYPE_MAIL;
|
||||
|
||||
if (StoreObjectCreate(client, &newmail)) {
|
||||
printf("Couldn't create new mail object\n");
|
||||
goto ioerror;
|
||||
}
|
||||
newmail.collection_guid = collection.guid;
|
||||
newmail.flags = flags;
|
||||
newmail.time_created = newmail.time_modified = (uint64_t) time(NULL);
|
||||
|
||||
// need to acquire lock from this point
|
||||
if (! LogicalLockGain(client, &collection, LLOCK_READWRITE, "DeliverMessageToMailbox")) {
|
||||
StoreObjectRemove(client, &newmail);
|
||||
goto ioerror;
|
||||
}
|
||||
lock=LLOCK_READWRITE;
|
||||
|
||||
// possibly need more locking involved in this function
|
||||
StoreProcessDocument(client, &newmail, tmppath);
|
||||
|
||||
// now we have guid etc., move the mail into the right place
|
||||
if (MaildirDeliverTempDocument(client, collection.guid, tmppath, newmail.guid)) {
|
||||
printf("Can't put temporary mail into the store\n");
|
||||
StoreObjectRemove(client, &newmail);
|
||||
goto ioerror;
|
||||
}
|
||||
|
||||
// all done!
|
||||
StoreObjectFixUpFilename(&collection, &newmail);
|
||||
StoreObjectSave(client, &newmail);
|
||||
StoreObjectUpdateImapUID(client, &newmail); // FIXME: racy?
|
||||
|
||||
// release lock here?
|
||||
LogicalLockRelease(client, &collection, lock, "DeliverMessageToMailbox");
|
||||
lock=LLOCK_NONE;
|
||||
|
||||
// announce new mail has arrived
|
||||
++client->stats.insertions;
|
||||
StoreWatcherEvent(client, &newmail, STORE_WATCH_EVENT_NEW);
|
||||
|
||||
return DELIVER_SUCCESS;
|
||||
|
||||
ioerror:
|
||||
if (lock!=LLOCK_NONE)
|
||||
LogicalLockRelease(client, &collection, lock, "DeliverMessageToMailbox");
|
||||
if (tmp) {
|
||||
fclose(tmp);
|
||||
unlink(tmppath);
|
||||
}
|
||||
return DELIVER_TRY_LATER;
|
||||
}
|
||||
|
||||
/* login */
|
||||
CCode
|
||||
SelectUser(StoreClient *client, char *user, char *password, int nouser)
|
||||
|
||||
@@ -288,12 +288,6 @@ void UnsetStoreReadonly(StoreClient *client);
|
||||
|
||||
CCode WriteDocumentHeaders(StoreClient *client, FILE *fh, const char *folder, time_t tod);
|
||||
|
||||
NMAPDeliveryCode DeliverMessageToMailbox(StoreClient *client,
|
||||
char *sender, char *authSender,
|
||||
char *recipient, char *mbox,
|
||||
FILE *msgfile, unsigned long scmsID,
|
||||
size_t msglen, unsigned long flags);
|
||||
|
||||
int ImportIncomingMail(StoreClient *client);
|
||||
|
||||
const char *StoreProcessDocument(StoreClient *client,
|
||||
|
||||
Reference in New Issue
Block a user