Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

How to restrict maximum IMAP command length?

more options

The IMAP server supports a maximum command line length of 8191 characters. When I select and move approximately 4000 messages between folders Thunderbird issues an IMAP onlinemove request that far exceeds that limit. One example from the tbird log is approximately 21K in length. I suspect selecting 100,000 messages would create a command 800K in length. The IMAP server drops the connection when an IMAP command exceeding the maximum limit is reached. This is likely a violation of the IMAP protocol and a bug report has been filed with the vendor. In the meantime, Thunderbird reports a network communication failure and then retries the failed operation the next time the Inbox is queried. The retry repeats the failure and this state persists indefinitely.

Three questions:

  1. Is there a configuration knob for Thunderbird as a whole or per server that can specify the maximum command length to send?
  2. If the IMAP server replied with a tagged BAD response instead of closing the connection, would Thunderbird respond any differently?
  3. How does Thunderbird measure the maximum supported command line length of an IMAP server?

The maximum supported command line length for Microsoft Exchange is 16K (the default is 10K). I could not find anything in the IMAP RFC describing how to negotiate the maximum command length between the client and server. In order for a move of more than ~800 message to succeed multiple onlinemove commands would need to be issued.

Thank you for your support.

The IMAP server supports a maximum command line length of 8191 characters. When I select and move approximately 4000 messages between folders Thunderbird issues an IMAP onlinemove request that far exceeds that limit. One example from the tbird log is approximately 21K in length. I suspect selecting 100,000 messages would create a command 800K in length. The IMAP server drops the connection when an IMAP command exceeding the maximum limit is reached. This is likely a violation of the IMAP protocol and a bug report has been filed with the vendor. In the meantime, Thunderbird reports a network communication failure and then retries the failed operation the next time the Inbox is queried. The retry repeats the failure and this state persists indefinitely. Three questions: # Is there a configuration knob for Thunderbird as a whole or per server that can specify the maximum command length to send? # If the IMAP server replied with a tagged BAD response instead of closing the connection, would Thunderbird respond any differently? # How does Thunderbird measure the maximum supported command line length of an IMAP server? The maximum supported command line length for Microsoft Exchange is 16K (the default is 10K). I could not find anything in the IMAP RFC describing how to negotiate the maximum command length between the client and server. In order for a move of more than ~800 message to succeed multiple onlinemove commands would need to be issued. Thank you for your support.

All Replies (5)

more options

I did my best to get an answer, as to be honest I had never heard of such things. The response was that Thunderbird does not use max length in any way.

Modified by Matt

more options

Matt said

I did my best to get an answer, as to be honest I had never heard of such things. The response was that Thunderbird does not use max length in any way.

Thank you for trying. Did you receive any responses to the second question? How would Thunderbird respond to a tagged "* BAD Command too long." response from the IMAP server? There are several possible behaviors I can imagine:

  1. Thunderbird recognizes the failure, notifies the end user, and reverts any local changes. For an attempt to move "too many messages" the user would then need to reattempt to move fewer messages via the GUI.
  2. Thunderbird recognizes the failure, and retries the operation by breaking up the request into smaller units.
  3. Thunderbird recognizes the failure, notifies the user but does not revert any local changes resulting in the mailboxes being out of sync with the server.
  4. Thunderbird recognizes the failure, and retries the "too long command" indefinitely as is the behavior when the IMAP server (or SNORT) terminates the TCP connection.

Thanks again for everyone's assistance.

more options

Per RFC 7162 Section 4 "Long Command Lines"

While [RFC3501] doesn't specify a specific line-length limit, several server implementations chose to implement the recommended line-length limit suggested in Section 3.2.1.5 of [RFC2683] in order to protect from Denial-of-Service attacks. When the line-length limit is exceeded, such servers return a BAD response (as required by [RFC3501] in case of a syntactic error) and may even close the connection. Clients that support CONDSTORE/QRESYNC extensions can trigger this limit by sending a long UID sequence (previously returned by the server) in an extended SELECT or FETCH command. This document updates recommended line-length limits specified in Section 3.2.1.5 of [RFC2683]. While the advice in the first paragraph of that section still applies (use compact message/UID set representations), the 1000-octet limit suggested in the second paragraph turns out to be quite problematic when the CONDSTORE and/or QRESYNC extension is used. The updated recommendation is as follows: a client should limit the length of the command lines it generates to approximately 8192 octets (including all quoted strings but not including literals). If the client is unable to group things into ranges so that the command line is within that length, it should split the request into multiple commands. The client should use literals instead of long quoted strings in order to keep the command length down.

Therefore, Thunderbird's transmission of unlimited length commands is a violation of the IMAP RFCs and does negatively impact the end user experience. This is especially true if the IMAP server or SNORT responds to the "too long command" by closing the TCP connection. Thunderbird's response to a failed connection is to retry the command indefinitely.

What is the appropriate method for submitting the bug report?

more options

I suspect https://bugzilla.mozilla.org/show_bug.cgi?id=263821 covers this, and I have already asked a developer to comment about it. No response yet.

more options

Wayne Mery said

I suspect https://bugzilla.mozilla.org/show_bug.cgi?id=263821 covers this, and I have already asked a developer to comment about it. No response yet.

Indeed. The root cause problem is the same but the operations are different. In my case I hit it in the OnlineMove and OnlineCopy IMAP commands. For example:

<preformat> [Parent 15976: IMAP]: D/IMAP URL failed with code 0x80470002 (imap://user%40example%2Ecom@imap.example.com:143/onlinemove%3EUID%3EINBOX%3E19413,19422,19424,19427:19428,19441,19443,19446,19448,19450:19453,19457,19485:19487,19490:19491,19496,19498:19499,19508,19511,19517:19519,19521:19522,19532,19535:19537,19546:19547,19550,19553,19562:19566,19568,19570,19572,19576,19578:19579,19585,19587,19595,19599:19600,19606:19608,19611:19612,19616,19618:19619,19623,19629,19631:19632,19635:19637,19640,19648,19653:19654,19660,19665:19666,19675:19676,19678:19679,19683,19685,19688:19689,19691,19694:19695,19697,19700,19707,19709,19713,19723:19724,19728:19729,19736,19738:19739,19741,19743:19744,19749:19751,19753:19757,19759:19760,19762:19766,19771,19783,19785,19791:19792,19795:19797,19799,19804:19806,19808:19809,19816:19817,19822:19827,19830,19832:19833,19839,19842,19845,19848,19850:19851,19853,19862,19867,19873:19874,19884,19901,19909,19912,19914:19915,19917:19918,19921,19925:19929,19936,19939,19943,19965:19967,19969:19970,19973:19976,19987:19990,19994,19996:19997,19999,20001:20005,20007:20008,20013:20014,20016:20017,20023,20025:20026,20032,20037,20040,20044,20047,20051,20058,20062,20079,20081,20087,20091:20092,20094,20096,20098:20100,20102:20109,20111,20115,20123:20124,20126:20128,20130:20133,20137,20141,20147:20148,20151:20154,20157,20161,20165:20166,20168:20171,20184,20191,20194,20198:20199,20202:20204,20214:20216,20223:20225,20227,20232,20234,20236,20238,20241:20246,20249:20250,20252,20255,20260,20266:20267,20271,20273,20289,20295:20298,20300,20305,20308:20311,20316,20322:20324,20328,20339,20352,20354:20355,20359,20362:20363,20365,20368:20369,20381:20384,20386,20389:20390,20392,20394,20396:20397,20399,20403,20410,20412,20421,20424,20427,20429,20432,20437,20440,20442,20447:20448,20450,20455:20456,20465:20466,20472,20474:20478,20480,20482:20484,20488,20492,20497,20502,20504,20506,20510:20512,20514,20516,20519:20521,20523:20527,20530:20532,20535,20538,20542,20544,20548,20550,20552,20557:20559,20563,20566,20568,20577:20578,20580,20582:20583,20590:20594,20608,20610:20611,20613,20634,20636,20638:20639,20643,20649,20652,20655,20659,20662,20673,20677:20680,20685,20693:20695,20700,20704:20705,20717,20719,20722:20724,20726,20731:20733,20736,20739:20740,20752:20753,20760,20762:20765,20768,20773:20776,20778,20783,20786:20788,20790:20791,20805,20807:20808,20811:20812,20816:20818,20820,20822,20826,20835:20837,20839,20846:20847,20851,20855:20856,20860,20868,20873,20877,20883,20891:20893,20900,20904:20905,20912:20913,20916,20920:20921,20926,20929:20930,20933,20936,20938:20949,20951:20955,20961,20965,20968,20978,20994:21001,21007,21014,21018,21021:21022,21029,21038:21039,21041,21043:21044,21048,21051,21056:21059,21062:21063,21068,21070:21071,21073:21075,21078:21079,21084,21086,21093:21094,21098,21100,21103:21105,21110,21113:21116,21119:21120,21126,21128:21129,21131,21133:21138,21140,21146,21151,21155,21157,21159,21164,21169:21171,21174:21177,21179:21180,21184,21186,21189:21190,21194:21195,21197,21202:21203,21205:21206,21209,21211:21213,21215:21216,21220:21223,21225:21226,21233,21235:21236,21238:21239,21241,21244,21246,21252,21254,21256:21257,21260:21261,21264,21267,21269,21273,21276,21279:21284,21286:21287,21290,21292,21296,21299,21303:21304,21306:21307,21311:21313,21316:21318,21325:21326,21328,21330:21331,21335,21338,21341,21343,21347,21350,21356:21357,21362,21364,21371,21373,21377:21378,21381:21385,21389:21391,21395:21397,21400,21402,21404,21422,21426,21428,21432,21435,21443,21445:21446,21449,21458,21460:21461,21465:21468,21471,21476,21478,21480:21481,21488,21493,21497,21505,21507,21515,21518,21520:21521,21524:21525,21527,21531:21532,21534,21539:21541,21543,21545:21549,21556,21559:21560,21562,21565:21570,21572,21574,21577,21579,21581,21587,21594,21602:21605,21609:21611,21617:21618,21620:21621,21624,21626,21628,21630:21633,21636,21646,21649:21653,21655,21658,21663,21665,21668,21672,21686,21688,21694:21695,21698,21700:21701,21703,21705:21707,21710,21714,21719:21720,21735:21736,21739,21745:21748,21756,21760:21763,21765:21767,21769:21771,21776:21779,21784,21786:21787,21792,21795,21801,21803:21804,21809,21816,21821,21824,21827,21844,21847,21850:21851,21853,21857,21860,21872:21875,21877,21884,21888:21889,21891:21892,21894,21897:21898,21900,21905,21909,21913,21916,21920,21928,21935:21938,21947,21956:21961,21965,21973,21980,21988,21993:22000,22002,22009:22014,22017,22023,22026:22027,22029,22031,22038:22039,22045,22049:22057,22060,22063,22065:22066,22075:22076,22080:22082,22085,22089:22090,22093,22096:22097,22099,22103,22114,22118,22123,22129,22141,22144,22148:22149,22153,22163,22174:22176,22179:22182,22187,22189,22192,22195:22201,22205,22212,22219,22223:22228,22233:22235,22241,22245:22246,22249:22250,22256:22259,22261,22268,22271,22276,22278:22279,22283:22284,22288:22289,22291:22292,22295,22298:22299,22301,22303:22304,22308:22309,22311:22321,22324,22327,22330:22331,22337,22341,22348:22357,22363:22364,22366:22368,22375,22385,22387:22390,22392:22393,22396,22401:22406,22411:22412,22416,22422,22427,22431,22436:22438,22441,22450:22452,22455:22458,22460:22461,22466,22471,22476,22484,22487:22488,22492:22495,22497,22502:22505,22507,22510,22518:22519,22522,22525,22529:22530,22533:22534,22537,22540:22542,22544,22546,22548,22550,22552:22556,22558,22572,22575,22578,22582,22584,22587:22588,22596:22597,22605:22608,22611,22614:22616,22619,22621,22623:22624,22628:22630,22632:22634,22636,22638:22639,22643:22646,22648:22649,22653:22654,22656,22659,22661,22664,22668,22673:22674,22681,22688:22689,22693,22695,22697,22700:22701,22711,22715,22717,22719,22721,22723:22726,22728,22730:22733,22735:22736,22744,22746:22747,22754:22756,22760:22761,22766,22771,22775,22782:22783,22792,22800:22801,22804,22811,22816:22819,22821:22824,22826:22828,22834,22840:22841,22847,22851,22854:22855,22858,22860,22862:22863,22866,22868,22872,22874,22876,22880,22882,22885,22887,22894:22895,22897:22899,22901:22914,22918:22919,22921:22922,22924:22927,22940:22942,22944,22946,22951:22952,22958:22959,22965:22966,22973:22974,22976,22979,22996,22998,23001,23004,23008:23009,23011,23017,23022,23034:23035,23041,23044,23047:23051,23058,23064,23072:23073,23077:23082,23085:23088,23090:23097,23099,23101,23103,23106,23112:23113,23117:23118,23122:23124,23127,23131,23133,23135,23141,23146:23147,23149:23151,23155:23156,23158,23166,23173,23177,23179:23181,23184:23186,23188:23190,23203,23208,23212:23213,23219,23223,23228,23231,23233,23242,23251,23255,23261,23264,23266,23272,23284:23285,23288,23291:23292,23296:23297,23299,23306,23312,23314,23317,23320:23321,23324:23325,23328:23329,23331,23334,23337:23338,23346:23347,23356:23357,23363,23366,23372,23379,23382:23383,23391,23396,23399,23404:23406,23408,23422,23425:23428,23432:23433,23435,23437,23443,23447:23448,23452:23454,23459,23461,23463,23465,23470:23473,23477:23480,23486,23489,23491:23493,23495:23496,23499,23501:23503,23505,23507:23508,23511:23512,23514:23516,23521:23524,23526,23528,23537,23552:23554,23561,23564,23566,23569,23572:23573,23576,23578:23580,23582:23584,23598,23602:23603,23605,23608:23610,23617:23618,23625,23636,23638,23646,23648:23649,23677,23682,23685:23687,23691:23692,23701,23704:23706,23711:23712,23714,23719:23722,23724,23727,23729,23731,23733,23737:23738,23740,23745:23746,23750:23751,23759,23761:23762,23769:23770,23780,23789,23794,23801,23805:23806,23808:23810,23815,23820:23822,23826,23828:23829,23834,23838:23839,23841:23844,23846:23848,23851,23855,23857:23858,23864,23866,23874:23875,23877,23884,23890:23892,23895,23899:23901,23906:23908,23912:23913,23915,23917,23919:23920,23923:23927,23931,23944,23946,23949,23952:23953,23957,23960,23963:23966,23972:23973,23977,23980:23981,23983:23984,23986:23987,23993,23996,23998,24005,24009:24010,24013,24017,24025,24027:24029,24032,24034:24035,24039,24041:24043,24047:24048,24052,24056,24064,24070:24071,24073,24078:24081,24083:24084,24086,24093,24100:24101,24105:24107,24110:24112,24116,24119,24121:24122,24125,24127:24128,24132,24137:24142,24148,24150,24153:24157,24159:24160,24162:24163,24165:24167,24170:24173,24179:24180,24182,24186:24189,24194:24195,24197:24199,24203:24204,24208,24210,24214:24218,24221,24224:24225,24227,24233,24247,24249,24251:24253,24261,24263,24266:24267,24271,24273,24275,24277,24283,24286:24287,24294,24299:24300,24309:24310,24317,24323,24325,24333,24335:24336,24339,24342,24349,24351:24354,24356:24357,24363:24364,24368,24375,24378,24380,24384:24385,24389,24391,24396,24405,24410,24415:24419,24437,24443:24445,24447:24448,24452,24454,24459,24464,24468:24469,24478,24485:24486,24488,24496,24498,24503:24504,24506:24507,24521,24528:24529,24533:24535,24537:24538,24542,24545,24552,24557,24559,24564,24566,24568,24577,24580:24581,24585,24590,24592,24595,24598,24600,24604,24606,24608,24612,24619:24622,24624,24626:24627,24631,24634,24636,24638:24642,24646,24649:24650,24654:24655,24662,24664,24671:24675,24679,24684,24686:24687,24696,24705:24706,24709,24722,24724,24731:24737,24741,24744,24747,24752,24758:24759,24761,24764:24765,24767,24777,24779:24780,24787,24791,24793,24797:24800,24807,24821,24831:24832,24838:24839,24843,24850,24852,24855:24856,24858,24863,24867,24873,24884,24896,24899:24901,24903,24916,24927:24928,24934,24938:24939,24944,24950,24952,24956,24958:24959,24962:24963,24966:24967,24970,24972,24977,24979:24980,24986,24991,24994:24997,25002,25004,25007,25009:25010,25012,25022,25027:25028,25031,25040,25049,25051,25055:25056,25075,25078:25079,25083,25087,25093:25096,25098,25102,25104,25107,25112,25115,25121,25135,25137:25139,25147:25149,25155,25159:25161 </preformat>