dovecot imap server · rackspace • rackspace email uses dovecot to serve imap for over a million...

35
Dovecot IMAP Server http://www.dovecot.org/ Date: September, 2009

Upload: dinhdan

Post on 14-Oct-2018

280 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Dovecot IMAP Server

http://www.dovecot.org/

Date: September, 2009

Page 2: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Rackspace

•  RackspaceEmailusesDovecottoserveIMAPforoveramillionpaidmailboxes– MSExchangealsoavailable

•  RackspacehassponsoredDovecotdevelopmentforyears– Andemployedmefull@meforyear2009

Page 3: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Overview

•  Dovecothistory&howAppleusesit•  Dovecotfeatures•  IMAP&Dovecotperformance

•  Troubleshoo@ng•  Futurefeatures

Page 4: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

WhatisDovecot?•  Dovecotis

–  IMAPserver

– POP3server– LocalmaildeliveryagentwithSievefiltering– Managesieveserver

– LMTPserver(v2.0+)

•  DovecotisNOT– SMTPserver

•  Soitneitherreceivesnorsendsmailsdirectly

Page 5: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Dovecot

Pictures from Wikipedia, by Cyril Thomas and Carcharoth

Page 6: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

History

•  DovecotdesignwasstartedaroundJune2002•  FirstreleasewasJuly2002•  Late2003aredesignstarted•  v1.0.0releasedApril13th2007•  v1.1.0releasedJune21st2008•  v1.2.0releasedJuly1st2009•  v2.0betashopefullythisyear

Page 7: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

WhyDidAppleSwitchtoDovecotfromCyrus?

• 

Page 8: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Apple’sDovecot•  Mytestversion:WWDCdeveloperspreview•  dovecot‐‐versionsays:1.1.14apple0.5•  Applepatches:

– OpenDirectoryauthen@ca@on– Mul@pleconnec@onspermailprocess

•  Configura@onin/etc/dovecot/dovecot.conf– Serveradminchangessomese_ngs

– Defaultsmoretowardsperformancethansecurity

Page 9: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange
Page 10: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Features

•  O`enhasbeaerperformancethancompe@@on.– Op@mizedforminimizingdiskI/O(index/cachefiles)– Hos@ngmyownmailson10yearsoldSparchelps

•  Highlyconfigurablefordifferentenvironments–  StandardmboxandMaildirwithtransparentindexing(externalmailboxmodifica@onsareok)

–  dbox:Dovecot’shigh‐performancemailboxformat– Manydifferentwaysofclustering

–  Extremelyflexibleauthen@ca@on•  PoseixandEximsupportDovecotforSMTPAUTH

Page 11: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Features•  Admin‐friendly/self‐healing

– Allerrorsarelogged– Understandableerrormessages

– Improvedconstantly(toreducemyemailload)

– Detected(index)corrup@ongetsfixedautoma@cally

•  file_dotlock_create(/home/@mo/Maildir/dovecot‐uidlist)failed:Permissiondenied(euid=1000(@mo)egid=1000(@mo)missing+xperm:

/home/@mo)

•  chown(/home/@mo/Maildir/.box,‐1,0(root))failed:Opera@onnotpermiaed(egid=1000(@mo),groupbasedon/home/@mo/Maildir)

Page 12: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Authen@ca@on

•  Passwordanduserdatabasesepara@on– Passdbforverifyinguser’spassword– Userdbforlookinguphowtoaccessmailbox

•  Supportforalmosteverything:SQL,LDAP,PAM,checkpasswordscripts,etc.– Everythingisconfigurable(e.g.fullSQLqueries)– Supportsmul@pledbs(e.g.system+virtualusers)

•  Authmechanisms:PLAIN,CRAM‐MD5,DIGEST‐MD5,Kerberos,OTP,etc.

•  Passwordschemes:Plaintext,CRYPT,MD5,SHA1,SHA256,SSHA,SSHA256,etc.

Page 13: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Authen@ca@onCache

•  Passdbanduserdblookupscanbecached•  Passwordchangesareautoma@callydetected:Ifauthisunsuccessful,andpreviousauthwasa)  successful:douncachedpassdblookupb)  usuccessful:faillogin

•  Nega@vecachingcanbedisabled–  Userdoesn’texistcaching–  Passwordfailures(v1.2+)

•  Avoidsaneedforimapproxywithwebmails?

Page 14: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Maildir

•  Apple:/var/spool/mail/dovecot/<user‐id>/•  Maildirbasics:

– Onefile=onemail

– Filenamegloballyunique– Messageflagsstoredinfilename

•  1250461029.M8247P5745.host,W=1279,S=1243:2,S–  W=Virtualmessagesize(CRLFlinefeeds)

–  S=Physicalmessagesize(exactlythesameasindisk)–forspeedingupquotarecalcula@on

–  :2,justmeans“version2”andflagsfollowthecomma.S=Seen

•  Messagesmustneverchange!

Page 15: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Maildir++DirectoryLayout

•  Maildir/‐INBOX– cur/,new/,tmp/

•  Maildir/.foo/–foldercalled”foo”– cur/,new/,tmp/

•  Maildir/.foo.bar/–foo’schildfolder”bar”– cur/,new/,tmp/

•  ’.’beginsallfolderdirectorynamesandseparateshierarchies

Page 16: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

MaildirDirectories

•  Savingmessages:– firstmailiswriaentotmp/

•  Onceinawhileoldfiles(fromcrashes,etc.)aredeleted

– mailismovedtonew/tofinishsaving

•  Dovecotlooksformailsinnew/andmovestocur/– Scanningnew/isfasterthanscanningcur/– Socur/willeventuallycontainallmessages

Page 17: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

DovecotFiles

•  dovecot‐uidlistmapsfilenamestoIMAPUIDs•  dovecot‐keywordsmapsa..zflagsinfilenamestoIMAPkeywords(aka.customflags,labels)

•  subscrip:onstracksIMAPsubscrip@ons

Nostateislostifdeleted:

•  dovecot‐uidvalidity*‐forgenera@nguniqueIMAPUIDVALIDITYvalues

•  dovecot.index*‐Indexfiles•  maildirsize–Tracksquotausage

Page 18: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

IMAPProtocol

•  Baseprotocoliscomplex–difficulttoimplementitcorrectly(bothclient&server)

•  Flexible–manydifferentwaystoimplementaclient(online&offlineclients)

•  Extensible–therearealotofextensions– Clientsrarelysupportmorethansomebasicextensions,suchasIDLE.

– Thunderbirdv3addssupportforseveralnewextensions,suchasCONDSTORE.

Page 19: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

ImapTestIMAPServerTester

•  WriaenoriginallyforDovecotstresstes@ng–  Foundalotofcrashes,hangsandmailboxcorrup@ononotherIMAPserversaswell

•  TestsIMAPservercompliancewithscriptedtestsanddynamicrandomstresstes@ng.

•  DovecotiscurrentlytheonlyIMAPserverthatfullypassesallofImapTesttests.•  PandaIMAPisprac@callytheretoo

•  Mostotherserversfailinmanydifferentways.•  hap://imapwiki.org/ImapTest

Page 20: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

OfflineIMAPClients

•  Typicallydownloadnewlyseenmessages’bodiesonceandcachethemlocally

•  O`encanbeconfiguredtodownloadimmediatelyvs.downloadwhenreading

•  Someuseserversidesearches(Thunderbird)andsomedon’t(Outlook–ifsomemessageshaven’tbeendownloaded,thosearen’tsearched)

•  Usuallyalsofetchmessages’metadataonce(headers,receiveddate)

•  Server‐sidecachingmayhelp,butnotthatmuch–  It’sextradiskI/O‐>morelikelyjusthurts

Page 21: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

OnlineIMAPClients

•  Webmailso`enkeepaskingforthesameinforma@onoverandoverandoveragain

•  Pineandsomewebmailscachewhatthey’vealreadyseen,butnotpermanently

•  Mua(withoutlocalcache)andsomeothersfetchallmessages’metadataevery@mewhenopeningamailbox

•  Cachingisveryuseful,butdifferentclientswantdifferentmetadata

Page 22: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

IMAPServerPerformance•  Difficulttobenchmark•  Dependsalotonclients:Whetherclientsusealocalcachemakesahugedifference.– Onlinevs.offlineclients

•  Whatdatatoindex/cache?•  SPECmail2009addssupportforIMAP

– EmulatesdifferentIMAPclients.Clientamountsareconfigurable.

– Theonlybenchmarkgivingrealis@cresults.– Publishedresultsallrunondifferenthardware‐>resultsunusableforcomparingso`ware

Page 23: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

DovecotCacheFile

•  dovecot.index.cachefiles•  ThemainreasonforDovecot’sgoodperformance•  Dynamic:cachesonlywhatclientswant.

–  Specificmessageheaders(From:,Subject:,etc),– MIMEstructureinforma@on,–  Sent/receiveddate,etc.

•  Cachingdecisionsforeachfield:“no”,“temporary”,“permanent”

•  Unusedfieldsdroppeda`eramonth.•  Cacheddataneverchanges(IMAPguarantees)•  Cachefilegets“compressed”onceinawhile•  O`enabout10‐20%ofmailboxsize

Page 24: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

DovecotIndexFiles

•  dovecot.indexcontainsmessages’metadata–  IMAPUniqueIDnumber(UID)iden@fiesmessages

– Flags(\Seen,\Answered,keywords,etc.)– Extensiondata:mboxfileoffsets,cachefileoffsets,modseqnumber(v1.2CONDSTORE),etc.

•  Lazilycreated/updatedsincev1.1– dovecot.index.loghasallthelatestchanges.dovecot.indexisupdateda`er8kBofnewdatahasbeenwriaentothe.log

Page 25: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

DovecotIndexFiles

•  dovecot.index.logisamailboxtransac@onlog– Somewhatsimilartodatabases’transac@onlogsorfilesystemjournals.

– Containsallchangestobedonetodovecot.index.•  dovecot.indexisreadtomemoryonceandthenupdatedfromdovecot.index.log– VeryefficientwithNFS/clusteredfilesystems!– Veryefficienttofindoutwhatchangesanothersessionhaddone!

Page 26: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Plugins

•  DovecotpluginscanhookintoalmostanythingandmodifyDovecot’sbehavior.Someexis@ngfeaturesimplementedasplugins:– AccessControlLists– Quota–  Fulltextsearchindexes–  Readingcompressedmbox/maildirfiles

•  CanaddnewIMAPcommands•  Implementnewmailstoragebackends(virtual,SQL,IMAPproxying)

Page 27: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

DovecotClustering

•  Twodifferentwaystodoit:•  Globallysharedfilesystem

– ManyIMAPservers,eachabletohandleanyuser

– NFS,clusterfilesystems

•  Sharding– Eachuser’sdataindifferentservers

•  maybemirroredto2‐3servers

–  IMAPproxyforwardsuserstocorrectserver(s)

Page 28: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

AppleClustering

•  I’veonlygoogledthisinforma@on..•  Xsan,clusterfilesystem

•  Mul@plemailserversconnectedtoXsan– Ac@ve‐ac@vesetup– Loadbalancingwithhardware,DNS,..?– Performanceprobablybestifuserusuallyredirectedtothesameserver•  Orifnotuser,atleastthesameIP

Page 29: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Troubleshoo@ng

•  Logs!Dovecotlogsallerrors!•  top•  rawlog•  dtruss

Page 30: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

DovecotProcesses

•  Something’sslow?Isolateittoaspecificprocessfirst,thenusee.g.dtruss:

•  dovecot–masterprocess,createsallotherprocesses,alllogginggoesthroughit

•  dovecot‐auth–ODlookups•  imap‐login,pop3‐login–acceptsnewconnec@ons,handlescommandsun@lsuccessfullogin,SSLproxyingevena`erlogin

•  imap,pop3–post‐loginhandling

Page 31: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

ClientTroubleshoo@ng

•  LookattheIMAP/POP3protocoltrafficbetweenDovecotandclient– Dovecot’srawlogtool

•  worksalsowithSSLconnec@ons– SomeothernetworksniffersuchasWireshark

•  imap/pop3_client_workaroundsse_ngsnotenabledinApple’sdefaultconfig(?)

Page 32: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

v1.2NewFeatures

•  Virtualmailboxes(searchviews)– ”Allunreademailsinallmailboxes”

– Allmessagesinallmailboxes(exceptTrash)•  VirtualPOP3INBOX•  Forsearchingmessagesfromallmailboxes•  gmail‐likeconversa@onviews

•  Userscansharemailboxestoeachothers–  IMAPACLcommands

•  NewIMAPextensions,performanceimprovements

Page 33: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Dovecotv2.0

•  Somenewfeaturesalreadyimplemented:– Redesignedmasterprocess

•  Easytoaddexternalservices,e.g.ManageSieve– Redesignedconfigura@on

•  Local/remoteIP/mask‐specificconfigura@on–  SSLcerts

•  Allowchangingconfigdatasource(e.g.SQL?)– LMTPserverandproxy– dsync:Realiablyandefficientlysynctwomailboxes(e.g.viaSSH)

– dbox–highperformancemailboxformat

Page 34: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Dovecotv2.x

•  Featuresnotyetimplemented,buthopefullywillbebytheendofthisyear:–  Indexfileimprovements

•  Nolocking(withatomicappends)

•  Smallchecksumsallaroundfordetec@ngcorrup@on•  Ingeneralmakethecodesimplerandmorerobust

– Mul@‐masterreplica@on•  dboxcloudstorage(forsomeexis@ngcloudAPI(s)?)

•  Indexsharing/replica@onbetweenservers

Page 35: Dovecot IMAP Server · Rackspace • Rackspace Email uses Dovecot to serve IMAP for over a million paid mailboxes – MS Exchange

Ques@ons?