void mail::maildir::genericMessageRead(string uid, size_t messageNumber, bool peek, mail::readMode readType, mail::callback::message &callback) { if (!fixMessageNumber(this, uid, messageNumber)) { callback.success("OK"); return; } MONITOR(mail::maildir); string messageFn=getfilename(messageNumber); if (messageFn.size() == 0) { callback.success("OK"); return; } int fd=maildir_safeopen(messageFn.c_str(), O_RDONLY, 0); if (fd < 0) { callback.success("OK"); return; } try { mail::file f(fd, "r"); f.genericMessageRead(this, messageNumber, readType, callback); if (ferror(f)) { callback.fail(strerror(errno)); close(fd); return; } } catch (...) { close(fd); LIBMAIL_THROW(LIBMAIL_THROW_EMPTY); } close(fd); if (!peek && index[messageNumber].unread) { index[messageNumber].unread=false; saveFolderIndexInfo(messageNumber, index[messageNumber], callback); return; } callback.success("OK"); }
void mail::maildir::genericMessageSize(string uid, size_t messageNumber, mail::callback::message &callback) { if (!fixMessageNumber(this, uid, messageNumber)) { callback.messageSizeCallback(messageNumber, 0); callback.success("OK"); return; } string messageFn=getfilename(messageNumber); if (messageFn.size() == 0) { callback.messageSizeCallback(messageNumber,0); callback.success("OK"); return; } unsigned long ul; if (maildir_parsequota(messageFn.c_str(), &ul) == 0) { callback.messageSizeCallback(messageNumber, ul); callback.success("OK"); return; } struct stat stat_buf; int rc=stat(messageFn.c_str(), &stat_buf); callback.messageSizeCallback(messageNumber, rc == 0 ? stat_buf.st_size:0); callback.success("OK"); }
void mail::mbox::genericMessageSize(string uid, size_t messageNumber, mail::callback::message &callback) { if (!verifyUid(uid, messageNumber, callback)) return; size_t n=uidmap.find(uid)->second; off_t s=folderMessageIndex[n].startingPos; off_t e=n + 1 >= folderMessageIndex.size() ? folderSavedSize:folderMessageIndex[n+1].startingPos; callback.messageSizeCallback( messageNumber, e > s ? e-s:0); callback.success("OK"); }
void mail::mbox::readMessageAttributes(const vector<size_t> &messages, MessageAttributes attributes, mail::callback::message &callback) { vector<size_t> messageCpy=messages; // ARRIVALDATE can be handled here, for everything else use the // generic methods. if (attributes & mail::account::ARRIVALDATE) { attributes &= ~mail::account::ARRIVALDATE; vector<size_t>::iterator b=messageCpy.begin(), e=messageCpy.end(); MONITOR(mail::mbox); while (b != e && !DESTROYED()) { size_t n= *b++; if (n >= index.size()) continue; string uid=index[n].uid; callback .messageArrivalDateCallback(n, uidmap.count(uid) == 0 ? 0: folderMessageIndex [ uidmap.find(uid) ->second] .internalDate); } if (DESTROYED() || attributes == 0) { callback.success("OK"); return; } } MultiLockRelease *mlock=new MultiLockRelease(*this, callback); if (!mlock) { callback.fail(strerror(errno)); return; } try { MultiLockGenericAttributes *mr= new MultiLockGenericAttributes(*this, messageCpy, attributes, *mlock); if (!mr) LIBMAIL_THROW((strerror(errno))); try { installTask(new MultiLock( *this, *mr )); } catch (...) { delete mr; } } catch (...) { delete mlock; LIBMAIL_THROW(LIBMAIL_THROW_EMPTY); } }