gnus-art.el 308 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760
  1. ;;; gnus-art.el --- article mode commands for Gnus
  2. ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
  3. ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
  4. ;; Keywords: news
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. ;; For Emacs <22.2 and XEmacs.
  19. (eval-and-compile
  20. (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
  21. (eval-when-compile
  22. (require 'cl))
  23. (defvar tool-bar-map)
  24. (defvar w3m-minor-mode-map)
  25. (require 'gnus)
  26. (require 'gnus-sum)
  27. (require 'gnus-spec)
  28. (require 'gnus-int)
  29. (require 'gnus-win)
  30. (require 'mm-bodies)
  31. (require 'mail-parse)
  32. (require 'mm-decode)
  33. (require 'mm-view)
  34. (require 'wid-edit)
  35. (require 'mm-uu)
  36. (require 'message)
  37. (require 'mouse)
  38. (autoload 'gnus-msg-mail "gnus-msg" nil t)
  39. (autoload 'gnus-button-mailto "gnus-msg")
  40. (autoload 'gnus-button-reply "gnus-msg" nil t)
  41. (autoload 'parse-time-string "parse-time" nil nil)
  42. (autoload 'ansi-color-apply-on-region "ansi-color")
  43. (autoload 'mm-url-insert-file-contents-external "mm-url")
  44. (autoload 'mm-extern-cache-contents "mm-extern")
  45. (defgroup gnus-article nil
  46. "Article display."
  47. :link '(custom-manual "(gnus)Article Buffer")
  48. :group 'gnus)
  49. (defgroup gnus-article-treat nil
  50. "Treating article parts."
  51. :link '(custom-manual "(gnus)Article Hiding")
  52. :group 'gnus-article)
  53. (defgroup gnus-article-hiding nil
  54. "Hiding article parts."
  55. :link '(custom-manual "(gnus)Article Hiding")
  56. :group 'gnus-article)
  57. (defgroup gnus-article-highlight nil
  58. "Article highlighting."
  59. :link '(custom-manual "(gnus)Article Highlighting")
  60. :group 'gnus-article
  61. :group 'gnus-visual)
  62. (defgroup gnus-article-signature nil
  63. "Article signatures."
  64. :link '(custom-manual "(gnus)Article Signature")
  65. :group 'gnus-article)
  66. (defgroup gnus-article-headers nil
  67. "Article headers."
  68. :link '(custom-manual "(gnus)Hiding Headers")
  69. :group 'gnus-article)
  70. (defgroup gnus-article-washing nil
  71. "Special commands on articles."
  72. :link '(custom-manual "(gnus)Article Washing")
  73. :group 'gnus-article)
  74. (defgroup gnus-article-emphasis nil
  75. "Fontisizing articles."
  76. :link '(custom-manual "(gnus)Article Fontisizing")
  77. :group 'gnus-article)
  78. (defgroup gnus-article-saving nil
  79. "Saving articles."
  80. :link '(custom-manual "(gnus)Saving Articles")
  81. :group 'gnus-article)
  82. (defgroup gnus-article-mime nil
  83. "Worshiping the MIME wonder."
  84. :link '(custom-manual "(gnus)Using MIME")
  85. :group 'gnus-article)
  86. (defgroup gnus-article-buttons nil
  87. "Pushable buttons in the article buffer."
  88. :link '(custom-manual "(gnus)Article Buttons")
  89. :group 'gnus-article)
  90. (defgroup gnus-article-various nil
  91. "Other article options."
  92. :link '(custom-manual "(gnus)Misc Article")
  93. :group 'gnus-article)
  94. (defcustom gnus-ignored-headers
  95. (mapcar
  96. (lambda (header)
  97. (concat "^" header ":"))
  98. '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
  99. "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
  100. "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
  101. "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
  102. "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
  103. "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
  104. "X-Attribution" "X-Originating-IP" "Delivered-To"
  105. "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
  106. "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
  107. "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
  108. "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
  109. "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
  110. "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
  111. "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
  112. "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
  113. "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
  114. "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
  115. "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
  116. "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
  117. "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
  118. "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
  119. "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
  120. "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
  121. "List-[A-Za-z]+" "X-Listprocessor-Version"
  122. "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
  123. "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
  124. "X-Received" "Content-length" "X-precedence"
  125. "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
  126. "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
  127. "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
  128. "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
  129. "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
  130. "X-Content-length" "X-Posting-Agent" "Original-Received"
  131. "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
  132. "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
  133. "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
  134. "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
  135. "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
  136. "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
  137. "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
  138. "Envelope-Sender" "Envelope-Recipients"))
  139. "*All headers that start with this regexp will be hidden.
  140. This variable can also be a list of regexps of headers to be ignored.
  141. If `gnus-visible-headers' is non-nil, this variable will be ignored."
  142. :type '(choice regexp
  143. (repeat regexp))
  144. :group 'gnus-article-hiding)
  145. (defcustom gnus-visible-headers
  146. "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
  147. "*All headers that do not match this regexp will be hidden.
  148. This variable can also be a list of regexp of headers to remain visible.
  149. If this variable is non-nil, `gnus-ignored-headers' will be ignored."
  150. :type '(choice
  151. (repeat :value-to-internal (lambda (widget value)
  152. (custom-split-regexp-maybe value))
  153. :match (lambda (widget value)
  154. (or (stringp value)
  155. (widget-editable-list-match widget value)))
  156. regexp)
  157. (const :tag "Use gnus-ignored-headers" nil)
  158. regexp)
  159. :group 'gnus-article-hiding)
  160. (defcustom gnus-sorted-header-list
  161. '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
  162. "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
  163. "*This variable is a list of regular expressions.
  164. If it is non-nil, headers that match the regular expressions will
  165. be placed first in the article buffer in the sequence specified by
  166. this list."
  167. :type '(repeat regexp)
  168. :group 'gnus-article-hiding)
  169. (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
  170. "Headers that are only to be displayed if they have interesting data.
  171. Possible values in this list are:
  172. 'empty Headers with no content.
  173. 'newsgroups Newsgroup identical to Gnus group.
  174. 'to-address To identical to To-address.
  175. 'to-list To identical to To-list.
  176. 'cc-list CC identical to To-list.
  177. 'followup-to Followup-to identical to Newsgroups.
  178. 'reply-to Reply-to identical to From.
  179. 'date Date less than four days old.
  180. 'long-to To and/or Cc longer than 1024 characters.
  181. 'many-to Multiple To and/or Cc."
  182. :type '(set (const :tag "Headers with no content." empty)
  183. (const :tag "Newsgroups identical to Gnus group." newsgroups)
  184. (const :tag "To identical to To-address." to-address)
  185. (const :tag "To identical to To-list." to-list)
  186. (const :tag "CC identical to To-list." cc-list)
  187. (const :tag "Followup-to identical to Newsgroups." followup-to)
  188. (const :tag "Reply-to identical to From." reply-to)
  189. (const :tag "Date less than four days old." date)
  190. (const :tag "To and/or Cc longer than 1024 characters." long-to)
  191. (const :tag "Multiple To and/or Cc headers." many-to))
  192. :group 'gnus-article-hiding)
  193. (defcustom gnus-article-skip-boring nil
  194. "Skip over text that is not worth reading.
  195. By default, if you set this t, then Gnus will display citations and
  196. signatures, but will never scroll down to show you a page consisting
  197. only of boring text. Boring text is controlled by
  198. `gnus-article-boring-faces'."
  199. :version "22.1"
  200. :type 'boolean
  201. :group 'gnus-article-hiding)
  202. (defcustom gnus-signature-separator '("^-- $" "^-- *$")
  203. "Regexp matching signature separator.
  204. This can also be a list of regexps. In that case, it will be checked
  205. from head to tail looking for a separator. Searches will be done from
  206. the end of the buffer."
  207. :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
  208. (regexp)
  209. (repeat :tag "List of regexp" regexp))
  210. :group 'gnus-article-signature)
  211. (defcustom gnus-signature-limit nil
  212. "Provide a limit to what is considered a signature.
  213. If it is a number, no signature may not be longer (in characters) than
  214. that number. If it is a floating point number, no signature may be
  215. longer (in lines) than that number. If it is a function, the function
  216. will be called without any parameters, and if it returns nil, there is
  217. no signature in the buffer. If it is a string, it will be used as a
  218. regexp. If it matches, the text in question is not a signature.
  219. This can also be a list of the above values."
  220. :type '(choice (const nil)
  221. (integer :value 200)
  222. (number :value 4.0)
  223. function
  224. (regexp :value ".*"))
  225. :group 'gnus-article-signature)
  226. (defcustom gnus-hidden-properties '(invisible t intangible t)
  227. "Property list to use for hiding text."
  228. :type 'sexp
  229. :group 'gnus-article-hiding)
  230. ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
  231. ;; frames in a session.
  232. (defcustom gnus-article-x-face-command
  233. (if (featurep 'xemacs)
  234. (if (or (gnus-image-type-available-p 'xface)
  235. (gnus-image-type-available-p 'pbm))
  236. 'gnus-display-x-face-in-from
  237. "{ echo \
  238. '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
  239. ; uncompface; } | icontopbm | ee -")
  240. (if (gnus-image-type-available-p 'pbm)
  241. 'gnus-display-x-face-in-from
  242. "{ echo \
  243. '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
  244. ; uncompface; } | icontopbm | display -"))
  245. "*String or function to be executed to display an X-Face header.
  246. If it is a string, the command will be executed in a sub-shell
  247. asynchronously. The compressed face will be piped to this command."
  248. :type `(choice string
  249. (function-item gnus-display-x-face-in-from)
  250. function)
  251. :version "21.1"
  252. :group 'gnus-picon
  253. :group 'gnus-article-washing)
  254. (defcustom gnus-article-x-face-too-ugly nil
  255. "Regexp matching posters whose face shouldn't be shown automatically."
  256. :type '(choice regexp (const nil))
  257. :group 'gnus-article-washing)
  258. (defcustom gnus-article-banner-alist nil
  259. "Banner alist for stripping.
  260. For example,
  261. ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
  262. :version "21.1"
  263. :type '(repeat (cons symbol regexp))
  264. :group 'gnus-article-washing)
  265. (gnus-define-group-parameter
  266. banner
  267. :variable-document
  268. "Alist of regexps (to match group names) and banner."
  269. :variable-group gnus-article-washing
  270. :parameter-type
  271. '(choice :tag "Banner"
  272. :value nil
  273. (const :tag "Remove signature" signature)
  274. (symbol :tag "Item in `gnus-article-banner-alist'" none)
  275. regexp
  276. (const :tag "None" nil))
  277. :parameter-document
  278. "If non-nil, specify how to remove `banners' from articles.
  279. Symbol `signature' means to remove signatures delimited by
  280. `gnus-signature-separator'. Any other symbol is used to look up a
  281. regular expression to match the banner in `gnus-article-banner-alist'.
  282. A string is used as a regular expression to match the banner
  283. directly.")
  284. (defcustom gnus-article-address-banner-alist nil
  285. "Alist of mail addresses and banners.
  286. Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
  287. to match a mail address in the From: header, BANNER is one of a symbol
  288. `signature', an item in `gnus-article-banner-alist', a regexp and nil.
  289. If ADDRESS matches author's mail address, it will remove things like
  290. advertisements. For example:
  291. \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
  292. "
  293. :type '(repeat
  294. (cons
  295. (regexp :tag "Address")
  296. (choice :tag "Banner" :value nil
  297. (const :tag "Remove signature" signature)
  298. (symbol :tag "Item in `gnus-article-banner-alist'" none)
  299. regexp
  300. (const :tag "None" nil))))
  301. :version "22.1"
  302. :group 'gnus-article-washing)
  303. (defmacro gnus-emphasis-custom-with-format (&rest body)
  304. `(let ((format "\
  305. \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
  306. \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
  307. ,@body))
  308. (defun gnus-emphasis-custom-value-to-external (value)
  309. (gnus-emphasis-custom-with-format
  310. (if (consp (car value))
  311. (list (format format (car (car value)) (cdr (car value)))
  312. 2
  313. (if (nth 1 value) 2 3)
  314. (nth 2 value))
  315. value)))
  316. (defun gnus-emphasis-custom-value-to-internal (value)
  317. (gnus-emphasis-custom-with-format
  318. (let ((regexp (concat "\\`"
  319. (format (regexp-quote format)
  320. "\\([^()]+\\)" "\\([^()]+\\)")
  321. "\\'"))
  322. pattern)
  323. (if (string-match regexp (setq pattern (car value)))
  324. (list (cons (match-string 1 pattern) (match-string 2 pattern))
  325. (= (nth 2 value) 2)
  326. (nth 3 value))
  327. value))))
  328. (defcustom gnus-emphasis-alist
  329. (let ((types
  330. '(("\\*" "\\*" bold nil 2)
  331. ("_" "_" underline)
  332. ("/" "/" italic)
  333. ("_/" "/_" underline-italic)
  334. ("_\\*" "\\*_" underline-bold)
  335. ("\\*/" "/\\*" bold-italic)
  336. ("_\\*/" "/\\*_" underline-bold-italic))))
  337. (nconc
  338. (gnus-emphasis-custom-with-format
  339. (mapcar (lambda (spec)
  340. (list (format format (car spec) (cadr spec))
  341. (or (nth 3 spec) 2)
  342. (or (nth 4 spec) 3)
  343. (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
  344. types))
  345. '(;; I've never seen anyone use this strikethru convention whereas I've
  346. ;; several times seen it triggered by normal text. --Stef
  347. ;; Miles suggests that this form is sometimes used but for italics,
  348. ;; so maybe we should map it to `italic'.
  349. ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
  350. ;; 2 3 gnus-emphasis-strikethru)
  351. ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
  352. 2 3 gnus-emphasis-underline))))
  353. "*Alist that says how to fontify certain phrases.
  354. Each item looks like this:
  355. (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
  356. The first element is a regular expression to be matched. The second
  357. is a number that says what regular expression grouping used to find
  358. the entire emphasized word. The third is a number that says what
  359. regexp grouping should be displayed and highlighted. The fourth
  360. is the face used for highlighting."
  361. :type
  362. '(repeat
  363. (menu-choice
  364. :format "%[Customizing Style%]\n%v"
  365. :indent 2
  366. (group :tag "Default"
  367. :value ("" 0 0 default)
  368. :value-create
  369. (lambda (widget)
  370. (let ((value (widget-get
  371. (cadr (widget-get (widget-get widget :parent)
  372. :args))
  373. :value)))
  374. (if (not (eq (nth 2 value) 'default))
  375. (widget-put
  376. widget
  377. :value
  378. (gnus-emphasis-custom-value-to-external value))))
  379. (widget-group-value-create widget))
  380. regexp
  381. (integer :format "Match group: %v")
  382. (integer :format "Emphasize group: %v")
  383. face)
  384. (group :tag "Simple"
  385. :value (("_" . "_") nil default)
  386. (cons :format "%v"
  387. (regexp :format "Start regexp: %v")
  388. (regexp :format "End regexp: %v"))
  389. (boolean :format "Show start and end patterns: %[%v%]\n"
  390. :on " On " :off " Off ")
  391. face)))
  392. :get (lambda (symbol)
  393. (mapcar 'gnus-emphasis-custom-value-to-internal
  394. (default-value symbol)))
  395. :set (lambda (symbol value)
  396. (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
  397. value)))
  398. :group 'gnus-article-emphasis)
  399. (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
  400. "A regexp to describe whitespace which should not be emphasized.
  401. Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
  402. The former avoids underlining of leading and trailing whitespace,
  403. and the latter avoids underlining any whitespace at all."
  404. :version "21.1"
  405. :group 'gnus-article-emphasis
  406. :type 'regexp)
  407. (defface gnus-emphasis-bold '((t (:bold t)))
  408. "Face used for displaying strong emphasized text (*word*)."
  409. :group 'gnus-article-emphasis)
  410. (defface gnus-emphasis-italic '((t (:italic t)))
  411. "Face used for displaying italic emphasized text (/word/)."
  412. :group 'gnus-article-emphasis)
  413. (defface gnus-emphasis-underline '((t (:underline t)))
  414. "Face used for displaying underlined emphasized text (_word_)."
  415. :group 'gnus-article-emphasis)
  416. (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
  417. "Face used for displaying underlined bold emphasized text (_*word*_)."
  418. :group 'gnus-article-emphasis)
  419. (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
  420. "Face used for displaying underlined italic emphasized text (_/word/_)."
  421. :group 'gnus-article-emphasis)
  422. (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
  423. "Face used for displaying bold italic emphasized text (/*word*/)."
  424. :group 'gnus-article-emphasis)
  425. (defface gnus-emphasis-underline-bold-italic
  426. '((t (:bold t :italic t :underline t)))
  427. "Face used for displaying underlined bold italic emphasized text.
  428. Example: (_/*word*/_)."
  429. :group 'gnus-article-emphasis)
  430. (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
  431. '((t (:strikethru t)))
  432. '((t (:strike-through t))))
  433. "Face used for displaying strike-through text (-word-)."
  434. :group 'gnus-article-emphasis)
  435. (defface gnus-emphasis-highlight-words
  436. '((t (:background "black" :foreground "yellow")))
  437. "Face used for displaying highlighted words."
  438. :group 'gnus-article-emphasis)
  439. (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
  440. "Format for display of Date headers in article bodies.
  441. See `format-time-string' for the possible values.
  442. The variable can also be function, which should return a complete Date
  443. header. The function is called with one argument, the time, which can
  444. be fed to `format-time-string'."
  445. :type '(choice string function)
  446. :link '(custom-manual "(gnus)Article Date")
  447. :group 'gnus-article-washing)
  448. (defcustom gnus-save-all-headers t
  449. "*If non-nil, don't remove any headers before saving.
  450. This will be overridden by the `:headers' property that the symbol of
  451. the saver function, which is specified by `gnus-default-article-saver',
  452. might have."
  453. :group 'gnus-article-saving
  454. :type 'boolean)
  455. (defcustom gnus-prompt-before-saving 'always
  456. "*This variable says how much prompting is to be done when saving articles.
  457. If it is nil, no prompting will be done, and the articles will be
  458. saved to the default files. If this variable is `always', each and
  459. every article that is saved will be preceded by a prompt, even when
  460. saving large batches of articles. If this variable is neither nil not
  461. `always', there the user will be prompted once for a file name for
  462. each invocation of the saving commands."
  463. :group 'gnus-article-saving
  464. :type '(choice (item always)
  465. (item :tag "never" nil)
  466. (sexp :tag "once" :format "%t\n" :value t)))
  467. (defcustom gnus-saved-headers gnus-visible-headers
  468. "Headers to keep if `gnus-save-all-headers' is nil.
  469. If `gnus-save-all-headers' is non-nil, this variable will be ignored.
  470. If that variable is nil, however, all headers that match this regexp
  471. will be kept while the rest will be deleted before saving. This and
  472. `gnus-save-all-headers' will be overridden by the `:headers' property
  473. that the symbol of the saver function, which is specified by
  474. `gnus-default-article-saver', might have."
  475. :group 'gnus-article-saving
  476. :type 'regexp)
  477. ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
  478. (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
  479. "A function to save articles in your favorite format.
  480. The function will be called by way of the `gnus-summary-save-article'
  481. command, and friends such as `gnus-summary-save-article-rmail'.
  482. Gnus provides the following functions:
  483. * gnus-summary-save-in-rmail (Rmail format)
  484. * gnus-summary-save-in-mail (Unix mail format)
  485. * gnus-summary-save-in-folder (MH folder)
  486. * gnus-summary-save-in-file (article format)
  487. * gnus-summary-save-body-in-file (article body)
  488. * gnus-summary-save-in-vm (use VM's folder format)
  489. * gnus-summary-write-to-file (article format -- overwrite)
  490. * gnus-summary-write-body-to-file (article body -- overwrite)
  491. * gnus-summary-save-in-pipe (article format)
  492. The symbol of each function may have the following properties:
  493. * :decode
  494. The value non-nil means save decoded articles. This is meaningful
  495. only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
  496. `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
  497. `gnus-summary-save-in-pipe'.
  498. * :function
  499. The value specifies an alternative function which appends, not
  500. overwrites, articles to a file. This implies that when saving many
  501. articles at a time, `gnus-prompt-before-saving' is bound to t and all
  502. articles are saved in a single file. This is meaningful only with
  503. `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
  504. * :headers
  505. The value specifies the symbol of a variable of which the value
  506. specifies headers to be saved. If it is omitted,
  507. `gnus-save-all-headers' and `gnus-saved-headers' control what
  508. headers should be saved."
  509. :group 'gnus-article-saving
  510. :type '(radio (function-item gnus-summary-save-in-rmail)
  511. (function-item gnus-summary-save-in-mail)
  512. (function-item gnus-summary-save-in-folder)
  513. (function-item gnus-summary-save-in-file)
  514. (function-item gnus-summary-save-body-in-file)
  515. (function-item gnus-summary-save-in-vm)
  516. (function-item gnus-summary-write-to-file)
  517. (function-item gnus-summary-write-body-to-file)
  518. (function-item gnus-summary-save-in-pipe)
  519. (function)))
  520. (defcustom gnus-article-save-coding-system
  521. (or (and (mm-coding-system-p 'utf-8) 'utf-8)
  522. (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
  523. (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
  524. (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
  525. "Coding system used to save decoded articles to a file.
  526. The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
  527. which can safely encode any characters in text. This is used by the
  528. commands including:
  529. * gnus-summary-save-article-file
  530. * gnus-summary-save-article-body-file
  531. * gnus-summary-write-article-file
  532. * gnus-summary-write-article-body-file
  533. and the functions to which you may set `gnus-default-article-saver':
  534. * gnus-summary-save-in-file
  535. * gnus-summary-save-body-in-file
  536. * gnus-summary-write-to-file
  537. * gnus-summary-write-body-to-file
  538. Those commands and functions save just text displayed in the article
  539. buffer to a file if the value of this variable is non-nil. Note that
  540. buttonized MIME parts will be lost in a saved file in that case.
  541. Otherwise, raw articles will be saved."
  542. :group 'gnus-article-saving
  543. :type `(choice
  544. :format "%{%t%}:\n %[Value Menu%] %v"
  545. (const :tag "Save raw articles" nil)
  546. ,@(delq nil
  547. (mapcar
  548. (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
  549. '((const :tag "UTF-8" utf-8)
  550. (const :tag "iso-2022-7bit" iso-2022-7bit)
  551. (const :tag "Emacs internal" emacs-mule)
  552. (const :tag "escape-quoted" escape-quoted))))
  553. (symbol :tag "Coding system")))
  554. (defcustom gnus-rmail-save-name 'gnus-plain-save-name
  555. "A function generating a file name to save articles in Rmail format.
  556. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
  557. :group 'gnus-article-saving
  558. :type 'function)
  559. (defcustom gnus-mail-save-name 'gnus-plain-save-name
  560. "A function generating a file name to save articles in Unix mail format.
  561. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
  562. :group 'gnus-article-saving
  563. :type 'function)
  564. (defcustom gnus-folder-save-name 'gnus-folder-save-name
  565. "A function generating a file name to save articles in MH folder.
  566. The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
  567. :group 'gnus-article-saving
  568. :type 'function)
  569. (defcustom gnus-file-save-name 'gnus-numeric-save-name
  570. "A function generating a file name to save articles in article format.
  571. The function is called with NEWSGROUP, HEADERS, and optional
  572. LAST-FILE."
  573. :group 'gnus-article-saving
  574. :type 'function)
  575. (defcustom gnus-split-methods
  576. '((gnus-article-archive-name)
  577. (gnus-article-nndoc-name))
  578. "*Variable used to suggest where articles are to be saved.
  579. For instance, if you would like to save articles related to Gnus in
  580. the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
  581. you could set this variable to something like:
  582. '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
  583. (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
  584. This variable is an alist where the key is the match and the
  585. value is a list of possible files to save in if the match is
  586. non-nil.
  587. If the match is a string, it is used as a regexp match on the
  588. article. If the match is a symbol, that symbol will be funcalled
  589. from the buffer of the article to be saved with the newsgroup as the
  590. parameter. If it is a list, it will be evalled in the same buffer.
  591. If this form or function returns a string, this string will be used as a
  592. possible file name; and if it returns a non-nil list, that list will be
  593. used as possible file names."
  594. :group 'gnus-article-saving
  595. :type '(repeat (choice (list :value (fun) function)
  596. (cons :value ("" "") regexp (repeat string))
  597. (sexp :value nil))))
  598. (defcustom gnus-page-delimiter "^\^L"
  599. "*Regexp describing what to use as article page delimiters.
  600. The default value is \"^\^L\", which is a form linefeed at the
  601. beginning of a line."
  602. :type 'regexp
  603. :group 'gnus-article-various)
  604. (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
  605. "*The format specification for the article mode line.
  606. See `gnus-summary-mode-line-format' for a closer description.
  607. The following additional specs are available:
  608. %w The article washing status.
  609. %m The number of MIME parts in the article."
  610. :version "24.1"
  611. :type 'string
  612. :group 'gnus-article-various)
  613. (defcustom gnus-article-mode-hook nil
  614. "*A hook for Gnus article mode."
  615. :type 'hook
  616. :group 'gnus-article-various)
  617. (when (featurep 'xemacs)
  618. ;; Extracted from gnus-xmas-define in order to preserve user settings
  619. (when (fboundp 'turn-off-scroll-in-place)
  620. (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
  621. ;; Extracted from gnus-xmas-redefine in order to preserve user settings
  622. (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
  623. (defcustom gnus-article-menu-hook nil
  624. "*Hook run after the creation of the article mode menu."
  625. :type 'hook
  626. :group 'gnus-article-various)
  627. (defcustom gnus-article-prepare-hook nil
  628. "*A hook called after an article has been prepared in the article buffer."
  629. :type 'hook
  630. :group 'gnus-article-various)
  631. (defcustom gnus-copy-article-ignored-headers nil
  632. "List of headers to be removed when copying an article.
  633. Each element is a regular expression."
  634. :version "23.1" ;; No Gnus
  635. :type '(repeat regexp)
  636. :group 'gnus-article-various)
  637. (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
  638. "Gnus 5.10 (Emacs 22.1)")
  639. (defface gnus-button
  640. '((t (:weight bold)))
  641. "Face used for highlighting a button in the article buffer."
  642. :group 'gnus-article-buttons)
  643. (defcustom gnus-article-button-face 'gnus-button
  644. "Face used for highlighting buttons in the article buffer.
  645. An article button is a piece of text that you can activate by pressing
  646. `RET' or `mouse-2' above it."
  647. :type 'face
  648. :group 'gnus-article-buttons)
  649. (defcustom gnus-article-mouse-face 'highlight
  650. "Face used for mouse highlighting in the article buffer.
  651. Article buttons will be displayed in this face when the cursor is
  652. above them."
  653. :type 'face
  654. :group 'gnus-article-buttons)
  655. (defcustom gnus-signature-face 'gnus-signature
  656. "Face used for highlighting a signature in the article buffer.
  657. Obsolete; use the face `gnus-signature' for customizations instead."
  658. :type 'face
  659. :group 'gnus-article-highlight
  660. :group 'gnus-article-signature)
  661. (defface gnus-signature
  662. '((t
  663. (:italic t)))
  664. "Face used for highlighting a signature in the article buffer."
  665. :group 'gnus-article-highlight
  666. :group 'gnus-article-signature)
  667. ;; backward-compatibility alias
  668. (put 'gnus-signature-face 'face-alias 'gnus-signature)
  669. (put 'gnus-signature-face 'obsolete-face "22.1")
  670. (defface gnus-header-from
  671. '((((class color)
  672. (background dark))
  673. (:foreground "PaleGreen1"))
  674. (((class color)
  675. (background light))
  676. (:foreground "red3"))
  677. (t
  678. (:italic t)))
  679. "Face used for displaying from headers."
  680. :group 'gnus-article-headers
  681. :group 'gnus-article-highlight)
  682. ;; backward-compatibility alias
  683. (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
  684. (put 'gnus-header-from-face 'obsolete-face "22.1")
  685. (defface gnus-header-subject
  686. '((((class color)
  687. (background dark))
  688. (:foreground "SeaGreen1"))
  689. (((class color)
  690. (background light))
  691. (:foreground "red4"))
  692. (t
  693. (:bold t :italic t)))
  694. "Face used for displaying subject headers."
  695. :group 'gnus-article-headers
  696. :group 'gnus-article-highlight)
  697. ;; backward-compatibility alias
  698. (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
  699. (put 'gnus-header-subject-face 'obsolete-face "22.1")
  700. (defface gnus-header-newsgroups
  701. '((((class color)
  702. (background dark))
  703. (:foreground "yellow" :italic t))
  704. (((class color)
  705. (background light))
  706. (:foreground "MidnightBlue" :italic t))
  707. (t
  708. (:italic t)))
  709. "Face used for displaying newsgroups headers.
  710. In the default setup this face is only used for crossposted
  711. articles."
  712. :group 'gnus-article-headers
  713. :group 'gnus-article-highlight)
  714. ;; backward-compatibility alias
  715. (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
  716. (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
  717. (defface gnus-header-name
  718. '((((class color)
  719. (background dark))
  720. (:foreground "SpringGreen2"))
  721. (((class color)
  722. (background light))
  723. (:foreground "maroon"))
  724. (t
  725. (:bold t)))
  726. "Face used for displaying header names."
  727. :group 'gnus-article-headers
  728. :group 'gnus-article-highlight)
  729. ;; backward-compatibility alias
  730. (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
  731. (put 'gnus-header-name-face 'obsolete-face "22.1")
  732. (defface gnus-header-content
  733. '((((class color)
  734. (background dark))
  735. (:foreground "SpringGreen1" :italic t))
  736. (((class color)
  737. (background light))
  738. (:foreground "indianred4" :italic t))
  739. (t
  740. (:italic t))) "Face used for displaying header content."
  741. :group 'gnus-article-headers
  742. :group 'gnus-article-highlight)
  743. ;; backward-compatibility alias
  744. (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
  745. (put 'gnus-header-content-face 'obsolete-face "22.1")
  746. (defcustom gnus-header-face-alist
  747. '(("From" nil gnus-header-from)
  748. ("Subject" nil gnus-header-subject)
  749. ("Newsgroups:.*," nil gnus-header-newsgroups)
  750. ("" gnus-header-name gnus-header-content))
  751. "*Controls highlighting of article headers.
  752. An alist of the form (HEADER NAME CONTENT).
  753. HEADER is a regular expression which should match the name of a
  754. header and NAME and CONTENT are either face names or nil.
  755. The name of each header field will be displayed using the face
  756. specified by the first element in the list where HEADER matches
  757. the header name and NAME is non-nil. Similarly, the content will
  758. be displayed by the first non-nil matching CONTENT face."
  759. :group 'gnus-article-headers
  760. :group 'gnus-article-highlight
  761. :type '(repeat (list (regexp :tag "Header")
  762. (choice :tag "Name"
  763. (item :tag "skip" nil)
  764. (face :value default))
  765. (choice :tag "Content"
  766. (item :tag "skip" nil)
  767. (face :value default)))))
  768. (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
  769. '((xface . (:face gnus-x-face)))
  770. '((pbm . (:face gnus-x-face))
  771. (png . nil)))
  772. "Alist of image types and properties applied to Face and X-Face images.
  773. Here are examples:
  774. ;; Specify the altitude of Face images in the From header.
  775. \(setq gnus-face-properties-alist
  776. '((pbm . (:face gnus-x-face :ascent 80))
  777. (png . (:ascent 80))))
  778. ;; Show Face images as pressed buttons.
  779. \(setq gnus-face-properties-alist
  780. '((pbm . (:face gnus-x-face :relief -2))
  781. (png . (:relief -2))))
  782. See the manual for the valid properties for various image types.
  783. Currently, `pbm' is used for X-Face images and `png' is used for Face
  784. images in Emacs. Only the `:face' property is effective on the `xface'
  785. image type in XEmacs if it is built with the libcompface library."
  786. :version "23.1" ;; No Gnus
  787. :group 'gnus-article-headers
  788. :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
  789. (defcustom gnus-article-decode-hook
  790. '(article-decode-charset article-decode-encoded-words
  791. article-decode-group-name article-decode-idna-rhs)
  792. "*Hook run to decode charsets in articles."
  793. :group 'gnus-article-headers
  794. :type 'hook)
  795. (defcustom gnus-display-mime-function 'gnus-display-mime
  796. "Function to display MIME articles."
  797. :group 'gnus-article-mime
  798. :type 'function)
  799. (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
  800. "Function used to decode headers.")
  801. (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
  802. "Function used to decode addresses.")
  803. (defvar gnus-article-dumbquotes-map
  804. '((?\200 "EUR")
  805. (?\202 ",")
  806. (?\203 "f")
  807. (?\204 ",,")
  808. (?\205 "...")
  809. (?\213 "<")
  810. (?\214 "OE")
  811. (?\221 "`")
  812. (?\222 "'")
  813. (?\223 "``")
  814. (?\224 "\"")
  815. (?\225 "*")
  816. (?\226 "-")
  817. (?\227 "--")
  818. (?\230 "~")
  819. (?\231 "(TM)")
  820. (?\233 ">")
  821. (?\234 "oe")
  822. (?\264 "'"))
  823. "Table for MS-to-Latin1 translation.")
  824. (defcustom gnus-ignored-mime-types nil
  825. "List of MIME types that should be ignored by Gnus."
  826. :version "21.1"
  827. :group 'gnus-article-mime
  828. :type '(repeat regexp))
  829. (defcustom gnus-unbuttonized-mime-types '(".*/.*")
  830. "List of MIME types that should not be given buttons when rendered inline.
  831. See also `gnus-buttonized-mime-types' which may override this variable.
  832. This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
  833. :version "21.1"
  834. :group 'gnus-article-mime
  835. :type '(repeat regexp))
  836. (defcustom gnus-buttonized-mime-types nil
  837. "List of MIME types that should be given buttons when rendered inline.
  838. If set, this variable overrides `gnus-unbuttonized-mime-types'.
  839. To see e.g. security buttons you could set this to
  840. `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
  841. this list to display radio buttons that allow you to choose one of two
  842. media types those mails include. See also `mm-discouraged-alternatives'.
  843. This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
  844. :version "22.1"
  845. :group 'gnus-article-mime
  846. :type '(repeat regexp))
  847. (defcustom gnus-inhibit-mime-unbuttonizing nil
  848. "If non-nil, all MIME parts get buttons.
  849. When nil (the default value), then some MIME parts do not get buttons,
  850. as described by the variables `gnus-buttonized-mime-types' and
  851. `gnus-unbuttonized-mime-types'."
  852. :version "22.1"
  853. :group 'gnus-article-mime
  854. :type 'boolean)
  855. (defcustom gnus-body-boundary-delimiter "_"
  856. "String used to delimit header and body.
  857. This variable is used by `gnus-article-treat-body-boundary' which can
  858. be controlled by `gnus-treat-body-boundary'."
  859. :version "22.1"
  860. :group 'gnus-article-various
  861. :type '(choice (item :tag "None" :value nil)
  862. string))
  863. (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
  864. "/usr/share/picons")
  865. "Defines the location of the faces database.
  866. For information on obtaining this database of pretty pictures, please
  867. see http://www.cs.indiana.edu/picons/ftp/index.html"
  868. :version "22.1"
  869. :type '(repeat directory)
  870. :link '(url-link :tag "download"
  871. "http://www.cs.indiana.edu/picons/ftp/index.html")
  872. :link '(custom-manual "(gnus)Picons")
  873. :group 'gnus-picon)
  874. (defun gnus-picons-installed-p ()
  875. "Say whether picons are installed on your machine."
  876. (let ((installed nil))
  877. (dolist (database gnus-picon-databases)
  878. (when (file-exists-p database)
  879. (setq installed t)))
  880. installed))
  881. (defcustom gnus-article-mime-part-function nil
  882. "Function called with a MIME handle as the argument.
  883. This is meant for people who want to do something automatic based
  884. on parts -- for instance, adding Vcard info to a database."
  885. :group 'gnus-article-mime
  886. :type '(choice (const nil)
  887. function))
  888. (defcustom gnus-mime-multipart-functions nil
  889. "An alist of MIME types to functions to display them."
  890. :version "21.1"
  891. :group 'gnus-article-mime
  892. :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
  893. (defcustom gnus-article-date-headers '(combined-lapsed)
  894. "A list of Date header formats to display.
  895. Valid formats are `ut' (universal time), `local' (local time
  896. zone), `english' (readable English), `lapsed' (elapsed time),
  897. `combined-lapsed' (both the original date and the elapsed time),
  898. `original' (the original date header), `iso8601' (ISO8601
  899. format), and `user-defined' (a user-defined format defined by the
  900. `gnus-article-time-format' variable).
  901. You have as many date headers as you want in the article buffer.
  902. Some of these headers are updated automatically. See
  903. `gnus-article-update-date-headers' for details."
  904. :version "24.1"
  905. :group 'gnus-article-headers
  906. :type '(repeat
  907. (item :tag "Universal time (UT)" :value 'ut)
  908. (item :tag "Local time zone" :value 'local)
  909. (item :tag "Readable English" :value 'english)
  910. (item :tag "Elapsed time" :value 'lapsed)
  911. (item :tag "Original and elapsed time" :value 'combined-lapsed)
  912. (item :tag "Original date header" :value 'original)
  913. (item :tag "ISO8601 format" :value 'iso8601)
  914. (item :tag "User-defined" :value 'user-defined)))
  915. (defcustom gnus-article-update-date-headers nil
  916. "A number that says how often to update the date header (in seconds).
  917. If nil, don't update it at all."
  918. :version "24.1"
  919. :group 'gnus-article-headers
  920. :type '(choice
  921. (item :tag "Don't update" :value nil)
  922. integer))
  923. (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
  924. "Function called with a MIME handle as the argument.
  925. This is meant for people who want to view first matched part.
  926. For `undisplayed-alternative' (default), the first undisplayed
  927. part or alternative part is used. For `undisplayed', the first
  928. undisplayed part is used. For a function, the first part which
  929. the function return t is used. For nil, the first part is
  930. used."
  931. :version "21.1"
  932. :group 'gnus-article-mime
  933. :type '(choice
  934. (item :tag "first" :value nil)
  935. (item :tag "undisplayed" :value undisplayed)
  936. (item :tag "undisplayed or alternative"
  937. :value undisplayed-alternative)
  938. (function)))
  939. (defcustom gnus-mime-action-alist
  940. '(("save to file" . gnus-mime-save-part)
  941. ("save and strip" . gnus-mime-save-part-and-strip)
  942. ("replace with file" . gnus-mime-replace-part)
  943. ("delete part" . gnus-mime-delete-part)
  944. ("display as text" . gnus-mime-inline-part)
  945. ("view the part" . gnus-mime-view-part)
  946. ("pipe to command" . gnus-mime-pipe-part)
  947. ("toggle display" . gnus-article-press-button)
  948. ("toggle display" . gnus-article-view-part-as-charset)
  949. ("view as type" . gnus-mime-view-part-as-type)
  950. ("view internally" . gnus-mime-view-part-internally)
  951. ("view externally" . gnus-mime-view-part-externally))
  952. "An alist of actions that run on the MIME attachment."
  953. :group 'gnus-article-mime
  954. :type '(repeat (cons (string :tag "name")
  955. (function))))
  956. (defcustom gnus-auto-select-part 1
  957. "Advance to next MIME part when deleting or stripping parts.
  958. When 0, point will be placed on the same part as before. When
  959. positive (negative), move point forward (backwards) this many
  960. parts. When nil, redisplay article."
  961. :version "23.1" ;; No Gnus
  962. :group 'gnus-article-mime
  963. :type '(choice (const nil :tag "Redisplay article.")
  964. (const 1 :tag "Next part.")
  965. (const 0 :tag "Current part.")
  966. integer))
  967. ;;;
  968. ;;; The treatment variables
  969. ;;;
  970. (defvar gnus-part-display-hook nil
  971. "Hook called on parts that are to receive treatment.")
  972. (defvar gnus-article-treat-custom
  973. '(choice (const :tag "Off" nil)
  974. (const :tag "On" t)
  975. (const :tag "Header" head)
  976. (const :tag "First" first)
  977. (const :tag "Last" last)
  978. (integer :tag "Less")
  979. (repeat :tag "Groups" regexp)
  980. (sexp :tag "Predicate")))
  981. (defvar gnus-article-treat-head-custom
  982. '(choice (const :tag "Off" nil)
  983. (const :tag "Header" head)))
  984. (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
  985. "text/x-patch")
  986. "Parts to treat.")
  987. (defvar gnus-inhibit-treatment nil
  988. "Whether to inhibit treatment.")
  989. (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
  990. "Highlight the signature.
  991. Valid values are nil, t, `head', `first', `last', an integer or a
  992. predicate. See Info node `(gnus)Customizing Articles'."
  993. :group 'gnus-article-treat
  994. :link '(custom-manual "(gnus)Customizing Articles")
  995. :type gnus-article-treat-custom)
  996. (put 'gnus-treat-highlight-signature 'highlight t)
  997. (defcustom gnus-treat-buttonize 100000
  998. "Add buttons.
  999. Valid values are nil, t, `head', `first', `last', an integer or a
  1000. predicate. See Info node `(gnus)Customizing Articles'."
  1001. :group 'gnus-article-treat
  1002. :link '(custom-manual "(gnus)Customizing Articles")
  1003. :type gnus-article-treat-custom)
  1004. (put 'gnus-treat-buttonize 'highlight t)
  1005. (defcustom gnus-treat-buttonize-head 'head
  1006. "Add buttons to the head.
  1007. Valid values are nil, t, `head', `first', `last', an integer or a
  1008. predicate. See Info node `(gnus)Customizing Articles'."
  1009. :group 'gnus-article-treat
  1010. :link '(custom-manual "(gnus)Customizing Articles")
  1011. :type gnus-article-treat-head-custom)
  1012. (put 'gnus-treat-buttonize-head 'highlight t)
  1013. (defcustom gnus-treat-date 'head
  1014. "Display dates according to the `gnus-article-date-headers' variable.
  1015. Valid values are nil, t, `head', `first', `last', an integer or a
  1016. predicate. See Info node `(gnus)Customizing Articles'."
  1017. :version "24.1"
  1018. :group 'gnus-article-treat
  1019. :link '(custom-manual "(gnus)Customizing Articles")
  1020. :type gnus-article-treat-head-custom)
  1021. (defcustom gnus-treat-emphasize 50000
  1022. "Emphasize text.
  1023. Valid values are nil, t, `head', `first', `last', an integer or a
  1024. predicate. See Info node `(gnus)Customizing Articles'."
  1025. :group 'gnus-article-treat
  1026. :link '(custom-manual "(gnus)Customizing Articles")
  1027. :type gnus-article-treat-custom)
  1028. (put 'gnus-treat-emphasize 'highlight t)
  1029. (defcustom gnus-treat-strip-cr nil
  1030. "Remove carriage returns.
  1031. Valid values are nil, t, `head', `first', `last', an integer or a
  1032. predicate. See Info node `(gnus)Customizing Articles'."
  1033. :version "22.1"
  1034. :group 'gnus-article-treat
  1035. :link '(custom-manual "(gnus)Customizing Articles")
  1036. :type gnus-article-treat-custom)
  1037. (defcustom gnus-treat-unsplit-urls nil
  1038. "Remove newlines from within URLs.
  1039. Valid values are nil, t, `head', `first', `last', an integer or a
  1040. predicate. See Info node `(gnus)Customizing Articles'."
  1041. :version "22.1"
  1042. :group 'gnus-article-treat
  1043. :link '(custom-manual "(gnus)Customizing Articles")
  1044. :type gnus-article-treat-custom)
  1045. (defcustom gnus-treat-leading-whitespace nil
  1046. "Remove leading whitespace in headers.
  1047. Valid values are nil, t, `head', `first', `last', an integer or a
  1048. predicate. See Info node `(gnus)Customizing Articles'."
  1049. :version "22.1"
  1050. :group 'gnus-article-treat
  1051. :link '(custom-manual "(gnus)Customizing Articles")
  1052. :type gnus-article-treat-custom)
  1053. (defcustom gnus-treat-hide-headers 'head
  1054. "Hide headers.
  1055. Valid values are nil, t, `head', `first', `last', an integer or a
  1056. predicate. See Info node `(gnus)Customizing Articles'."
  1057. :group 'gnus-article-treat
  1058. :link '(custom-manual "(gnus)Customizing Articles")
  1059. :type gnus-article-treat-head-custom)
  1060. (defcustom gnus-treat-hide-boring-headers nil
  1061. "Hide boring headers.
  1062. Valid values are nil, t, `head', `first', `last', an integer or a
  1063. predicate. See Info node `(gnus)Customizing Articles'."
  1064. :group 'gnus-article-treat
  1065. :link '(custom-manual "(gnus)Customizing Articles")
  1066. :type gnus-article-treat-head-custom)
  1067. (defcustom gnus-treat-hide-signature nil
  1068. "Hide the signature.
  1069. Valid values are nil, t, `head', `first', `last', an integer or a
  1070. predicate. See Info node `(gnus)Customizing Articles'."
  1071. :group 'gnus-article-treat
  1072. :link '(custom-manual "(gnus)Customizing Articles")
  1073. :type gnus-article-treat-custom)
  1074. (defcustom gnus-treat-fill-article nil
  1075. "Fill the article.
  1076. Valid values are nil, t, `head', `first', `last', an integer or a
  1077. predicate. See Info node `(gnus)Customizing Articles'."
  1078. :group 'gnus-article-treat
  1079. :link '(custom-manual "(gnus)Customizing Articles")
  1080. :type gnus-article-treat-custom)
  1081. (defcustom gnus-treat-hide-citation nil
  1082. "Hide cited text.
  1083. Valid values are nil, t, `head', `first', `last', an integer or a
  1084. predicate. See Info node `(gnus)Customizing Articles'.
  1085. See `gnus-article-highlight-citation' for variables used to
  1086. control what it hides."
  1087. :group 'gnus-article-treat
  1088. :link '(custom-manual "(gnus)Customizing Articles")
  1089. :type gnus-article-treat-custom)
  1090. (defcustom gnus-treat-hide-citation-maybe nil
  1091. "Hide cited text according to certain conditions.
  1092. Valid values are nil, t, `head', `first', `last', an integer or a
  1093. predicate. See Info node `(gnus)Customizing Articles'.
  1094. See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
  1095. how to control what it hides."
  1096. :group 'gnus-article-treat
  1097. :link '(custom-manual "(gnus)Customizing Articles")
  1098. :type gnus-article-treat-custom)
  1099. (defcustom gnus-treat-strip-list-identifiers 'head
  1100. "Strip list identifiers from `gnus-list-identifiers`.
  1101. Valid values are nil, t, `head', `first', `last', an integer or a
  1102. predicate. See Info node `(gnus)Customizing Articles'."
  1103. :version "21.1"
  1104. :group 'gnus-article-treat
  1105. :link '(custom-manual "(gnus)Customizing Articles")
  1106. :type gnus-article-treat-custom)
  1107. (gnus-define-group-parameter
  1108. list-identifier
  1109. :variable-document
  1110. "Alist of regexps and correspondent identifiers."
  1111. :variable-group gnus-article-washing
  1112. :parameter-type
  1113. '(choice :tag "Identifier"
  1114. :value nil
  1115. (symbol :tag "Item in `gnus-list-identifiers'" none)
  1116. regexp
  1117. (const :tag "None" nil))
  1118. :parameter-document
  1119. "If non-nil, specify how to remove `identifiers' from articles' subject.
  1120. Any symbol is used to look up a regular expression to match the
  1121. banner in `gnus-list-identifiers'. A string is used as a regular
  1122. expression to match the identifier directly.")
  1123. (make-obsolete-variable 'gnus-treat-strip-pgp nil
  1124. "Gnus 5.10 (Emacs 22.1)")
  1125. (defcustom gnus-treat-strip-pem nil
  1126. "Strip PEM signatures.
  1127. Valid values are nil, t, `head', `first', `last', an integer or a
  1128. predicate. See Info node `(gnus)Customizing Articles'."
  1129. :group 'gnus-article-treat
  1130. :link '(custom-manual "(gnus)Customizing Articles")
  1131. :type gnus-article-treat-custom)
  1132. (defcustom gnus-treat-strip-banner t
  1133. "Strip banners from articles.
  1134. The banner to be stripped is specified in the `banner' group parameter.
  1135. Valid values are nil, t, `head', `first', `last', an integer or a
  1136. predicate. See Info node `(gnus)Customizing Articles'."
  1137. :group 'gnus-article-treat
  1138. :link '(custom-manual "(gnus)Customizing Articles")
  1139. :type gnus-article-treat-custom)
  1140. (defcustom gnus-treat-highlight-headers 'head
  1141. "Highlight the headers.
  1142. Valid values are nil, t, `head', `first', `last', an integer or a
  1143. predicate. See Info node `(gnus)Customizing Articles'."
  1144. :group 'gnus-article-treat
  1145. :link '(custom-manual "(gnus)Customizing Articles")
  1146. :type gnus-article-treat-head-custom)
  1147. (put 'gnus-treat-highlight-headers 'highlight t)
  1148. (defcustom gnus-treat-highlight-citation t
  1149. "Highlight cited text.
  1150. Valid values are nil, t, `head', `first', `last', an integer or a
  1151. predicate. See Info node `(gnus)Customizing Articles'."
  1152. :group 'gnus-article-treat
  1153. :link '(custom-manual "(gnus)Customizing Articles")
  1154. :type gnus-article-treat-custom)
  1155. (put 'gnus-treat-highlight-citation 'highlight t)
  1156. (defcustom gnus-treat-strip-headers-in-body t
  1157. "Strip the X-No-Archive header line from the beginning of the body.
  1158. Valid values are nil, t, `head', `first', `last', an integer or a
  1159. predicate. See Info node `(gnus)Customizing Articles'."
  1160. :version "21.1"
  1161. :group 'gnus-article-treat
  1162. :link '(custom-manual "(gnus)Customizing Articles")
  1163. :type gnus-article-treat-custom)
  1164. (defcustom gnus-treat-strip-trailing-blank-lines nil
  1165. "Strip trailing blank lines.
  1166. Valid values are nil, t, `head', `first', `last', an integer or a
  1167. predicate. See Info node `(gnus)Customizing Articles'.
  1168. When set to t, it also strips trailing blanks in all MIME parts.
  1169. Consider to use `last' instead."
  1170. :group 'gnus-article-treat
  1171. :link '(custom-manual "(gnus)Customizing Articles")
  1172. :type gnus-article-treat-custom)
  1173. (defcustom gnus-treat-strip-leading-blank-lines nil
  1174. "Strip leading blank lines.
  1175. Valid values are nil, t, `head', `first', `last', an integer or a
  1176. predicate. See Info node `(gnus)Customizing Articles'.
  1177. When set to t, it also strips trailing blanks in all MIME parts."
  1178. :group 'gnus-article-treat
  1179. :link '(custom-manual "(gnus)Customizing Articles")
  1180. :type gnus-article-treat-custom)
  1181. (defcustom gnus-treat-strip-multiple-blank-lines nil
  1182. "Strip multiple blank lines.
  1183. Valid values are nil, t, `head', `first', `last', an integer or a
  1184. predicate. See Info node `(gnus)Customizing Articles'."
  1185. :group 'gnus-article-treat
  1186. :link '(custom-manual "(gnus)Customizing Articles")
  1187. :type gnus-article-treat-custom)
  1188. (defcustom gnus-treat-unfold-headers 'head
  1189. "Unfold folded header lines.
  1190. Valid values are nil, t, `head', `first', `last', an integer or a
  1191. predicate. See Info node `(gnus)Customizing Articles'."
  1192. :version "22.1"
  1193. :group 'gnus-article-treat
  1194. :link '(custom-manual "(gnus)Customizing Articles")
  1195. :type gnus-article-treat-custom)
  1196. (defcustom gnus-article-unfold-long-headers nil
  1197. "If non-nil, allow unfolding headers even if the header is long.
  1198. If it is a regexp, only long headers matching this regexp are unfolded.
  1199. If it is t, all long headers are unfolded.
  1200. This variable has no effect if `gnus-treat-unfold-headers' is nil."
  1201. :version "23.1" ;; No Gnus
  1202. :group 'gnus-article-treat
  1203. :type '(choice (const nil)
  1204. (const :tag "all" t)
  1205. (regexp)))
  1206. (defcustom gnus-treat-fold-headers nil
  1207. "Fold headers.
  1208. Valid values are nil, t, `head', `first', `last', an integer or a
  1209. predicate. See Info node `(gnus)Customizing Articles'."
  1210. :version "22.1"
  1211. :group 'gnus-article-treat
  1212. :link '(custom-manual "(gnus)Customizing Articles")
  1213. :type gnus-article-treat-custom)
  1214. (defcustom gnus-treat-fold-newsgroups 'head
  1215. "Fold the Newsgroups and Followup-To headers.
  1216. Valid values are nil, t, `head', `first', `last', an integer or a
  1217. predicate. See Info node `(gnus)Customizing Articles'."
  1218. :version "22.1"
  1219. :group 'gnus-article-treat
  1220. :link '(custom-manual "(gnus)Customizing Articles")
  1221. :type gnus-article-treat-custom)
  1222. (defcustom gnus-treat-overstrike t
  1223. "Treat overstrike highlighting.
  1224. Valid values are nil, t, `head', `first', `last', an integer or a
  1225. predicate. See Info node `(gnus)Customizing Articles'."
  1226. :group 'gnus-article-treat
  1227. :link '(custom-manual "(gnus)Customizing Articles")
  1228. :type gnus-article-treat-custom)
  1229. (put 'gnus-treat-overstrike 'highlight t)
  1230. (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
  1231. "Treat ANSI SGR control sequences.
  1232. Valid values are nil, t, `head', `first', `last', an integer or a
  1233. predicate. See Info node `(gnus)Customizing Articles'."
  1234. :group 'gnus-article-treat
  1235. :link '(custom-manual "(gnus)Customizing Articles")
  1236. :type gnus-article-treat-custom)
  1237. (make-obsolete-variable 'gnus-treat-display-xface
  1238. 'gnus-treat-display-x-face "Emacs 22.1")
  1239. (defcustom gnus-treat-display-x-face
  1240. (and (not noninteractive)
  1241. (gnus-image-type-available-p 'xbm)
  1242. (if (featurep 'xemacs)
  1243. (featurep 'xface)
  1244. (condition-case nil
  1245. (and (string-match "^0x" (shell-command-to-string "uncompface"))
  1246. (executable-find "icontopbm"))
  1247. ;; shell-command-to-string may signal an error, e.g. if
  1248. ;; shell-file-name is not found.
  1249. (error nil)))
  1250. 'head)
  1251. "Display X-Face headers.
  1252. Valid values are nil and `head'.
  1253. See Info node `(gnus)Customizing Articles' and Info node
  1254. `(gnus)X-Face' for details."
  1255. :group 'gnus-article-treat
  1256. :version "21.1"
  1257. :link '(custom-manual "(gnus)Customizing Articles")
  1258. :link '(custom-manual "(gnus)X-Face")
  1259. :type gnus-article-treat-head-custom
  1260. :set (lambda (symbol value)
  1261. (set-default
  1262. symbol
  1263. (cond ((or (boundp symbol) (get symbol 'saved-value))
  1264. value)
  1265. ((boundp 'gnus-treat-display-xface)
  1266. (message "\
  1267. ** gnus-treat-display-xface is an obsolete variable;\
  1268. use gnus-treat-display-x-face instead")
  1269. (default-value 'gnus-treat-display-xface))
  1270. ((get 'gnus-treat-display-xface 'saved-value)
  1271. (message "\
  1272. ** gnus-treat-display-xface is an obsolete variable;\
  1273. use gnus-treat-display-x-face instead")
  1274. (eval (car (get 'gnus-treat-display-xface 'saved-value))))
  1275. (t
  1276. value)))))
  1277. (put 'gnus-treat-display-x-face 'highlight t)
  1278. (defcustom gnus-treat-display-face
  1279. (and (not noninteractive)
  1280. (gnus-image-type-available-p 'png)
  1281. 'head)
  1282. "Display Face headers.
  1283. Valid values are nil, t, `head', `first', `last', an integer or a
  1284. predicate. See Info node `(gnus)Customizing Articles' and Info
  1285. node `(gnus)Face' for details."
  1286. :group 'gnus-article-treat
  1287. :version "22.1"
  1288. :link '(custom-manual "(gnus)Customizing Articles")
  1289. :link '(custom-manual "(gnus)X-Face")
  1290. :type gnus-article-treat-head-custom)
  1291. (put 'gnus-treat-display-face 'highlight t)
  1292. (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
  1293. "Display smileys.
  1294. Valid values are nil, t, `head', `first', `last', an integer or a
  1295. predicate. See Info node `(gnus)Customizing Articles' and Info
  1296. node `(gnus)Smileys' for details."
  1297. :group 'gnus-article-treat
  1298. :version "21.1"
  1299. :link '(custom-manual "(gnus)Customizing Articles")
  1300. :link '(custom-manual "(gnus)Smileys")
  1301. :type gnus-article-treat-custom)
  1302. (put 'gnus-treat-display-smileys 'highlight t)
  1303. (defcustom gnus-treat-from-picon
  1304. (if (and (gnus-image-type-available-p 'xpm)
  1305. (gnus-picons-installed-p))
  1306. 'head nil)
  1307. "Display picons in the From header.
  1308. Valid values are nil, t, `head', `first', `last', an integer or a
  1309. predicate. See Info node `(gnus)Customizing Articles' and Info
  1310. node `(gnus)Picons' for details."
  1311. :version "22.1"
  1312. :group 'gnus-article-treat
  1313. :group 'gnus-picon
  1314. :link '(custom-manual "(gnus)Customizing Articles")
  1315. :link '(custom-manual "(gnus)Picons")
  1316. :type gnus-article-treat-head-custom)
  1317. (put 'gnus-treat-from-picon 'highlight t)
  1318. (defcustom gnus-treat-mail-picon
  1319. (if (and (gnus-image-type-available-p 'xpm)
  1320. (gnus-picons-installed-p))
  1321. 'head nil)
  1322. "Display picons in To and Cc headers.
  1323. Valid values are nil, t, `head', `first', `last', an integer or a
  1324. predicate. See Info node `(gnus)Customizing Articles' and Info
  1325. node `(gnus)Picons' for details."
  1326. :version "22.1"
  1327. :group 'gnus-article-treat
  1328. :group 'gnus-picon
  1329. :link '(custom-manual "(gnus)Customizing Articles")
  1330. :link '(custom-manual "(gnus)Picons")
  1331. :type gnus-article-treat-head-custom)
  1332. (put 'gnus-treat-mail-picon 'highlight t)
  1333. (defcustom gnus-treat-newsgroups-picon
  1334. (if (and (gnus-image-type-available-p 'xpm)
  1335. (gnus-picons-installed-p))
  1336. 'head nil)
  1337. "Display picons in the Newsgroups and Followup-To headers.
  1338. Valid values are nil, t, `head', `first', `last', an integer or a
  1339. predicate. See Info node `(gnus)Customizing Articles' and Info
  1340. node `(gnus)Picons' for details."
  1341. :version "22.1"
  1342. :group 'gnus-article-treat
  1343. :group 'gnus-picon
  1344. :link '(custom-manual "(gnus)Customizing Articles")
  1345. :link '(custom-manual "(gnus)Picons")
  1346. :type gnus-article-treat-head-custom)
  1347. (put 'gnus-treat-newsgroups-picon 'highlight t)
  1348. (defcustom gnus-treat-from-gravatar nil
  1349. "Display gravatars in the From header.
  1350. Valid values are nil, t, `head', `first', `last', an integer or a
  1351. predicate. See Info node `(gnus)Customizing Articles' and Info
  1352. node `(gnus)Gravatars' for details."
  1353. :version "24.1"
  1354. :group 'gnus-article-treat
  1355. :group 'gnus-gravatar
  1356. :link '(custom-manual "(gnus)Customizing Articles")
  1357. :link '(custom-manual "(gnus)Gravatars")
  1358. :type gnus-article-treat-head-custom)
  1359. (put 'gnus-treat-from-gravatar 'highlight t)
  1360. (defcustom gnus-treat-mail-gravatar nil
  1361. "Display gravatars in To and Cc headers.
  1362. Valid values are nil, t, `head', `first', `last', an integer or a
  1363. predicate. See Info node `(gnus)Customizing Articles' and Info
  1364. node `(gnus)Gravatars' for details."
  1365. :version "24.1"
  1366. :group 'gnus-article-treat
  1367. :group 'gnus-gravatar
  1368. :link '(custom-manual "(gnus)Customizing Articles")
  1369. :link '(custom-manual "(gnus)Gravatars")
  1370. :type gnus-article-treat-head-custom)
  1371. (put 'gnus-treat-mail-gravatar 'highlight t)
  1372. (defcustom gnus-treat-body-boundary
  1373. (if (or gnus-treat-newsgroups-picon
  1374. gnus-treat-mail-picon
  1375. gnus-treat-from-picon
  1376. gnus-treat-from-gravatar
  1377. gnus-treat-mail-gravatar)
  1378. ;; If there's much decoration, the user might prefer a boundary.
  1379. 'head
  1380. nil)
  1381. "Draw a boundary at the end of the headers.
  1382. Valid values are nil and `head'.
  1383. See Info node `(gnus)Customizing Articles' for details."
  1384. :version "22.1"
  1385. :group 'gnus-article-treat
  1386. :link '(custom-manual "(gnus)Customizing Articles")
  1387. :type gnus-article-treat-head-custom)
  1388. (defcustom gnus-treat-capitalize-sentences nil
  1389. "Capitalize sentence-starting words.
  1390. Valid values are nil, t, `head', `first', `last', an integer or a
  1391. predicate. See Info node `(gnus)Customizing Articles'."
  1392. :version "21.1"
  1393. :group 'gnus-article-treat
  1394. :link '(custom-manual "(gnus)Customizing Articles")
  1395. :type gnus-article-treat-custom)
  1396. (defcustom gnus-treat-wash-html nil
  1397. "Format as HTML.
  1398. Valid values are nil, t, `head', `first', `last', an integer or a
  1399. predicate. See Info node `(gnus)Customizing Articles'."
  1400. :version "22.1"
  1401. :group 'gnus-article-treat
  1402. :link '(custom-manual "(gnus)Customizing Articles")
  1403. :type gnus-article-treat-custom)
  1404. (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
  1405. "Fill long lines.
  1406. Valid values are nil, t, `head', `first', `last', an integer or a
  1407. predicate. See Info node `(gnus)Customizing Articles'."
  1408. :version "24.1"
  1409. :group 'gnus-article-treat
  1410. :link '(custom-manual "(gnus)Customizing Articles")
  1411. :type gnus-article-treat-custom)
  1412. (defcustom gnus-treat-x-pgp-sig nil
  1413. "Verify X-PGP-Sig.
  1414. To automatically treat X-PGP-Sig, set it to head.
  1415. Valid values are nil, t, `head', `first', `last', an integer or a
  1416. predicate. See Info node `(gnus)Customizing Articles'."
  1417. :version "22.1"
  1418. :group 'gnus-article-treat
  1419. :group 'mime-security
  1420. :link '(custom-manual "(gnus)Customizing Articles")
  1421. :type gnus-article-treat-custom)
  1422. (defvar gnus-article-encrypt-protocol-alist
  1423. '(("PGP" . mml2015-self-encrypt)))
  1424. ;; Set to nil if more than one protocol added to
  1425. ;; gnus-article-encrypt-protocol-alist.
  1426. (defcustom gnus-article-encrypt-protocol "PGP"
  1427. "The protocol used for encrypt articles.
  1428. It is a string, such as \"PGP\". If nil, ask user."
  1429. :version "22.1"
  1430. :type 'string
  1431. :group 'mime-security)
  1432. (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
  1433. (mm-coding-system-p 'utf-8)
  1434. (executable-find idna-program))
  1435. "Whether IDNA decoding of headers is used when viewing messages.
  1436. This requires GNU Libidn, and by default only enabled if it is found."
  1437. :version "22.1"
  1438. :group 'gnus-article-headers
  1439. :type 'boolean)
  1440. (defcustom gnus-article-over-scroll nil
  1441. "If non-nil, allow scrolling the article buffer even when there no more text."
  1442. :version "22.1"
  1443. :group 'gnus-article
  1444. :type 'boolean)
  1445. (defcustom gnus-inhibit-images nil
  1446. "Non-nil means inhibit displaying of images inline in the article body."
  1447. :version "24.1"
  1448. :group 'gnus-article
  1449. :type 'boolean)
  1450. (defcustom gnus-blocked-images 'gnus-block-private-groups
  1451. "Images that have URLs matching this regexp will be blocked.
  1452. This can also be a function to be evaluated. If so, it will be
  1453. called with the group name as the parameter, and should return a
  1454. regexp."
  1455. :version "24.1"
  1456. :group 'gnus-art
  1457. :type 'regexp)
  1458. ;;; Internal variables
  1459. (defvar gnus-english-month-names
  1460. '("January" "February" "March" "April" "May" "June" "July" "August"
  1461. "September" "October" "November" "December"))
  1462. (defvar article-goto-body-goes-to-point-min-p nil)
  1463. (defvar gnus-article-wash-types nil)
  1464. (defvar gnus-article-emphasis-alist nil)
  1465. (defvar gnus-article-image-alist nil)
  1466. (defvar gnus-article-mime-handle-alist-1 nil)
  1467. (defvar gnus-treatment-function-alist
  1468. '((gnus-treat-strip-cr gnus-article-remove-cr)
  1469. (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
  1470. (gnus-treat-strip-banner gnus-article-strip-banner)
  1471. (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
  1472. (gnus-treat-highlight-signature gnus-article-highlight-signature)
  1473. (gnus-treat-buttonize gnus-article-add-buttons)
  1474. (gnus-treat-fill-article gnus-article-fill-cited-article)
  1475. (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
  1476. (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
  1477. (gnus-treat-display-x-face gnus-article-display-x-face)
  1478. (gnus-treat-display-face gnus-article-display-face)
  1479. (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
  1480. (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
  1481. (gnus-treat-hide-signature gnus-article-hide-signature)
  1482. (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
  1483. (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
  1484. (gnus-treat-from-picon gnus-treat-from-picon)
  1485. (gnus-treat-mail-picon gnus-treat-mail-picon)
  1486. (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
  1487. (gnus-treat-strip-pem gnus-article-hide-pem)
  1488. (gnus-treat-date gnus-article-treat-date)
  1489. (gnus-treat-from-gravatar gnus-treat-from-gravatar)
  1490. (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
  1491. (gnus-treat-highlight-headers gnus-article-highlight-headers)
  1492. (gnus-treat-highlight-signature gnus-article-highlight-signature)
  1493. (gnus-treat-strip-trailing-blank-lines
  1494. gnus-article-remove-trailing-blank-lines)
  1495. (gnus-treat-strip-leading-blank-lines
  1496. gnus-article-strip-leading-blank-lines)
  1497. (gnus-treat-strip-multiple-blank-lines
  1498. gnus-article-strip-multiple-blank-lines)
  1499. (gnus-treat-overstrike gnus-article-treat-overstrike)
  1500. (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
  1501. (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
  1502. (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
  1503. (gnus-treat-fold-headers gnus-article-treat-fold-headers)
  1504. (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
  1505. (gnus-treat-display-smileys gnus-treat-smiley)
  1506. (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
  1507. (gnus-treat-wash-html gnus-article-wash-html)
  1508. (gnus-treat-emphasize gnus-article-emphasize)
  1509. (gnus-treat-hide-citation gnus-article-hide-citation)
  1510. (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
  1511. (gnus-treat-highlight-citation gnus-article-highlight-citation)
  1512. (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
  1513. (defvar gnus-article-mime-handle-alist nil)
  1514. (defvar article-lapsed-timer nil)
  1515. (defvar gnus-article-current-summary nil)
  1516. (defvar gnus-article-mode-syntax-table
  1517. (let ((table (copy-syntax-table text-mode-syntax-table)))
  1518. ;; This causes the citation match run O(2^n).
  1519. ;; (modify-syntax-entry ?- "w" table)
  1520. (modify-syntax-entry ?> ")<" table)
  1521. (modify-syntax-entry ?< "(>" table)
  1522. ;; make M-. in article buffers work for `foo' strings
  1523. (modify-syntax-entry ?' " " table)
  1524. (modify-syntax-entry ?` " " table)
  1525. table)
  1526. "Syntax table used in article mode buffers.
  1527. Initialized from `text-mode-syntax-table.")
  1528. (defvar gnus-save-article-buffer nil)
  1529. (defvar gnus-number-of-articles-to-be-saved nil)
  1530. (defvar gnus-inhibit-hiding nil)
  1531. (defvar gnus-article-edit-mode nil)
  1532. ;;; Macros for dealing with the article buffer.
  1533. (defmacro gnus-with-article-headers (&rest forms)
  1534. `(with-current-buffer gnus-article-buffer
  1535. (save-restriction
  1536. (let ((inhibit-read-only t)
  1537. (inhibit-point-motion-hooks t)
  1538. (case-fold-search t))
  1539. (article-narrow-to-head)
  1540. ,@forms))))
  1541. (put 'gnus-with-article-headers 'lisp-indent-function 0)
  1542. (put 'gnus-with-article-headers 'edebug-form-spec '(body))
  1543. (defmacro gnus-with-article-buffer (&rest forms)
  1544. `(when (buffer-live-p (get-buffer gnus-article-buffer))
  1545. (with-current-buffer gnus-article-buffer
  1546. (let ((inhibit-read-only t))
  1547. ,@forms))))
  1548. (put 'gnus-with-article-buffer 'lisp-indent-function 0)
  1549. (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
  1550. (defun gnus-article-goto-header (header)
  1551. "Go to HEADER, which is a regular expression."
  1552. (re-search-forward (concat "^\\(" header "\\):") nil t))
  1553. (defsubst gnus-article-hide-text (b e props)
  1554. "Set text PROPS on the B to E region, extending `intangible' 1 past B."
  1555. (gnus-add-text-properties-when 'article-type nil b e props)
  1556. (when (memq 'intangible props)
  1557. (put-text-property
  1558. (max (1- b) (point-min))
  1559. b 'intangible (cddr (memq 'intangible props)))))
  1560. (defsubst gnus-article-unhide-text (b e)
  1561. "Remove hidden text properties from region between B and E."
  1562. (remove-text-properties b e gnus-hidden-properties)
  1563. (when (memq 'intangible gnus-hidden-properties)
  1564. (put-text-property (max (1- b) (point-min))
  1565. b 'intangible nil)))
  1566. (defun gnus-article-hide-text-type (b e type)
  1567. "Hide text of TYPE between B and E."
  1568. (gnus-add-wash-type type)
  1569. (gnus-article-hide-text
  1570. b e (cons 'article-type (cons type gnus-hidden-properties))))
  1571. (defun gnus-article-unhide-text-type (b e type)
  1572. "Unhide text of TYPE between B and E."
  1573. (gnus-delete-wash-type type)
  1574. (remove-text-properties
  1575. b e (cons 'article-type (cons type gnus-hidden-properties)))
  1576. (when (memq 'intangible gnus-hidden-properties)
  1577. (put-text-property (max (1- b) (point-min))
  1578. b 'intangible nil)))
  1579. (defun gnus-article-hide-text-of-type (type)
  1580. "Hide text of TYPE in the current buffer."
  1581. (save-excursion
  1582. (let ((b (point-min))
  1583. (e (point-max)))
  1584. (while (setq b (text-property-any b e 'article-type type))
  1585. (add-text-properties b (incf b) gnus-hidden-properties)))))
  1586. (defun gnus-article-delete-text-of-type (type)
  1587. "Delete text of TYPE in the current buffer."
  1588. (save-excursion
  1589. (let ((b (point-min)))
  1590. (if (eq type 'multipart)
  1591. ;; Remove MIME buttons associated with multipart/alternative parts.
  1592. (progn
  1593. (goto-char b)
  1594. (while (if (get-text-property (point) 'gnus-part)
  1595. (setq b (point))
  1596. (when (setq b (next-single-property-change (point)
  1597. 'gnus-part))
  1598. (goto-char b)
  1599. t))
  1600. (end-of-line)
  1601. (skip-chars-forward "\n")
  1602. (when (eq (get-text-property b 'article-type) 'multipart)
  1603. (delete-region b (point)))))
  1604. (while (setq b (text-property-any b (point-max) 'article-type type))
  1605. (delete-region
  1606. b (or (text-property-not-all b (point-max) 'article-type type)
  1607. (point-max))))))))
  1608. (defun gnus-article-delete-invisible-text ()
  1609. "Delete all invisible text in the current buffer."
  1610. (save-excursion
  1611. (let ((b (point-min)))
  1612. (while (setq b (text-property-any b (point-max) 'invisible t))
  1613. (delete-region
  1614. b (or (text-property-not-all b (point-max) 'invisible t)
  1615. (point-max)))))))
  1616. (defun gnus-article-text-type-exists-p (type)
  1617. "Say whether any text of type TYPE exists in the buffer."
  1618. (text-property-any (point-min) (point-max) 'article-type type))
  1619. (defsubst gnus-article-header-rank ()
  1620. "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
  1621. (let ((list gnus-sorted-header-list)
  1622. (i 1))
  1623. (while list
  1624. (if (looking-at (car list))
  1625. (setq list nil)
  1626. (setq list (cdr list))
  1627. (incf i)))
  1628. i))
  1629. (defun article-hide-headers (&optional arg delete)
  1630. "Hide unwanted headers and possibly sort them as well."
  1631. (interactive)
  1632. ;; This function might be inhibited.
  1633. (unless gnus-inhibit-hiding
  1634. (let ((inhibit-read-only t)
  1635. (case-fold-search t)
  1636. (max (1+ (length gnus-sorted-header-list)))
  1637. (inhibit-point-motion-hooks t)
  1638. (cur (current-buffer))
  1639. ignored visible beg)
  1640. (save-excursion
  1641. ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
  1642. ;; group parameters, so we should go to the summary buffer.
  1643. (when (prog1
  1644. (condition-case nil
  1645. (progn (set-buffer gnus-summary-buffer) t)
  1646. (error nil))
  1647. (setq ignored (when (not gnus-visible-headers)
  1648. (cond ((stringp gnus-ignored-headers)
  1649. gnus-ignored-headers)
  1650. ((listp gnus-ignored-headers)
  1651. (mapconcat 'identity
  1652. gnus-ignored-headers
  1653. "\\|"))))
  1654. visible (cond ((stringp gnus-visible-headers)
  1655. gnus-visible-headers)
  1656. ((and gnus-visible-headers
  1657. (listp gnus-visible-headers))
  1658. (mapconcat 'identity
  1659. gnus-visible-headers
  1660. "\\|")))))
  1661. (set-buffer cur))
  1662. (save-restriction
  1663. ;; First we narrow to just the headers.
  1664. (article-narrow-to-head)
  1665. ;; Hide any "From " lines at the beginning of (mail) articles.
  1666. (while (looking-at "From ")
  1667. (forward-line 1))
  1668. (unless (bobp)
  1669. (delete-region (point-min) (point)))
  1670. ;; Then treat the rest of the header lines.
  1671. ;; Then we use the two regular expressions
  1672. ;; `gnus-ignored-headers' and `gnus-visible-headers' to
  1673. ;; select which header lines is to remain visible in the
  1674. ;; article buffer.
  1675. (while (re-search-forward "^[^ \t:]*:" nil t)
  1676. (beginning-of-line)
  1677. ;; Mark the rank of the header.
  1678. (put-text-property
  1679. (point) (1+ (point)) 'message-rank
  1680. (if (or (and visible (looking-at visible))
  1681. (and ignored
  1682. (not (looking-at ignored))))
  1683. (gnus-article-header-rank)
  1684. (+ 2 max)))
  1685. (forward-line 1))
  1686. (message-sort-headers-1)
  1687. (when (setq beg (text-property-any
  1688. (point-min) (point-max) 'message-rank (+ 2 max)))
  1689. ;; We delete the unwanted headers.
  1690. (gnus-add-wash-type 'headers)
  1691. (add-text-properties (point-min) (+ 5 (point-min))
  1692. '(article-type headers dummy-invisible t))
  1693. (delete-region beg (point-max))))))))
  1694. (defun article-hide-boring-headers (&optional arg)
  1695. "Toggle hiding of headers that aren't very interesting.
  1696. If given a negative prefix, always show; if given a positive prefix,
  1697. always hide."
  1698. (interactive (gnus-article-hidden-arg))
  1699. (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
  1700. (not gnus-show-all-headers))
  1701. (save-excursion
  1702. (save-restriction
  1703. (let ((inhibit-read-only t)
  1704. (inhibit-point-motion-hooks t))
  1705. (article-narrow-to-head)
  1706. (dolist (elem gnus-boring-article-headers)
  1707. (goto-char (point-min))
  1708. (cond
  1709. ;; Hide empty headers.
  1710. ((eq elem 'empty)
  1711. (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
  1712. (forward-line -1)
  1713. (gnus-article-hide-text-type
  1714. (point-at-bol)
  1715. (progn
  1716. (end-of-line)
  1717. (if (re-search-forward "^[^ \t]" nil t)
  1718. (match-beginning 0)
  1719. (point-max)))
  1720. 'boring-headers)))
  1721. ;; Hide boring Newsgroups header.
  1722. ((eq elem 'newsgroups)
  1723. (when (gnus-string-equal
  1724. (gnus-fetch-field "newsgroups")
  1725. (gnus-group-real-name
  1726. (if (boundp 'gnus-newsgroup-name)
  1727. gnus-newsgroup-name
  1728. "")))
  1729. (gnus-article-hide-header "newsgroups")))
  1730. ((eq elem 'to-address)
  1731. (let ((to (message-fetch-field "to"))
  1732. (to-address
  1733. (gnus-parameter-to-address
  1734. (if (boundp 'gnus-newsgroup-name)
  1735. gnus-newsgroup-name ""))))
  1736. (when (and to to-address
  1737. (ignore-errors
  1738. (gnus-string-equal
  1739. ;; only one address in To
  1740. (nth 1 (mail-extract-address-components to))
  1741. to-address)))
  1742. (gnus-article-hide-header "to"))))
  1743. ((eq elem 'to-list)
  1744. (let ((to (message-fetch-field "to"))
  1745. (to-list
  1746. (gnus-parameter-to-list
  1747. (if (boundp 'gnus-newsgroup-name)
  1748. gnus-newsgroup-name ""))))
  1749. (when (and to to-list
  1750. (ignore-errors
  1751. (gnus-string-equal
  1752. ;; only one address in To
  1753. (nth 1 (mail-extract-address-components to))
  1754. to-list)))
  1755. (gnus-article-hide-header "to"))))
  1756. ((eq elem 'cc-list)
  1757. (let ((cc (message-fetch-field "cc"))
  1758. (to-list
  1759. (gnus-parameter-to-list
  1760. (if (boundp 'gnus-newsgroup-name)
  1761. gnus-newsgroup-name ""))))
  1762. (when (and cc to-list
  1763. (ignore-errors
  1764. (gnus-string-equal
  1765. ;; only one address in CC
  1766. (nth 1 (mail-extract-address-components cc))
  1767. to-list)))
  1768. (gnus-article-hide-header "cc"))))
  1769. ((eq elem 'followup-to)
  1770. (when (gnus-string-equal
  1771. (message-fetch-field "followup-to")
  1772. (message-fetch-field "newsgroups"))
  1773. (gnus-article-hide-header "followup-to")))
  1774. ((eq elem 'reply-to)
  1775. (if (gnus-group-find-parameter
  1776. gnus-newsgroup-name 'broken-reply-to)
  1777. (gnus-article-hide-header "reply-to")
  1778. (let ((from (message-fetch-field "from"))
  1779. (reply-to (message-fetch-field "reply-to")))
  1780. (when
  1781. (and
  1782. from reply-to
  1783. (ignore-errors
  1784. (equal
  1785. (sort (mapcar
  1786. (lambda (x) (downcase (cadr x)))
  1787. (mail-extract-address-components from t))
  1788. 'string<)
  1789. (sort (mapcar
  1790. (lambda (x) (downcase (cadr x)))
  1791. (mail-extract-address-components reply-to t))
  1792. 'string<))))
  1793. (gnus-article-hide-header "reply-to")))))
  1794. ((eq elem 'date)
  1795. (let ((date (with-current-buffer gnus-original-article-buffer
  1796. ;; If date in `gnus-article-buffer' is localized
  1797. ;; (`gnus-treat-date-user-defined'),
  1798. ;; `days-between' might fail.
  1799. (message-fetch-field "date"))))
  1800. (when (and date
  1801. (< (days-between (current-time-string) date)
  1802. 4))
  1803. (gnus-article-hide-header "date"))))
  1804. ((eq elem 'long-to)
  1805. (let ((to (message-fetch-field "to"))
  1806. (cc (message-fetch-field "cc")))
  1807. (when (> (length to) 1024)
  1808. (gnus-article-hide-header "to"))
  1809. (when (> (length cc) 1024)
  1810. (gnus-article-hide-header "cc"))))
  1811. ((eq elem 'many-to)
  1812. (let ((to-count 0)
  1813. (cc-count 0))
  1814. (goto-char (point-min))
  1815. (while (re-search-forward "^to:" nil t)
  1816. (setq to-count (1+ to-count)))
  1817. (when (> to-count 1)
  1818. (while (> to-count 0)
  1819. (goto-char (point-min))
  1820. (save-restriction
  1821. (re-search-forward "^to:" nil nil to-count)
  1822. (forward-line -1)
  1823. (narrow-to-region (point) (point-max))
  1824. (gnus-article-hide-header "to"))
  1825. (setq to-count (1- to-count))))
  1826. (goto-char (point-min))
  1827. (while (re-search-forward "^cc:" nil t)
  1828. (setq cc-count (1+ cc-count)))
  1829. (when (> cc-count 1)
  1830. (while (> cc-count 0)
  1831. (goto-char (point-min))
  1832. (save-restriction
  1833. (re-search-forward "^cc:" nil nil cc-count)
  1834. (forward-line -1)
  1835. (narrow-to-region (point) (point-max))
  1836. (gnus-article-hide-header "cc"))
  1837. (setq cc-count (1- cc-count)))))))))))))
  1838. (defun gnus-article-hide-header (header)
  1839. (save-excursion
  1840. (goto-char (point-min))
  1841. (when (re-search-forward (concat "^" header ":") nil t)
  1842. (gnus-article-hide-text-type
  1843. (point-at-bol)
  1844. (progn
  1845. (end-of-line)
  1846. (if (re-search-forward "^[^ \t]" nil t)
  1847. (match-beginning 0)
  1848. (point-max)))
  1849. 'boring-headers))))
  1850. (defvar gnus-article-normalized-header-length 40
  1851. "Length of normalized headers.")
  1852. (defun article-normalize-headers ()
  1853. "Make all header lines 40 characters long."
  1854. (interactive)
  1855. (let ((inhibit-read-only t)
  1856. column)
  1857. (save-excursion
  1858. (save-restriction
  1859. (article-narrow-to-head)
  1860. (while (not (eobp))
  1861. (cond
  1862. ((< (setq column (- (point-at-eol) (point)))
  1863. gnus-article-normalized-header-length)
  1864. (end-of-line)
  1865. (insert (make-string
  1866. (- gnus-article-normalized-header-length column)
  1867. ? )))
  1868. ((> column gnus-article-normalized-header-length)
  1869. (gnus-put-text-property
  1870. (progn
  1871. (forward-char gnus-article-normalized-header-length)
  1872. (point))
  1873. (point-at-eol)
  1874. 'invisible t))
  1875. (t
  1876. ;; Do nothing.
  1877. ))
  1878. (forward-line 1))))))
  1879. (defun article-treat-dumbquotes ()
  1880. "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
  1881. Note that this function guesses whether a character is a sm*rtq**t* or
  1882. not, so it should only be used interactively.
  1883. Sm*rtq**t*s are M****s***'s unilateral extension to the
  1884. iso-8859-1 character map in an attempt to provide more quoting
  1885. characters. If you see something like \\222 or \\264 where
  1886. you're expecting some kind of apostrophe or quotation mark, then
  1887. try this wash."
  1888. (interactive)
  1889. (article-translate-strings gnus-article-dumbquotes-map))
  1890. (defvar org-entities)
  1891. (defun article-treat-non-ascii ()
  1892. "Translate many Unicode characters into their ASCII equivalents."
  1893. (interactive)
  1894. (require 'org-entities)
  1895. (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
  1896. (dolist (elem org-entities)
  1897. (when (and (listp elem)
  1898. (= (length (nth 6 elem)) 1))
  1899. (if (featurep 'xemacs)
  1900. (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
  1901. (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
  1902. (save-excursion
  1903. (when (article-goto-body)
  1904. (let ((inhibit-read-only t)
  1905. replace props)
  1906. (while (not (eobp))
  1907. (if (not (setq replace (if (featurep 'xemacs)
  1908. (get-char-table (following-char) table)
  1909. (aref table (following-char)))))
  1910. (forward-char 1)
  1911. (if (prog1
  1912. (setq props (text-properties-at (point)))
  1913. (delete-char 1))
  1914. (add-text-properties (point) (progn (insert replace) (point))
  1915. props)
  1916. (insert replace)))))))))
  1917. (defun article-translate-characters (from to)
  1918. "Translate all characters in the body of the article according to FROM and TO.
  1919. FROM is a string of characters to translate from; to is a string of
  1920. characters to translate to."
  1921. (save-excursion
  1922. (when (article-goto-body)
  1923. (let ((inhibit-read-only t)
  1924. (x (make-string 225 ?x))
  1925. (i -1))
  1926. (while (< (incf i) (length x))
  1927. (aset x i i))
  1928. (setq i 0)
  1929. (while (< i (length from))
  1930. (aset x (aref from i) (aref to i))
  1931. (incf i))
  1932. (translate-region (point) (point-max) x)))))
  1933. (defun article-translate-strings (map)
  1934. "Translate all string in the body of the article according to MAP.
  1935. MAP is an alist where the elements are on the form (\"from\" \"to\")."
  1936. (save-excursion
  1937. (when (article-goto-body)
  1938. (let ((inhibit-read-only t))
  1939. (dolist (elem map)
  1940. (let ((from (car elem))
  1941. (to (cadr elem)))
  1942. (save-excursion
  1943. (if (stringp from)
  1944. (while (search-forward from nil t)
  1945. (replace-match to))
  1946. (while (not (eobp))
  1947. (if (eq (following-char) from)
  1948. (progn
  1949. (delete-char 1)
  1950. (insert to))
  1951. (forward-char 1)))))))))))
  1952. (defun article-treat-overstrike ()
  1953. "Translate overstrikes into bold text."
  1954. (interactive)
  1955. (save-excursion
  1956. (when (article-goto-body)
  1957. (let ((inhibit-read-only t))
  1958. (while (search-forward "\b" nil t)
  1959. (let ((next (char-after))
  1960. (previous (char-after (- (point) 2))))
  1961. ;; We do the boldification/underlining by hiding the
  1962. ;; overstrikes and putting the proper text property
  1963. ;; on the letters.
  1964. (cond
  1965. ((eq next previous)
  1966. (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
  1967. (put-text-property (point) (1+ (point)) 'face 'bold))
  1968. ((eq next ?_)
  1969. (gnus-article-hide-text-type
  1970. (1- (point)) (1+ (point)) 'overstrike)
  1971. (put-text-property
  1972. (- (point) 2) (1- (point)) 'face 'underline))
  1973. ((eq previous ?_)
  1974. (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
  1975. (put-text-property
  1976. (point) (1+ (point)) 'face 'underline)))))))))
  1977. (defun article-treat-ansi-sequences ()
  1978. "Translate ANSI SGR control sequences into overlays or extents."
  1979. (interactive)
  1980. (save-excursion
  1981. (when (article-goto-body)
  1982. (let ((inhibit-read-only t))
  1983. (ansi-color-apply-on-region (point) (point-max))))))
  1984. (defun gnus-article-treat-unfold-headers ()
  1985. "Unfold folded message headers.
  1986. Only the headers that fit into the current window width will be
  1987. unfolded."
  1988. (interactive)
  1989. (gnus-with-article-headers
  1990. (let (length)
  1991. (while (not (eobp))
  1992. (save-restriction
  1993. (mail-header-narrow-to-field)
  1994. (let* ((header (buffer-string))
  1995. (unfoldable
  1996. (or (equal gnus-article-unfold-long-headers t)
  1997. (and (stringp gnus-article-unfold-long-headers)
  1998. (string-match gnus-article-unfold-long-headers header)))))
  1999. (with-temp-buffer
  2000. (insert header)
  2001. (goto-char (point-min))
  2002. (while (re-search-forward "\n[\t ]" nil t)
  2003. (replace-match " " t t)))
  2004. (setq length (- (point-max) (point-min) 1))
  2005. (when (or unfoldable
  2006. (< length (window-width)))
  2007. (while (re-search-forward "\n[\t ]" nil t)
  2008. (replace-match " " t t))))
  2009. (goto-char (point-max)))))))
  2010. (defun gnus-article-treat-fold-headers ()
  2011. "Fold message headers."
  2012. (interactive)
  2013. (gnus-with-article-headers
  2014. (while (not (eobp))
  2015. (save-restriction
  2016. (mail-header-narrow-to-field)
  2017. (mail-header-fold-field)
  2018. (goto-char (point-max))))))
  2019. (defun gnus-treat-smiley ()
  2020. "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
  2021. (interactive)
  2022. (gnus-with-article-buffer
  2023. (if (memq 'smiley gnus-article-wash-types)
  2024. (gnus-delete-images 'smiley)
  2025. (article-goto-body)
  2026. (let ((images (smiley-region (point) (point-max))))
  2027. (when images
  2028. (gnus-add-wash-type 'smiley)
  2029. (dolist (image images)
  2030. (gnus-add-image 'smiley image)))))))
  2031. (defun gnus-article-remove-images ()
  2032. "Remove all images from the article buffer."
  2033. (interactive)
  2034. (gnus-with-article-buffer
  2035. (save-restriction
  2036. (widen)
  2037. (dolist (elem gnus-article-image-alist)
  2038. (gnus-delete-images (car elem))))))
  2039. (autoload 'w3m-toggle-inline-images "w3m")
  2040. (defun gnus-article-show-images ()
  2041. "Show any images that are in the HTML-rendered article buffer.
  2042. This only works if the article in question is HTML."
  2043. (interactive)
  2044. (gnus-with-article-buffer
  2045. (save-restriction
  2046. (widen)
  2047. (if (eq mm-text-html-renderer 'w3m)
  2048. (let ((mm-inline-text-html-with-images nil))
  2049. (w3m-toggle-inline-images))
  2050. (dolist (region (gnus-find-text-property-region (point-min) (point-max)
  2051. 'image-displayer))
  2052. (destructuring-bind (start end function) region
  2053. (funcall function (get-text-property start 'image-url)
  2054. start end)))))))
  2055. (defun gnus-article-treat-fold-newsgroups ()
  2056. "Unfold folded message headers.
  2057. Only the headers that fit into the current window width will be
  2058. unfolded."
  2059. (interactive)
  2060. (gnus-with-article-headers
  2061. (while (gnus-article-goto-header "newsgroups\\|followup-to")
  2062. (save-restriction
  2063. (mail-header-narrow-to-field)
  2064. (while (re-search-forward ", *" nil t)
  2065. (replace-match ", " t t))
  2066. (mail-header-fold-field)
  2067. (goto-char (point-max))))))
  2068. (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
  2069. "Value of `truncate-lines' in Gnus Article buffer.
  2070. Valid values are nil, t, `head', `first', `last', an integer or a
  2071. predicate. See Info node `(gnus)Customizing Articles'."
  2072. :version "23.1" ;; No Gnus
  2073. :group 'gnus-article
  2074. ;; :link '(custom-manual "(gnus)Customizing Articles")
  2075. :type 'boolean)
  2076. (defun gnus-article-toggle-truncate-lines (&optional arg)
  2077. "Toggle whether to fold or truncate long lines in article the buffer.
  2078. If ARG is non-nil and not a number, toggle
  2079. `gnus-article-truncate-lines' too. If ARG is a number, truncate
  2080. long lines if and only if arg is positive."
  2081. (interactive "P")
  2082. (cond
  2083. ((and (numberp arg) (> arg 0))
  2084. (setq gnus-article-truncate-lines t))
  2085. ((numberp arg)
  2086. (setq gnus-article-truncate-lines nil))
  2087. (arg
  2088. (setq gnus-article-truncate-lines
  2089. (not gnus-article-truncate-lines))))
  2090. (gnus-with-article-buffer
  2091. (cond
  2092. ((and (numberp arg) (> arg 0))
  2093. (setq truncate-lines nil))
  2094. ((numberp arg)
  2095. (setq truncate-lines t)))
  2096. ;; In versions of Emacs 22 (CVS) before 2006-05-26,
  2097. ;; `toggle-truncate-lines' needs an argument.
  2098. (toggle-truncate-lines)))
  2099. (defun gnus-article-treat-body-boundary ()
  2100. "Place a boundary line at the end of the headers."
  2101. (interactive)
  2102. (when (and gnus-body-boundary-delimiter
  2103. (> (length gnus-body-boundary-delimiter) 0))
  2104. (gnus-with-article-headers
  2105. (goto-char (point-max))
  2106. (let ((start (point)))
  2107. (insert "X-Boundary: ")
  2108. (gnus-add-text-properties start (point) '(invisible t intangible t))
  2109. (insert (let (str (max (window-width)))
  2110. (if (featurep 'xemacs)
  2111. (setq max (1- max)))
  2112. (while (>= max (length str))
  2113. (setq str (concat str gnus-body-boundary-delimiter)))
  2114. (substring str 0 max))
  2115. "\n")
  2116. (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
  2117. (defun article-fill-long-lines ()
  2118. "Fill lines that are wider than the window width."
  2119. (interactive)
  2120. (save-excursion
  2121. (let ((inhibit-read-only t)
  2122. (width (window-width (get-buffer-window (current-buffer)))))
  2123. (save-restriction
  2124. (article-goto-body)
  2125. (let ((adaptive-fill-mode nil)) ;Why? -sm
  2126. (while (not (eobp))
  2127. (end-of-line)
  2128. (when (>= (current-column) (min fill-column width))
  2129. (narrow-to-region (min (1+ (point)) (point-max))
  2130. (point-at-bol))
  2131. (let ((goback (point-marker)))
  2132. (fill-paragraph nil)
  2133. (goto-char (marker-position goback)))
  2134. (widen))
  2135. (forward-line 1)))))))
  2136. (defun article-capitalize-sentences ()
  2137. "Capitalize the first word in each sentence."
  2138. (interactive)
  2139. (save-excursion
  2140. (let ((inhibit-read-only t)
  2141. (paragraph-start "^[\n\^L]"))
  2142. (article-goto-body)
  2143. (while (not (eobp))
  2144. (capitalize-word 1)
  2145. (forward-sentence)))))
  2146. (defun article-remove-cr ()
  2147. "Remove trailing CRs and then translate remaining CRs into LFs."
  2148. (interactive)
  2149. (save-excursion
  2150. (let ((inhibit-read-only t))
  2151. (goto-char (point-min))
  2152. (while (re-search-forward "\r+$" nil t)
  2153. (replace-match "" t t))
  2154. (goto-char (point-min))
  2155. (while (search-forward "\r" nil t)
  2156. (replace-match "\n" t t)))))
  2157. (defun article-remove-trailing-blank-lines ()
  2158. "Remove all trailing blank lines from the article."
  2159. (interactive)
  2160. (save-excursion
  2161. (let ((inhibit-read-only t))
  2162. (goto-char (point-max))
  2163. (delete-region
  2164. (point)
  2165. (progn
  2166. (while (and (not (bobp))
  2167. (looking-at "^[ \t]*$")
  2168. (not (gnus-annotation-in-region-p
  2169. (point) (point-at-eol))))
  2170. (forward-line -1))
  2171. (forward-line 1)
  2172. (point))))))
  2173. (defvar gnus-face-properties-alist)
  2174. (defun article-display-face (&optional force)
  2175. "Display any Face headers in the header."
  2176. (interactive (list 'force))
  2177. (let ((wash-face-p buffer-read-only))
  2178. (gnus-with-article-headers
  2179. ;; When displaying parts, this function can be called several times on
  2180. ;; the same article, without any intended toggle semantic (as typing `W
  2181. ;; D d' would have). So face deletion must occur only when we come from
  2182. ;; an interactive command, that is when the *Article* buffer is
  2183. ;; read-only.
  2184. (if (and wash-face-p (memq 'face gnus-article-wash-types))
  2185. (gnus-delete-images 'face)
  2186. (let ((from (message-fetch-field "from"))
  2187. face faces)
  2188. (save-current-buffer
  2189. (when (and wash-face-p
  2190. (gnus-buffer-live-p gnus-original-article-buffer)
  2191. (not (re-search-forward "^Face:[\t ]*" nil t)))
  2192. (set-buffer gnus-original-article-buffer))
  2193. (save-restriction
  2194. (mail-narrow-to-head)
  2195. (when (or force
  2196. ;; Check whether this face is censored.
  2197. (not (and gnus-article-x-face-too-ugly
  2198. (or from
  2199. (setq from (message-fetch-field "from")))
  2200. (string-match gnus-article-x-face-too-ugly
  2201. from))))
  2202. (while (gnus-article-goto-header "Face")
  2203. (push (mail-header-field-value) faces)))))
  2204. (when faces
  2205. (goto-char (point-min))
  2206. (let (png image)
  2207. (unless (setq from (gnus-article-goto-header "from"))
  2208. (insert "From:")
  2209. (setq from (point))
  2210. (insert " [no `from' set]\n"))
  2211. (while faces
  2212. (when (setq png (gnus-convert-face-to-png (pop faces)))
  2213. (setq image
  2214. (apply 'gnus-create-image png 'png t
  2215. (cdr (assq 'png gnus-face-properties-alist))))
  2216. (goto-char from)
  2217. (gnus-add-wash-type 'face)
  2218. (gnus-add-image 'face image)
  2219. (gnus-put-image image nil 'face))))))))))
  2220. (defun article-display-x-face (&optional force)
  2221. "Look for an X-Face header and display it if present."
  2222. (interactive (list 'force))
  2223. (let ((wash-face-p buffer-read-only)) ;; When type `W f'
  2224. (gnus-with-article-headers
  2225. ;; Delete the old process, if any.
  2226. (when (process-status "article-x-face")
  2227. (delete-process "article-x-face"))
  2228. ;; See the comment in `article-display-face'.
  2229. (if (and wash-face-p (memq 'xface gnus-article-wash-types))
  2230. ;; We have already displayed X-Faces, so we remove them
  2231. ;; instead.
  2232. (gnus-delete-images 'xface)
  2233. ;; Display X-Faces.
  2234. (let ((from (message-fetch-field "from"))
  2235. x-faces face)
  2236. (save-current-buffer
  2237. (when (and wash-face-p
  2238. (gnus-buffer-live-p gnus-original-article-buffer)
  2239. (not (re-search-forward "^X-Face:[\t ]*" nil t)))
  2240. ;; If type `W f', use gnus-original-article-buffer,
  2241. ;; otherwise use the current buffer because displaying
  2242. ;; RFC822 parts calls this function too.
  2243. (set-buffer gnus-original-article-buffer))
  2244. (save-restriction
  2245. (mail-narrow-to-head)
  2246. (and gnus-article-x-face-command
  2247. (or force
  2248. ;; Check whether this face is censored.
  2249. (not (and gnus-article-x-face-too-ugly
  2250. (or from
  2251. (setq from (message-fetch-field "from")))
  2252. (string-match gnus-article-x-face-too-ugly
  2253. from))))
  2254. (while (gnus-article-goto-header "X-Face")
  2255. (push (mail-header-field-value) x-faces)))))
  2256. (when x-faces
  2257. ;; We display the face.
  2258. (cond ((functionp gnus-article-x-face-command)
  2259. ;; The command is a lisp function, so we call it.
  2260. (mapc gnus-article-x-face-command x-faces))
  2261. ((stringp gnus-article-x-face-command)
  2262. ;; The command is a string, so we interpret the command
  2263. ;; as a, well, command, and fork it off.
  2264. (let ((process-connection-type nil))
  2265. (gnus-set-process-query-on-exit-flag
  2266. (start-process
  2267. "article-x-face" nil shell-file-name
  2268. shell-command-switch gnus-article-x-face-command)
  2269. nil)
  2270. ;; Sending multiple EOFs to xv doesn't work,
  2271. ;; so we only do a single external face.
  2272. (with-temp-buffer
  2273. (insert (car x-faces))
  2274. (process-send-region "article-x-face"
  2275. (point-min) (point-max)))
  2276. (process-send-eof "article-x-face")))
  2277. (t
  2278. (error "`%s' set to `%s' is not a function"
  2279. gnus-article-x-face-command
  2280. 'gnus-article-x-face-command)))))))))
  2281. (defun article-decode-mime-words ()
  2282. "Decode all MIME-encoded words in the article."
  2283. (interactive)
  2284. (gnus-with-article-buffer
  2285. (let ((inhibit-point-motion-hooks t)
  2286. (mail-parse-charset gnus-newsgroup-charset)
  2287. (mail-parse-ignored-charsets
  2288. (with-current-buffer gnus-summary-buffer
  2289. gnus-newsgroup-ignored-charsets)))
  2290. (mail-decode-encoded-word-region (point-min) (point-max)))))
  2291. (defun article-decode-charset (&optional prompt)
  2292. "Decode charset-encoded text in the article.
  2293. If PROMPT (the prefix), prompt for a coding system to use."
  2294. (interactive "P")
  2295. (let ((inhibit-point-motion-hooks t) (case-fold-search t)
  2296. (inhibit-read-only t)
  2297. (mail-parse-charset gnus-newsgroup-charset)
  2298. (mail-parse-ignored-charsets
  2299. (save-excursion (condition-case nil
  2300. (set-buffer gnus-summary-buffer)
  2301. (error))
  2302. gnus-newsgroup-ignored-charsets))
  2303. ct cte ctl charset format)
  2304. (save-excursion
  2305. (save-restriction
  2306. (article-narrow-to-head)
  2307. (setq ct (message-fetch-field "Content-Type" t)
  2308. cte (message-fetch-field "Content-Transfer-Encoding" t)
  2309. ctl (and ct (mail-header-parse-content-type ct))
  2310. charset (cond
  2311. (prompt
  2312. (mm-read-coding-system "Charset to decode: "))
  2313. (ctl
  2314. (mail-content-type-get ctl 'charset)))
  2315. format (and ctl (mail-content-type-get ctl 'format)))
  2316. (when cte
  2317. (setq cte (mail-header-strip cte)))
  2318. (if (and ctl (not (string-match "/" (car ctl))))
  2319. (setq ctl nil))
  2320. (goto-char (point-max)))
  2321. (forward-line 1)
  2322. (save-restriction
  2323. (narrow-to-region (point) (point-max))
  2324. (when (and (eq mail-parse-charset 'gnus-decoded)
  2325. (eq (mm-body-7-or-8) '8bit))
  2326. ;; The text code could have been decoded.
  2327. (setq charset mail-parse-charset))
  2328. (when (and (or (not ctl)
  2329. (equal (car ctl) "text/plain"))
  2330. (not format)) ;; article with format will decode later.
  2331. (mm-decode-body
  2332. charset (and cte (intern (downcase
  2333. (gnus-strip-whitespace cte))))
  2334. (car ctl)))))))
  2335. (defun article-decode-encoded-words ()
  2336. "Remove encoded-word encoding from headers."
  2337. (let ((inhibit-point-motion-hooks t)
  2338. (mail-parse-charset gnus-newsgroup-charset)
  2339. (mail-parse-ignored-charsets
  2340. (save-excursion (condition-case nil
  2341. (set-buffer gnus-summary-buffer)
  2342. (error))
  2343. gnus-newsgroup-ignored-charsets))
  2344. (inhibit-read-only t)
  2345. end start)
  2346. (goto-char (point-min))
  2347. (when (search-forward "\n\n" nil 'move)
  2348. (forward-line -1))
  2349. (setq end (point))
  2350. (while (not (bobp))
  2351. (while (progn
  2352. (forward-line -1)
  2353. (and (not (bobp))
  2354. (memq (char-after) '(?\t ? )))))
  2355. (setq start (point))
  2356. (if (looking-at "\
  2357. \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
  2358. \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
  2359. (funcall gnus-decode-address-function start end)
  2360. (funcall gnus-decode-header-function start end))
  2361. (goto-char (setq end start)))))
  2362. (defun article-decode-group-name ()
  2363. "Decode group names in Newsgroups, Followup-To and Xref headers."
  2364. (let ((inhibit-point-motion-hooks t)
  2365. (inhibit-read-only t)
  2366. (method (gnus-find-method-for-group gnus-newsgroup-name))
  2367. regexp)
  2368. (when (and (or gnus-group-name-charset-method-alist
  2369. gnus-group-name-charset-group-alist)
  2370. (gnus-buffer-live-p gnus-original-article-buffer))
  2371. (save-restriction
  2372. (article-narrow-to-head)
  2373. (dolist (header '("Newsgroups" "Followup-To" "Xref"))
  2374. (with-current-buffer gnus-original-article-buffer
  2375. (goto-char (point-min)))
  2376. (setq regexp (concat "^" header
  2377. ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
  2378. (while (re-search-forward regexp nil t)
  2379. (replace-match (save-match-data
  2380. (gnus-decode-newsgroups
  2381. ;; XXX how to use data in article buffer?
  2382. (with-current-buffer gnus-original-article-buffer
  2383. (re-search-forward regexp nil t)
  2384. (match-string 1))
  2385. gnus-newsgroup-name method))
  2386. t t nil 1))
  2387. (goto-char (point-min)))))))
  2388. (autoload 'idna-to-unicode "idna")
  2389. (defun article-decode-idna-rhs ()
  2390. "Decode IDNA strings in RHS in various headers in current buffer.
  2391. The following headers are decoded: From:, To:, Cc:, Reply-To:,
  2392. Mail-Reply-To: and Mail-Followup-To:."
  2393. (when gnus-use-idna
  2394. (save-restriction
  2395. (let ((inhibit-point-motion-hooks t)
  2396. (inhibit-read-only t))
  2397. (article-narrow-to-head)
  2398. (goto-char (point-min))
  2399. (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
  2400. (let (ace unicode)
  2401. (when (save-match-data
  2402. (and (setq ace (match-string 1))
  2403. (save-excursion
  2404. (and (re-search-backward "^[^ \t]" nil t)
  2405. (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
  2406. (setq unicode (idna-to-unicode ace))))
  2407. (unless (string= ace unicode)
  2408. (replace-match unicode nil nil nil 1)))))))))
  2409. (defun article-de-quoted-unreadable (&optional force read-charset)
  2410. "Translate a quoted-printable-encoded article.
  2411. If FORCE, decode the article whether it is marked as quoted-printable
  2412. or not.
  2413. If READ-CHARSET, ask for a coding system."
  2414. (interactive (list 'force current-prefix-arg))
  2415. (save-excursion
  2416. (let ((inhibit-read-only t) type charset)
  2417. (if (gnus-buffer-live-p gnus-original-article-buffer)
  2418. (with-current-buffer gnus-original-article-buffer
  2419. (setq type
  2420. (gnus-fetch-field "content-transfer-encoding"))
  2421. (let* ((ct (gnus-fetch-field "content-type"))
  2422. (ctl (and ct (mail-header-parse-content-type ct))))
  2423. (setq charset (and ctl
  2424. (mail-content-type-get ctl 'charset)))
  2425. (if (stringp charset)
  2426. (setq charset (intern (downcase charset)))))))
  2427. (if read-charset
  2428. (setq charset (mm-read-coding-system "Charset: " charset)))
  2429. (unless charset
  2430. (setq charset gnus-newsgroup-charset))
  2431. (when (or force
  2432. (and type (let ((case-fold-search t))
  2433. (string-match "quoted-printable" type))))
  2434. (article-goto-body)
  2435. (quoted-printable-decode-region
  2436. (point) (point-max) (mm-charset-to-coding-system charset))))))
  2437. (defun article-de-base64-unreadable (&optional force read-charset)
  2438. "Translate a base64 article.
  2439. If FORCE, decode the article whether it is marked as base64 not.
  2440. If READ-CHARSET, ask for a coding system."
  2441. (interactive (list 'force current-prefix-arg))
  2442. (save-excursion
  2443. (let ((inhibit-read-only t) type charset)
  2444. (if (gnus-buffer-live-p gnus-original-article-buffer)
  2445. (with-current-buffer gnus-original-article-buffer
  2446. (setq type
  2447. (gnus-fetch-field "content-transfer-encoding"))
  2448. (let* ((ct (gnus-fetch-field "content-type"))
  2449. (ctl (and ct (mail-header-parse-content-type ct))))
  2450. (setq charset (and ctl
  2451. (mail-content-type-get ctl 'charset)))
  2452. (if (stringp charset)
  2453. (setq charset (intern (downcase charset)))))))
  2454. (if read-charset
  2455. (setq charset (mm-read-coding-system "Charset: " charset)))
  2456. (unless charset
  2457. (setq charset gnus-newsgroup-charset))
  2458. (when (or force
  2459. (and type (let ((case-fold-search t))
  2460. (string-match "base64" type))))
  2461. (article-goto-body)
  2462. (save-restriction
  2463. (narrow-to-region (point) (point-max))
  2464. (base64-decode-region (point-min) (point-max))
  2465. (mm-decode-coding-region
  2466. (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
  2467. (eval-when-compile
  2468. (require 'rfc1843))
  2469. (defun article-decode-HZ ()
  2470. "Translate a HZ-encoded article."
  2471. (interactive)
  2472. (require 'rfc1843)
  2473. (save-excursion
  2474. (let ((inhibit-read-only t))
  2475. (rfc1843-decode-region (point-min) (point-max)))))
  2476. (defun article-unsplit-urls ()
  2477. "Remove the newlines that some other mailers insert into URLs."
  2478. (interactive)
  2479. (save-excursion
  2480. (let ((inhibit-read-only t))
  2481. (goto-char (point-min))
  2482. (while (re-search-forward
  2483. "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
  2484. (replace-match "\\1\\3" t)))
  2485. (when (interactive-p)
  2486. (gnus-treat-article nil))))
  2487. (defun article-wash-html ()
  2488. "Format an HTML article."
  2489. (interactive)
  2490. (let ((handles nil)
  2491. (buffer-read-only nil))
  2492. (when (gnus-buffer-live-p gnus-original-article-buffer)
  2493. (with-current-buffer gnus-original-article-buffer
  2494. (setq handles (mm-dissect-buffer t t))))
  2495. (article-goto-body)
  2496. (delete-region (point) (point-max))
  2497. (mm-enable-multibyte)
  2498. (mm-inline-text-html handles)))
  2499. (defvar gnus-article-browse-html-temp-list nil
  2500. "List of temporary files created by `gnus-article-browse-html-parts'.
  2501. Internal variable.")
  2502. (defcustom gnus-article-browse-delete-temp 'ask
  2503. "What to do with temporary files from `gnus-article-browse-html-parts'.
  2504. If nil, don't delete temporary files. If it is t, delete them on
  2505. exit from the summary buffer. If it is the symbol `file', query
  2506. on each file, if it is `ask' ask once when exiting from the
  2507. summary buffer."
  2508. :group 'gnus-article
  2509. :version "23.1" ;; No Gnus
  2510. :type '(choice (const :tag "Don't delete" nil)
  2511. (const :tag "Don't ask" t)
  2512. (const :tag "Ask" ask)
  2513. (const :tag "Ask for each file" file)))
  2514. ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
  2515. (defun gnus-article-browse-delete-temp-files (&optional how)
  2516. "Delete temp-files created by `gnus-article-browse-html-parts'."
  2517. (when (and gnus-article-browse-html-temp-list
  2518. (progn
  2519. (or how (setq how gnus-article-browse-delete-temp))
  2520. (if (eq how 'ask)
  2521. (let ((files (length gnus-article-browse-html-temp-list)))
  2522. (gnus-y-or-n-p
  2523. (if (= files 1)
  2524. "Delete the temporary HTML file? "
  2525. (format "Delete all %s temporary HTML files? "
  2526. files))))
  2527. how)))
  2528. (dolist (file gnus-article-browse-html-temp-list)
  2529. (cond ((file-directory-p file)
  2530. (when (or (not (eq how 'file))
  2531. (gnus-y-or-n-p
  2532. (format
  2533. "Delete temporary HTML file(s) in directory `%s'? "
  2534. (file-name-as-directory file))))
  2535. (gnus-delete-directory file)))
  2536. ((file-exists-p file)
  2537. (when (or (not (eq how 'file))
  2538. (gnus-y-or-n-p
  2539. (format "Delete temporary HTML file `%s'? " file)))
  2540. (delete-file file)))))
  2541. ;; Also remove file from the list when not deleted or if file doesn't
  2542. ;; exist anymore.
  2543. (setq gnus-article-browse-html-temp-list nil))
  2544. gnus-article-browse-html-temp-list)
  2545. (defun gnus-article-browse-html-save-cid-content (cid handles directory)
  2546. "Find CID content in HANDLES and save it in a file in DIRECTORY.
  2547. Return file name."
  2548. (save-match-data
  2549. (let (file type)
  2550. (catch 'found
  2551. (dolist (handle handles)
  2552. (cond
  2553. ((not (listp handle)))
  2554. ((equal (mm-handle-media-supertype handle) "multipart")
  2555. (when (setq file (gnus-article-browse-html-save-cid-content
  2556. cid handle directory))
  2557. (throw 'found file)))
  2558. ((equal (concat "<" cid ">") (mm-handle-id handle))
  2559. (setq file
  2560. (expand-file-name
  2561. (or (mm-handle-filename handle)
  2562. (concat
  2563. (make-temp-name "cid")
  2564. (car (rassoc (car (mm-handle-type handle)) mailcap-mime-extensions))))
  2565. directory))
  2566. (mm-save-part-to-file handle file)
  2567. (throw 'found file))))))))
  2568. (defun gnus-article-browse-html-parts (list &optional header)
  2569. "View all \"text/html\" parts from LIST.
  2570. Recurse into multiparts. The optional HEADER that should be a decoded
  2571. message header will be added to the bodies of the \"text/html\" parts."
  2572. ;; Internal function used by `gnus-article-browse-html-article'.
  2573. (let (type file charset content cid-dir tmp-file showed)
  2574. ;; Find and show the html-parts.
  2575. (dolist (handle list)
  2576. ;; If HTML, show it:
  2577. (cond ((not (listp handle)))
  2578. ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
  2579. (and (equal (car type) "message/external-body")
  2580. (or header
  2581. (setq file (mm-handle-filename handle)))
  2582. (or (mm-handle-cache handle)
  2583. (condition-case code
  2584. (progn (mm-extern-cache-contents handle) t)
  2585. (error
  2586. (gnus-message 3 "%s" (error-message-string code))
  2587. (when (>= gnus-verbose 3) (sit-for 2))
  2588. nil)))
  2589. (progn
  2590. (setq handle (mm-handle-cache handle)
  2591. type (mm-handle-type handle))
  2592. (equal (car type) "text/html"))))
  2593. (setq charset (mail-content-type-get type 'charset)
  2594. content (mm-get-part handle))
  2595. (with-temp-buffer
  2596. (if (eq charset 'gnus-decoded)
  2597. (mm-enable-multibyte)
  2598. (mm-disable-multibyte))
  2599. (insert content)
  2600. ;; resolve cid contents
  2601. (let ((case-fold-search t)
  2602. cid-file)
  2603. (goto-char (point-min))
  2604. (while (re-search-forward "\
  2605. <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
  2606. nil t)
  2607. (unless cid-dir
  2608. (setq cid-dir (mm-make-temp-file "cid" t))
  2609. (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
  2610. (setq file nil
  2611. content nil)
  2612. (when (setq cid-file
  2613. (gnus-article-browse-html-save-cid-content
  2614. (match-string 2)
  2615. (with-current-buffer gnus-article-buffer
  2616. gnus-article-mime-handles)
  2617. cid-dir))
  2618. (when (eq system-type 'cygwin)
  2619. (setq cid-file
  2620. (concat "/" (substring
  2621. (with-output-to-string
  2622. (call-process "cygpath" nil
  2623. standard-output
  2624. nil "-m" cid-file))
  2625. 0 -1))))
  2626. (replace-match (concat "file://" cid-file)
  2627. nil nil nil 1))))
  2628. (unless content (setq content (buffer-string))))
  2629. (when (or charset header (not file))
  2630. (setq tmp-file (mm-make-temp-file
  2631. ;; Do we need to care for 8.3 filenames?
  2632. "mm-" nil ".html")))
  2633. ;; Add a meta html tag to specify charset and a header.
  2634. (cond
  2635. (header
  2636. (let (title eheader body hcharset coding force-charset)
  2637. (with-temp-buffer
  2638. (mm-enable-multibyte)
  2639. (setq case-fold-search t)
  2640. (insert header "\n")
  2641. (setq title (message-fetch-field "subject"))
  2642. (goto-char (point-min))
  2643. (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
  2644. (replace-match (cond ((match-beginning 1) "&lt;")
  2645. ((match-beginning 2) "&gt;")
  2646. (t "&amp;"))))
  2647. (goto-char (point-min))
  2648. (insert "<pre>\n")
  2649. (goto-char (point-max))
  2650. (insert "</pre>\n<hr>\n")
  2651. ;; We have to examine charset one by one since
  2652. ;; charset specified in parts might be different.
  2653. (if (eq charset 'gnus-decoded)
  2654. (setq charset 'utf-8
  2655. eheader (mm-encode-coding-string (buffer-string)
  2656. charset)
  2657. title (when title
  2658. (mm-encode-coding-string title charset))
  2659. body (mm-encode-coding-string content charset)
  2660. force-charset t)
  2661. (setq hcharset (mm-find-mime-charset-region (point-min)
  2662. (point-max)))
  2663. (cond ((= (length hcharset) 1)
  2664. (setq hcharset (car hcharset)
  2665. coding (mm-charset-to-coding-system
  2666. hcharset)))
  2667. ((> (length hcharset) 1)
  2668. (setq hcharset 'utf-8
  2669. coding hcharset)))
  2670. (if coding
  2671. (if charset
  2672. (progn
  2673. (setq body
  2674. (mm-charset-to-coding-system charset))
  2675. (if (eq coding body)
  2676. (setq eheader (mm-encode-coding-string
  2677. (buffer-string) coding)
  2678. title (when title
  2679. (mm-encode-coding-string
  2680. title coding))
  2681. body content)
  2682. (setq charset 'utf-8
  2683. eheader (mm-encode-coding-string
  2684. (buffer-string) charset)
  2685. title (when title
  2686. (mm-encode-coding-string
  2687. title charset))
  2688. body (mm-encode-coding-string
  2689. (mm-decode-coding-string
  2690. content body)
  2691. charset)
  2692. force-charset t)))
  2693. (setq charset hcharset
  2694. eheader (mm-encode-coding-string
  2695. (buffer-string) coding)
  2696. title (when title
  2697. (mm-encode-coding-string
  2698. title coding))
  2699. body content))
  2700. (setq eheader (mm-string-as-unibyte (buffer-string))
  2701. body content)))
  2702. (erase-buffer)
  2703. (mm-disable-multibyte)
  2704. (insert body)
  2705. (when charset
  2706. (mm-add-meta-html-tag handle charset force-charset))
  2707. (when title
  2708. (goto-char (point-min))
  2709. (unless (search-forward "<title>" nil t)
  2710. (re-search-forward "<head>\\s-*" nil t)
  2711. (insert "<title>" title "</title>\n")))
  2712. (goto-char (point-min))
  2713. (or (re-search-forward
  2714. "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
  2715. (re-search-forward
  2716. "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
  2717. (insert eheader)
  2718. (mm-write-region (point-min) (point-max)
  2719. tmp-file nil nil nil 'binary t))))
  2720. (charset
  2721. (mm-with-unibyte-buffer
  2722. (insert (if (eq charset 'gnus-decoded)
  2723. (mm-encode-coding-string content
  2724. (setq charset 'utf-8))
  2725. content))
  2726. (if (or (mm-add-meta-html-tag handle charset)
  2727. (not file))
  2728. (mm-write-region (point-min) (point-max)
  2729. tmp-file nil nil nil 'binary t)
  2730. (setq tmp-file nil))))
  2731. (tmp-file
  2732. (mm-save-part-to-file handle tmp-file)))
  2733. (when tmp-file
  2734. (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
  2735. (add-hook 'gnus-summary-prepare-exit-hook
  2736. 'gnus-article-browse-delete-temp-files)
  2737. (add-hook 'gnus-exit-gnus-hook
  2738. (lambda ()
  2739. (gnus-article-browse-delete-temp-files t)))
  2740. ;; FIXME: Warn if there's an <img> tag?
  2741. (browse-url-of-file (or tmp-file (expand-file-name file)))
  2742. (setq showed t))
  2743. ;; If multipart, recurse
  2744. ((equal (mm-handle-media-supertype handle) "multipart")
  2745. (when (gnus-article-browse-html-parts handle header)
  2746. (setq showed t)))
  2747. ((equal (mm-handle-media-type handle) "message/rfc822")
  2748. (mm-with-multibyte-buffer
  2749. (mm-insert-part handle)
  2750. (setq handle (mm-dissect-buffer t t))
  2751. (when (and (bufferp (car handle))
  2752. (stringp (car (mm-handle-type handle))))
  2753. (setq handle (list handle)))
  2754. (when header
  2755. (article-decode-encoded-words)
  2756. (let ((gnus-visible-headers
  2757. (or (get 'gnus-visible-headers 'standard-value)
  2758. gnus-visible-headers)))
  2759. (article-hide-headers))
  2760. (goto-char (point-min))
  2761. (search-forward "\n\n" nil 'move)
  2762. (skip-chars-backward "\t\n ")
  2763. (setq header (buffer-substring (point-min) (point)))))
  2764. (when (prog1
  2765. (gnus-article-browse-html-parts handle header)
  2766. (mm-destroy-parts handle))
  2767. (setq showed t)))))
  2768. showed))
  2769. (defun gnus-article-browse-html-article (&optional arg)
  2770. "View \"text/html\" parts of the current article with a WWW browser.
  2771. Inline images embedded in a message using the cid scheme, as they are
  2772. generally considered to be safe, will be processed properly.
  2773. The message header is added to the beginning of every html part unless
  2774. the prefix argument ARG is given.
  2775. Warning: Spammers use links to images (using the http scheme) in HTML
  2776. articles to verify whether you have read the message. As
  2777. `gnus-article-browse-html-article' passes the HTML content to the
  2778. browser without eliminating these \"web bugs\" you should only
  2779. use it for mails from trusted senders.
  2780. If you always want to display HTML parts in the browser, set
  2781. `mm-text-html-renderer' to nil.
  2782. This command creates temporary files to pass HTML contents including
  2783. images if any to the browser, and deletes them when exiting the group
  2784. \(if you want)."
  2785. ;; Cf. `mm-w3m-safe-url-regexp'
  2786. (interactive "P")
  2787. (if arg
  2788. (gnus-summary-show-article)
  2789. (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
  2790. gnus-visible-headers))
  2791. ;; As we insert a <hr>, there's no need for the body boundary.
  2792. (gnus-treat-body-boundary nil))
  2793. (gnus-summary-show-article)))
  2794. (with-current-buffer gnus-article-buffer
  2795. (let ((header (unless arg
  2796. (save-restriction
  2797. (widen)
  2798. (buffer-substring-no-properties
  2799. (goto-char (point-min))
  2800. (if (search-forward "\n\n" nil t)
  2801. (match-beginning 0)
  2802. (goto-char (point-max))
  2803. (skip-chars-backward "\t\n ")
  2804. (point))))))
  2805. parts)
  2806. (set-buffer gnus-original-article-buffer)
  2807. (setq parts (mm-dissect-buffer t t))
  2808. ;; If singlepart, enforce a list.
  2809. (when (and (bufferp (car parts))
  2810. (stringp (car (mm-handle-type parts))))
  2811. (setq parts (list parts)))
  2812. ;; Process the list
  2813. (unless (gnus-article-browse-html-parts parts header)
  2814. (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
  2815. (mm-destroy-parts parts)
  2816. (unless arg
  2817. (gnus-summary-show-article)))))
  2818. (defun article-hide-list-identifiers ()
  2819. "Remove list identifies from the Subject header.
  2820. The `gnus-list-identifiers' variable specifies what to do."
  2821. (interactive)
  2822. (let ((inhibit-point-motion-hooks t)
  2823. (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
  2824. (inhibit-read-only t))
  2825. (when regexp
  2826. (save-excursion
  2827. (save-restriction
  2828. (article-narrow-to-head)
  2829. (goto-char (point-min))
  2830. (while (re-search-forward
  2831. (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
  2832. nil t)
  2833. (delete-region (match-beginning 2) (match-end 0))
  2834. (beginning-of-line))
  2835. (when (re-search-forward
  2836. "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
  2837. (delete-region (match-beginning 1) (match-end 1))))))))
  2838. (defun article-hide-pem (&optional arg)
  2839. "Toggle hiding of any PEM headers and signatures in the current article.
  2840. If given a negative prefix, always show; if given a positive prefix,
  2841. always hide."
  2842. (interactive (gnus-article-hidden-arg))
  2843. (unless (gnus-article-check-hidden-text 'pem arg)
  2844. (save-excursion
  2845. (let ((inhibit-read-only t) end)
  2846. (goto-char (point-min))
  2847. ;; Hide the horrendously ugly "header".
  2848. (when (and (search-forward
  2849. "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
  2850. nil t)
  2851. (setq end (1+ (match-beginning 0))))
  2852. (gnus-add-wash-type 'pem)
  2853. (gnus-article-hide-text-type
  2854. end
  2855. (if (search-forward "\n\n" nil t)
  2856. (match-end 0)
  2857. (point-max))
  2858. 'pem)
  2859. ;; Hide the trailer as well
  2860. (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
  2861. nil t)
  2862. (gnus-article-hide-text-type
  2863. (match-beginning 0) (match-end 0) 'pem)))))))
  2864. (defun article-strip-banner ()
  2865. "Strip the banners specified by the `banner' group parameter and by
  2866. `gnus-article-address-banner-alist'."
  2867. (interactive)
  2868. (save-excursion
  2869. (save-restriction
  2870. (let ((inhibit-point-motion-hooks t))
  2871. (when (gnus-parameter-banner gnus-newsgroup-name)
  2872. (article-really-strip-banner
  2873. (gnus-parameter-banner gnus-newsgroup-name)))
  2874. (when gnus-article-address-banner-alist
  2875. ;; Note that the From header is decoded here, so it is
  2876. ;; required that the *-extract-address-components function
  2877. ;; supports non-ASCII text.
  2878. (let ((from (save-restriction
  2879. (widen)
  2880. (article-narrow-to-head)
  2881. (mail-fetch-field "from"))))
  2882. (when (and from
  2883. (setq from
  2884. (cadr (funcall gnus-extract-address-components
  2885. from))))
  2886. (catch 'found
  2887. (dolist (pair gnus-article-address-banner-alist)
  2888. (when (string-match (car pair) from)
  2889. (throw 'found
  2890. (article-really-strip-banner (cdr pair)))))))))))))
  2891. (defun article-really-strip-banner (banner)
  2892. "Strip the banner specified by the argument."
  2893. (save-excursion
  2894. (save-restriction
  2895. (let ((inhibit-point-motion-hooks t)
  2896. (gnus-signature-limit nil)
  2897. (inhibit-read-only t))
  2898. (article-goto-body)
  2899. (cond
  2900. ((eq banner 'signature)
  2901. (when (gnus-article-narrow-to-signature)
  2902. (widen)
  2903. (forward-line -1)
  2904. (delete-region (point) (point-max))))
  2905. ((symbolp banner)
  2906. (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
  2907. (while (re-search-forward banner nil t)
  2908. (delete-region (match-beginning 0) (match-end 0)))))
  2909. ((stringp banner)
  2910. (while (re-search-forward banner nil t)
  2911. (delete-region (match-beginning 0) (match-end 0)))))))))
  2912. (defun article-babel ()
  2913. "Translate article using an online translation service."
  2914. (interactive)
  2915. (require 'babel)
  2916. (gnus-with-article-buffer
  2917. (when (article-goto-body)
  2918. (let* ((start (point))
  2919. (end (point-max))
  2920. (orig (buffer-substring start end))
  2921. (trans (babel-as-string orig)))
  2922. (save-restriction
  2923. (narrow-to-region start end)
  2924. (delete-region start end)
  2925. (insert trans))))))
  2926. (defun article-hide-signature (&optional arg)
  2927. "Hide the signature in the current article.
  2928. If given a negative prefix, always show; if given a positive prefix,
  2929. always hide."
  2930. (interactive (gnus-article-hidden-arg))
  2931. (unless (gnus-article-check-hidden-text 'signature arg)
  2932. (save-excursion
  2933. (save-restriction
  2934. (let ((inhibit-read-only t))
  2935. (when (gnus-article-narrow-to-signature)
  2936. (gnus-article-hide-text-type
  2937. (point-min) (point-max) 'signature))))))
  2938. (gnus-set-mode-line 'article))
  2939. (defun article-strip-headers-in-body ()
  2940. "Strip offensive headers from bodies."
  2941. (interactive)
  2942. (save-excursion
  2943. (article-goto-body)
  2944. (let ((case-fold-search t))
  2945. (when (looking-at "x-no-archive:")
  2946. (gnus-delete-line)))))
  2947. (defun article-strip-leading-blank-lines ()
  2948. "Remove all blank lines from the beginning of the article."
  2949. (interactive)
  2950. (save-excursion
  2951. (let ((inhibit-point-motion-hooks t)
  2952. (inhibit-read-only t))
  2953. (when (article-goto-body)
  2954. (while (and (not (eobp))
  2955. (looking-at "[ \t]*$"))
  2956. (gnus-delete-line))))))
  2957. (defun article-narrow-to-head ()
  2958. "Narrow the buffer to the head of the message.
  2959. Point is left at the beginning of the narrowed-to region."
  2960. (narrow-to-region
  2961. (goto-char (point-min))
  2962. (cond
  2963. ;; Absolutely no headers displayed.
  2964. ((looking-at "\n")
  2965. (point))
  2966. ;; Normal headers.
  2967. ((search-forward "\n\n" nil 1)
  2968. (1- (point)))
  2969. ;; Nothing but headers.
  2970. (t
  2971. (point-max))))
  2972. (goto-char (point-min)))
  2973. (defun article-goto-body ()
  2974. "Place point at the start of the body."
  2975. (goto-char (point-min))
  2976. (cond
  2977. ;; This variable is only bound when dealing with separate
  2978. ;; MIME body parts.
  2979. (article-goto-body-goes-to-point-min-p
  2980. t)
  2981. ((search-forward "\n\n" nil t)
  2982. t)
  2983. (t
  2984. (goto-char (point-max))
  2985. nil)))
  2986. (defun article-strip-multiple-blank-lines ()
  2987. "Replace consecutive blank lines with one empty line."
  2988. (interactive)
  2989. (save-excursion
  2990. (let ((inhibit-point-motion-hooks t)
  2991. (inhibit-read-only t))
  2992. ;; First make all blank lines empty.
  2993. (article-goto-body)
  2994. (while (re-search-forward "^[ \t]+$" nil t)
  2995. (unless (gnus-annotation-in-region-p
  2996. (match-beginning 0) (match-end 0))
  2997. (replace-match "" nil t)))
  2998. ;; Then replace multiple empty lines with a single empty line.
  2999. (article-goto-body)
  3000. (while (re-search-forward "\n\n\\(\n+\\)" nil t)
  3001. (unless (gnus-annotation-in-region-p
  3002. (match-beginning 0) (match-end 0))
  3003. (delete-region (match-beginning 1) (match-end 1)))))))
  3004. (defun article-strip-leading-space ()
  3005. "Remove all white space from the beginning of the lines in the article."
  3006. (interactive)
  3007. (save-excursion
  3008. (let ((inhibit-point-motion-hooks t)
  3009. (inhibit-read-only t))
  3010. (article-goto-body)
  3011. (while (re-search-forward "^[ \t]+" nil t)
  3012. (replace-match "" t t)))))
  3013. (defun article-strip-trailing-space ()
  3014. "Remove all white space from the end of the lines in the article."
  3015. (interactive)
  3016. (save-excursion
  3017. (let ((inhibit-point-motion-hooks t)
  3018. (inhibit-read-only t))
  3019. (article-goto-body)
  3020. (while (re-search-forward "[ \t]+$" nil t)
  3021. (replace-match "" t t)))))
  3022. (defun article-strip-blank-lines ()
  3023. "Strip leading, trailing and multiple blank lines."
  3024. (interactive)
  3025. (article-strip-leading-blank-lines)
  3026. (article-remove-trailing-blank-lines)
  3027. (article-strip-multiple-blank-lines))
  3028. (defun article-strip-all-blank-lines ()
  3029. "Strip all blank lines."
  3030. (interactive)
  3031. (save-excursion
  3032. (let ((inhibit-point-motion-hooks t)
  3033. (inhibit-read-only t))
  3034. (article-goto-body)
  3035. (while (re-search-forward "^[ \t]*\n" nil t)
  3036. (replace-match "" t t)))))
  3037. (defun gnus-article-narrow-to-signature ()
  3038. "Narrow to the signature; return t if a signature is found, else nil."
  3039. (let ((inhibit-point-motion-hooks t))
  3040. (when (gnus-article-search-signature)
  3041. (forward-line 1)
  3042. ;; Check whether we have some limits to what we consider
  3043. ;; to be a signature.
  3044. (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
  3045. (list gnus-signature-limit)))
  3046. limit limited)
  3047. (while (setq limit (pop limits))
  3048. (if (or (and (integerp limit)
  3049. (< (- (point-max) (point)) limit))
  3050. (and (floatp limit)
  3051. (< (count-lines (point) (point-max)) limit))
  3052. (and (functionp limit)
  3053. (funcall limit))
  3054. (and (stringp limit)
  3055. (not (re-search-forward limit nil t))))
  3056. () ; This limit did not succeed.
  3057. (setq limited t
  3058. limits nil)))
  3059. (unless limited
  3060. (narrow-to-region (point) (point-max))
  3061. t)))))
  3062. (defun gnus-article-search-signature ()
  3063. "Search the current buffer for the signature separator.
  3064. Put point at the beginning of the signature separator."
  3065. (let ((cur (point)))
  3066. (goto-char (point-max))
  3067. (if (if (stringp gnus-signature-separator)
  3068. (re-search-backward gnus-signature-separator nil t)
  3069. (let ((seps gnus-signature-separator))
  3070. (while (and seps
  3071. (not (re-search-backward (car seps) nil t)))
  3072. (pop seps))
  3073. seps))
  3074. t
  3075. (goto-char cur)
  3076. nil)))
  3077. (defun gnus-article-hidden-arg ()
  3078. "Return the current prefix arg as a number, or 0 if no prefix."
  3079. (list (if current-prefix-arg
  3080. (prefix-numeric-value current-prefix-arg)
  3081. 0)))
  3082. (defun gnus-article-check-hidden-text (type arg)
  3083. "Return nil if hiding is necessary.
  3084. Arg can be nil or a number. nil and positive means hide, negative
  3085. means show, 0 means toggle."
  3086. (save-excursion
  3087. (save-restriction
  3088. (let ((hide (gnus-article-hidden-text-p type)))
  3089. (cond
  3090. ((or (null arg)
  3091. (> arg 0))
  3092. nil)
  3093. ((< arg 0)
  3094. (gnus-article-show-hidden-text type)
  3095. t)
  3096. (t
  3097. (if (eq hide 'hidden)
  3098. (progn
  3099. (gnus-article-show-hidden-text type)
  3100. t)
  3101. nil)))))))
  3102. (defun gnus-article-hidden-text-p (type)
  3103. "Say whether the current buffer contains hidden text of type TYPE."
  3104. (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
  3105. (while (and pos
  3106. (not (get-text-property pos 'invisible))
  3107. (not (get-text-property pos 'dummy-invisible)))
  3108. (setq pos
  3109. (text-property-any (1+ pos) (point-max) 'article-type type)))
  3110. (if pos
  3111. 'hidden
  3112. nil)))
  3113. (defun gnus-article-show-hidden-text (type &optional dummy)
  3114. "Show all hidden text of type TYPE.
  3115. Originally it is hide instead of DUMMY."
  3116. (let ((inhibit-read-only t)
  3117. (inhibit-point-motion-hooks t))
  3118. (gnus-remove-text-properties-when
  3119. 'article-type type
  3120. (point-min) (point-max)
  3121. (cons 'article-type (cons type
  3122. gnus-hidden-properties)))
  3123. (gnus-delete-wash-type type)))
  3124. (defconst article-time-units
  3125. `((year . ,(* 365.25 24 60 60))
  3126. (week . ,(* 7 24 60 60))
  3127. (day . ,(* 24 60 60))
  3128. (hour . ,(* 60 60))
  3129. (minute . 60)
  3130. (second . 1))
  3131. "Mapping from time units to seconds.")
  3132. (defun gnus-article-forward-header ()
  3133. "Move point to the start of the next header.
  3134. If the current header is a continuation header, this can be several
  3135. lines forward."
  3136. (let ((ended nil))
  3137. (while (not ended)
  3138. (forward-line 1)
  3139. (if (looking-at "[ \t]+[^ \t]")
  3140. (forward-line 1)
  3141. (setq ended t)))))
  3142. (defun article-treat-date ()
  3143. (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
  3144. (with-current-buffer gnus-summary-buffer
  3145. gnus-article-date-headers)
  3146. gnus-article-date-headers)
  3147. t))
  3148. (defun article-date-ut (&optional type highlight date-position)
  3149. "Convert DATE date to TYPE in the current article.
  3150. The default type is `ut'. See `gnus-article-date-headers' for
  3151. possible values."
  3152. (interactive (list 'ut t))
  3153. (let* ((case-fold-search t)
  3154. (inhibit-read-only t)
  3155. (inhibit-point-motion-hooks t)
  3156. (first t)
  3157. (visible-date (mail-fetch-field "Date"))
  3158. pos date bface eface)
  3159. (save-excursion
  3160. (goto-char (point-min))
  3161. (when (re-search-forward "^Date:" nil t)
  3162. (setq bface (get-text-property (point-at-bol) 'face)
  3163. eface (get-text-property (1- (point-at-eol)) 'face)))
  3164. ;; Delete any old Date headers.
  3165. (if date-position
  3166. (progn
  3167. (goto-char date-position)
  3168. (setq date (get-text-property (point) 'original-date))
  3169. (delete-region (point)
  3170. (progn
  3171. (gnus-article-forward-header)
  3172. (point)))
  3173. (article-transform-date date type bface eface))
  3174. (save-restriction
  3175. (widen)
  3176. (goto-char (point-min))
  3177. (while (or (get-text-property (setq pos (point)) 'original-date)
  3178. (and (setq pos (next-single-property-change
  3179. (point) 'original-date))
  3180. (goto-char pos)))
  3181. (narrow-to-region pos (if (search-forward "\n\n" nil t)
  3182. (1+ (match-beginning 0))
  3183. (point-max)))
  3184. (goto-char (point-min))
  3185. (while (re-search-forward "^Date:" nil t)
  3186. (setq date (get-text-property (match-beginning 0) 'original-date))
  3187. (delete-region (point-at-bol) (progn
  3188. (gnus-article-forward-header)
  3189. (point))))
  3190. (when (and (not date)
  3191. visible-date)
  3192. (setq date visible-date))
  3193. (when date
  3194. (article-transform-date date type bface eface))
  3195. (goto-char (point-max))
  3196. (widen)))))))
  3197. (defun article-transform-date (date type bface eface)
  3198. (dolist (this-type (cond
  3199. ((null type)
  3200. (list 'ut))
  3201. ((atom type)
  3202. (list type))
  3203. (t
  3204. type)))
  3205. (insert (article-make-date-line date (or this-type 'ut)) "\n")
  3206. (forward-line -1)
  3207. (beginning-of-line)
  3208. (put-text-property (point) (1+ (point))
  3209. 'original-date date)
  3210. (put-text-property (point) (1+ (point))
  3211. 'gnus-date-type this-type)
  3212. ;; Do highlighting.
  3213. (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
  3214. (put-text-property (match-beginning 1) (1+ (match-end 1))
  3215. 'face bface)
  3216. (put-text-property (match-beginning 2) (match-end 2)
  3217. 'face eface))
  3218. (forward-line 1)))
  3219. (defun article-make-date-line (date type)
  3220. "Return a DATE line of TYPE."
  3221. (unless (memq type '(local ut original user-defined iso8601 lapsed english
  3222. combined-lapsed))
  3223. (error "Unknown conversion type: %s" type))
  3224. (condition-case ()
  3225. (let ((time (ignore-errors (date-to-time date))))
  3226. (cond
  3227. ;; Convert to the local timezone.
  3228. ((eq type 'local)
  3229. (concat "Date: " (message-make-date time)))
  3230. ;; Convert to Universal Time.
  3231. ((eq type 'ut)
  3232. (concat "Date: "
  3233. (substring
  3234. (message-make-date
  3235. (let* ((e (parse-time-string date))
  3236. (tm (apply 'encode-time e))
  3237. (ms (car tm))
  3238. (ls (- (cadr tm) (car (current-time-zone time)))))
  3239. (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
  3240. ((> ls 65535) (list (1+ ms) (- ls 65536)))
  3241. (t (list ms ls)))))
  3242. 0 -5)
  3243. "UT"))
  3244. ;; Get the original date from the article.
  3245. ((eq type 'original)
  3246. (concat "Date: " (if (string-match "\n+$" date)
  3247. (substring date 0 (match-beginning 0))
  3248. date)))
  3249. ;; Let the user define the format.
  3250. ((eq type 'user-defined)
  3251. (let ((format (or (condition-case nil
  3252. (with-current-buffer gnus-summary-buffer
  3253. gnus-article-time-format)
  3254. (error nil))
  3255. gnus-article-time-format)))
  3256. (if (functionp format)
  3257. (funcall format time)
  3258. (concat "Date: " (format-time-string format time)))))
  3259. ;; ISO 8601.
  3260. ((eq type 'iso8601)
  3261. (let ((tz (car (current-time-zone time))))
  3262. (concat
  3263. "Date: "
  3264. (format-time-string "%Y%m%dT%H%M%S" time)
  3265. (format "%s%02d%02d"
  3266. (if (> tz 0) "+" "-") (/ (abs tz) 3600)
  3267. (/ (% (abs tz) 3600) 60)))))
  3268. ;; Do a lapsed format.
  3269. ((eq type 'lapsed)
  3270. (concat "Date: " (article-lapsed-string time)))
  3271. ;; A combined date/lapsed format.
  3272. ((eq type 'combined-lapsed)
  3273. (let ((date-string (article-make-date-line date 'original))
  3274. (segments 3)
  3275. lapsed-string)
  3276. (while (and
  3277. time
  3278. (setq lapsed-string
  3279. (concat " (" (article-lapsed-string time segments) ")"))
  3280. (> (+ (length date-string)
  3281. (length lapsed-string))
  3282. (+ fill-column 6))
  3283. (> segments 0))
  3284. (setq segments (1- segments)))
  3285. (if (> segments 0)
  3286. (concat date-string lapsed-string)
  3287. date-string)))
  3288. ;; Display the date in proper English
  3289. ((eq type 'english)
  3290. (let ((dtime (decode-time time)))
  3291. (concat
  3292. "Date: the "
  3293. (number-to-string (nth 3 dtime))
  3294. (let ((digit (% (nth 3 dtime) 10)))
  3295. (cond
  3296. ((memq (nth 3 dtime) '(11 12 13)) "th")
  3297. ((= digit 1) "st")
  3298. ((= digit 2) "nd")
  3299. ((= digit 3) "rd")
  3300. (t "th")))
  3301. " of "
  3302. (nth (1- (nth 4 dtime)) gnus-english-month-names)
  3303. " "
  3304. (number-to-string (nth 5 dtime))
  3305. " at "
  3306. (format "%02d" (nth 2 dtime))
  3307. ":"
  3308. (format "%02d" (nth 1 dtime)))))))
  3309. (foo
  3310. (format "Date: %s (from Gnus)" date))))
  3311. (defun article-lapsed-string (time &optional max-segments)
  3312. ;; If the date is seriously mangled, the timezone functions are
  3313. ;; liable to bug out, so we ignore all errors.
  3314. (let* ((now (current-time))
  3315. (real-time (subtract-time now time))
  3316. (real-sec (and real-time
  3317. (+ (* (float (car real-time)) 65536)
  3318. (cadr real-time))))
  3319. (sec (and real-time (abs real-sec)))
  3320. (segments 0)
  3321. num prev)
  3322. (unless max-segments
  3323. (setq max-segments (length article-time-units)))
  3324. (cond
  3325. ((null real-time)
  3326. "Unknown")
  3327. ((zerop sec)
  3328. "Now")
  3329. (t
  3330. (concat
  3331. ;; This is a bit convoluted, but basically we go
  3332. ;; through the time units for years, weeks, etc,
  3333. ;; and divide things to see whether that results
  3334. ;; in positive answers.
  3335. (mapconcat
  3336. (lambda (unit)
  3337. (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
  3338. (>= segments max-segments))
  3339. ;; The (remaining) seconds are too few to
  3340. ;; be divided into this time unit.
  3341. ""
  3342. ;; It's big enough, so we output it.
  3343. (setq sec (- sec (* num (cdr unit))))
  3344. (prog1
  3345. (concat (if prev ", " "") (int-to-string
  3346. (floor num))
  3347. " " (symbol-name (car unit))
  3348. (if (> num 1) "s" ""))
  3349. (setq prev t
  3350. segments (1+ segments)))))
  3351. article-time-units "")
  3352. ;; If dates are odd, then it might appear like the
  3353. ;; article was sent in the future.
  3354. (if (> real-sec 0)
  3355. " ago"
  3356. " in the future"))))))
  3357. (defun article-date-local (&optional highlight)
  3358. "Convert the current article date to the local timezone."
  3359. (interactive (list t))
  3360. (article-date-ut 'local highlight))
  3361. (defun article-date-english (&optional highlight)
  3362. "Convert the current article date to something that is proper English."
  3363. (interactive (list t))
  3364. (article-date-ut 'english highlight))
  3365. (defun article-date-original (&optional highlight)
  3366. "Convert the current article date to what it was originally.
  3367. This is only useful if you have used some other date conversion
  3368. function and want to see what the date was before converting."
  3369. (interactive (list t))
  3370. (article-date-ut 'original highlight))
  3371. (defun article-date-lapsed (&optional highlight)
  3372. "Convert the current article date to time lapsed since it was sent."
  3373. (interactive (list t))
  3374. (article-date-ut 'lapsed highlight))
  3375. (defun article-date-combined-lapsed (&optional highlight)
  3376. "Convert the current article date to time lapsed since it was sent."
  3377. (interactive (list t))
  3378. (article-date-ut 'combined-lapsed highlight))
  3379. (defun article-update-date-lapsed ()
  3380. "Function to be run from a timer to update the lapsed time line."
  3381. (save-match-data
  3382. (let ((buffer (current-buffer)))
  3383. (ignore-errors
  3384. (walk-windows
  3385. (lambda (w)
  3386. (set-buffer (window-buffer w))
  3387. (when (eq major-mode 'gnus-article-mode)
  3388. (let ((old-line (count-lines (point-min) (point)))
  3389. (old-column (- (point) (line-beginning-position)))
  3390. (window-start
  3391. (window-start (get-buffer-window (current-buffer)))))
  3392. (goto-char (point-min))
  3393. (while (re-search-forward "^Date:" nil t)
  3394. (let ((type (get-text-property (match-beginning 0)
  3395. 'gnus-date-type)))
  3396. (when (memq type '(lapsed combined-lapsed user-format))
  3397. (when (and window-start
  3398. (not (= window-start
  3399. (save-excursion
  3400. (forward-line 1)
  3401. (point)))))
  3402. (setq window-start nil))
  3403. (save-excursion
  3404. (article-date-ut type t (match-beginning 0)))
  3405. (forward-line 1)
  3406. (when window-start
  3407. (set-window-start (get-buffer-window (current-buffer))
  3408. (point))))))
  3409. (goto-char (point-min))
  3410. (when (> old-column 0)
  3411. (setq old-line (1- old-line)))
  3412. (forward-line old-line)
  3413. (end-of-line)
  3414. (when (> (current-column) old-column)
  3415. (beginning-of-line)
  3416. (forward-char old-column)))))
  3417. nil 'visible))
  3418. (set-buffer buffer))))
  3419. (defun gnus-start-date-timer (&optional n)
  3420. "Start a timer to update the Date headers in the article buffers.
  3421. The numerical prefix says how frequently (in seconds) the function
  3422. is to run."
  3423. (interactive "p")
  3424. (unless n
  3425. (setq n 1))
  3426. (gnus-stop-date-timer)
  3427. (setq article-lapsed-timer
  3428. (run-at-time 1 n 'article-update-date-lapsed)))
  3429. (defun gnus-stop-date-timer ()
  3430. "Stop the Date timer."
  3431. (interactive)
  3432. (when article-lapsed-timer
  3433. (nnheader-cancel-timer article-lapsed-timer)
  3434. (setq article-lapsed-timer nil)))
  3435. (defun article-date-user (&optional highlight)
  3436. "Convert the current article date to the user-defined format.
  3437. This format is defined by the `gnus-article-time-format' variable."
  3438. (interactive (list t))
  3439. (article-date-ut 'user highlight))
  3440. (defun article-date-iso8601 (&optional highlight)
  3441. "Convert the current article date to ISO8601."
  3442. (interactive (list t))
  3443. (article-date-ut 'iso8601 highlight))
  3444. (defmacro gnus-article-save-original-date (&rest forms)
  3445. "Save the original date as a text property and evaluate FORMS."
  3446. `(let* ((case-fold-search t)
  3447. (start (progn
  3448. (goto-char (point-min))
  3449. (when (and (re-search-forward "^date:[\t\n ]+" nil t)
  3450. (not (bolp)))
  3451. (match-end 0))))
  3452. (date (when (and start
  3453. (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
  3454. nil t))
  3455. (buffer-substring-no-properties start
  3456. (match-beginning 0)))))
  3457. (goto-char (point-max))
  3458. (skip-chars-backward "\n")
  3459. (put-text-property (point-min) (point) 'original-date date)
  3460. ,@forms
  3461. (goto-char (point-max))
  3462. (skip-chars-backward "\n")
  3463. (put-text-property (point-min) (point) 'original-date date)))
  3464. ;; (defun article-show-all ()
  3465. ;; "Show all hidden text in the article buffer."
  3466. ;; (interactive)
  3467. ;; (save-excursion
  3468. ;; (let ((inhibit-read-only t))
  3469. ;; (gnus-article-unhide-text (point-min) (point-max)))))
  3470. (defun article-remove-leading-whitespace ()
  3471. "Remove excessive whitespace from all headers."
  3472. (interactive)
  3473. (save-excursion
  3474. (save-restriction
  3475. (let ((inhibit-read-only t))
  3476. (article-narrow-to-head)
  3477. (goto-char (point-min))
  3478. (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
  3479. (delete-region (match-beginning 1) (match-end 1)))))))
  3480. (defun article-emphasize (&optional arg)
  3481. "Emphasize text according to `gnus-emphasis-alist'."
  3482. (interactive (gnus-article-hidden-arg))
  3483. (unless (gnus-article-check-hidden-text 'emphasis arg)
  3484. (save-excursion
  3485. (let ((alist (or
  3486. (condition-case nil
  3487. (with-current-buffer gnus-summary-buffer
  3488. gnus-article-emphasis-alist)
  3489. (error))
  3490. gnus-emphasis-alist))
  3491. (inhibit-read-only t)
  3492. (props (append '(article-type emphasis)
  3493. gnus-hidden-properties))
  3494. regexp elem beg invisible visible face)
  3495. (article-goto-body)
  3496. (setq beg (point))
  3497. (while (setq elem (pop alist))
  3498. (goto-char beg)
  3499. (setq regexp (car elem)
  3500. invisible (nth 1 elem)
  3501. visible (nth 2 elem)
  3502. face (nth 3 elem))
  3503. (while (re-search-forward regexp nil t)
  3504. (when (and (match-beginning visible) (match-beginning invisible))
  3505. (gnus-article-hide-text
  3506. (match-beginning invisible) (match-end invisible) props)
  3507. (gnus-article-unhide-text-type
  3508. (match-beginning visible) (match-end visible) 'emphasis)
  3509. (gnus-put-overlay-excluding-newlines
  3510. (match-beginning visible) (match-end visible) 'face face)
  3511. (gnus-add-wash-type 'emphasis)
  3512. (goto-char (match-end invisible)))))))))
  3513. (defun gnus-article-setup-highlight-words (&optional highlight-words)
  3514. "Setup newsgroup emphasis alist."
  3515. (unless gnus-article-emphasis-alist
  3516. (let ((name (and gnus-newsgroup-name
  3517. (gnus-group-real-name gnus-newsgroup-name))))
  3518. (make-local-variable 'gnus-article-emphasis-alist)
  3519. (setq gnus-article-emphasis-alist
  3520. (nconc
  3521. (let ((alist gnus-group-highlight-words-alist) elem highlight)
  3522. (while (setq elem (pop alist))
  3523. (when (and name (string-match (car elem) name))
  3524. (setq alist nil
  3525. highlight (copy-sequence (cdr elem)))))
  3526. highlight)
  3527. (copy-sequence highlight-words)
  3528. (if gnus-newsgroup-name
  3529. (copy-sequence (gnus-group-find-parameter
  3530. gnus-newsgroup-name 'highlight-words t)))
  3531. gnus-emphasis-alist)))))
  3532. (defvar gnus-summary-article-menu)
  3533. (defvar gnus-summary-post-menu)
  3534. ;;; Saving functions.
  3535. (defun gnus-article-save (save-buffer file &optional num)
  3536. "Save the currently selected article."
  3537. (when (or (get gnus-default-article-saver :headers)
  3538. (not gnus-save-all-headers))
  3539. ;; Remove headers according to `gnus-saved-headers' or the value
  3540. ;; of the `:headers' property that the saver function might have.
  3541. (let ((gnus-visible-headers
  3542. (or (symbol-value (get gnus-default-article-saver :headers))
  3543. gnus-saved-headers gnus-visible-headers))
  3544. ;; Ignore group parameter. See `article-hide-headers'.
  3545. (gnus-summary-buffer nil))
  3546. (with-current-buffer save-buffer
  3547. (article-hide-headers 1 t))))
  3548. (save-window-excursion
  3549. (if (not gnus-default-article-saver)
  3550. (error "No default saver is defined")
  3551. ;; !!! Magic! The saving functions all save
  3552. ;; `gnus-save-article-buffer' (or so they think), but we
  3553. ;; bind that variable to our save-buffer.
  3554. (set-buffer gnus-article-buffer)
  3555. (let* ((gnus-save-article-buffer save-buffer)
  3556. (filename
  3557. (cond
  3558. ((not gnus-prompt-before-saving) 'default)
  3559. ((eq gnus-prompt-before-saving 'always) nil)
  3560. (t file)))
  3561. (gnus-number-of-articles-to-be-saved
  3562. (when (eq gnus-prompt-before-saving t)
  3563. num))) ; Magic
  3564. (set-buffer gnus-article-current-summary)
  3565. (funcall gnus-default-article-saver filename)))))
  3566. (defun gnus-read-save-file-name (prompt &optional filename
  3567. function group headers variable
  3568. dir-var)
  3569. (let ((default-name
  3570. (funcall function group headers (symbol-value variable)))
  3571. result)
  3572. (setq result
  3573. (expand-file-name
  3574. (cond
  3575. ((eq filename 'default)
  3576. default-name)
  3577. ((eq filename t)
  3578. default-name)
  3579. (filename filename)
  3580. (t
  3581. (when (symbol-value dir-var)
  3582. (setq default-name (expand-file-name
  3583. (file-name-nondirectory default-name)
  3584. (symbol-value dir-var))))
  3585. (let* ((split-name (gnus-get-split-value gnus-split-methods))
  3586. (prompt
  3587. (format prompt
  3588. (if (and gnus-number-of-articles-to-be-saved
  3589. (> gnus-number-of-articles-to-be-saved 1))
  3590. (format "these %d articles"
  3591. gnus-number-of-articles-to-be-saved)
  3592. "this article")))
  3593. (file
  3594. ;; Let the split methods have their say.
  3595. (cond
  3596. ;; No split name was found.
  3597. ((null split-name)
  3598. (read-file-name
  3599. (concat prompt " (default "
  3600. (file-name-nondirectory default-name) "): ")
  3601. (file-name-directory default-name)
  3602. default-name))
  3603. ;; A single group name is returned.
  3604. ((stringp split-name)
  3605. (setq default-name
  3606. (funcall function split-name headers
  3607. (symbol-value variable)))
  3608. (read-file-name
  3609. (concat prompt " (default "
  3610. (file-name-nondirectory default-name) "): ")
  3611. (file-name-directory default-name)
  3612. default-name))
  3613. ;; A single split name was found
  3614. ((= 1 (length split-name))
  3615. (let* ((name (expand-file-name
  3616. (car split-name)
  3617. gnus-article-save-directory))
  3618. (dir (cond ((file-directory-p name)
  3619. (file-name-as-directory name))
  3620. ((file-exists-p name) name)
  3621. (t gnus-article-save-directory))))
  3622. (read-file-name
  3623. (concat prompt " (default " name "): ")
  3624. dir name)))
  3625. ;; A list of splits was found.
  3626. (t
  3627. (setq split-name (nreverse split-name))
  3628. (let (result)
  3629. (let ((file-name-history
  3630. (nconc split-name file-name-history)))
  3631. (setq result
  3632. (expand-file-name
  3633. (read-file-name
  3634. (concat prompt " (`M-p' for defaults): ")
  3635. gnus-article-save-directory
  3636. (car split-name))
  3637. gnus-article-save-directory)))
  3638. (car (push result file-name-history)))))))
  3639. ;; Create the directory.
  3640. (gnus-make-directory (file-name-directory file))
  3641. ;; If we have read a directory, we append the default file name.
  3642. (when (file-directory-p file)
  3643. (setq file (expand-file-name (file-name-nondirectory
  3644. default-name)
  3645. (file-name-as-directory file))))
  3646. ;; Possibly translate some characters.
  3647. (nnheader-translate-file-chars file))))))
  3648. (gnus-make-directory (file-name-directory result))
  3649. (when variable
  3650. (set variable result))
  3651. (when dir-var
  3652. (set dir-var (file-name-directory result)))
  3653. result))
  3654. (defun gnus-article-archive-name (group)
  3655. "Return the first instance of an \"Archive-name\" in the current buffer."
  3656. (let ((case-fold-search t))
  3657. (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
  3658. (nnheader-concat gnus-article-save-directory
  3659. (match-string 1)))))
  3660. (defun gnus-article-nndoc-name (group)
  3661. "If GROUP is an nndoc group, return the name of the parent group."
  3662. (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
  3663. (gnus-group-get-parameter group 'save-article-group)))
  3664. (defun gnus-summary-save-in-rmail (&optional filename)
  3665. "Append this article to Rmail file.
  3666. Optional argument FILENAME specifies file name.
  3667. Directory to save to is default to `gnus-article-save-directory'."
  3668. (setq filename (gnus-read-save-file-name
  3669. "Save %s in rmail file" filename
  3670. gnus-rmail-save-name gnus-newsgroup-name
  3671. gnus-current-headers 'gnus-newsgroup-last-rmail))
  3672. (with-current-buffer gnus-save-article-buffer
  3673. (save-excursion
  3674. (save-restriction
  3675. (widen)
  3676. ;; Note that unlike gnus-summary-save-in-mail, there is no
  3677. ;; check to see if filename is Babyl. Rmail in Emacs 23 does
  3678. ;; not use Babyl.
  3679. (gnus-output-to-rmail filename))))
  3680. filename)
  3681. (defun gnus-summary-save-in-mail (&optional filename)
  3682. "Append this article to Unix mail file.
  3683. Optional argument FILENAME specifies file name.
  3684. Directory to save to is default to `gnus-article-save-directory'."
  3685. (setq filename (gnus-read-save-file-name
  3686. "Save %s in Unix mail file" filename
  3687. gnus-mail-save-name gnus-newsgroup-name
  3688. gnus-current-headers 'gnus-newsgroup-last-mail))
  3689. (with-current-buffer gnus-save-article-buffer
  3690. (save-excursion
  3691. (save-restriction
  3692. (widen)
  3693. (if (and (file-readable-p filename)
  3694. (file-regular-p filename)
  3695. (mail-file-babyl-p filename))
  3696. (gnus-output-to-rmail filename)
  3697. (gnus-output-to-mail filename)))))
  3698. filename)
  3699. (put 'gnus-summary-save-in-file :decode t)
  3700. (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
  3701. (defun gnus-summary-save-in-file (&optional filename overwrite)
  3702. "Append this article to file.
  3703. Optional argument FILENAME specifies file name.
  3704. Directory to save to is default to `gnus-article-save-directory'."
  3705. (setq filename (gnus-read-save-file-name
  3706. "Save %s in file" filename
  3707. gnus-file-save-name gnus-newsgroup-name
  3708. gnus-current-headers 'gnus-newsgroup-last-file))
  3709. (with-current-buffer gnus-save-article-buffer
  3710. (save-excursion
  3711. (save-restriction
  3712. (widen)
  3713. (when (and overwrite
  3714. (file-exists-p filename))
  3715. (delete-file filename))
  3716. (gnus-output-to-file filename))))
  3717. filename)
  3718. (put 'gnus-summary-write-to-file :decode t)
  3719. (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
  3720. (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
  3721. (defun gnus-summary-write-to-file (&optional filename)
  3722. "Write this article to a file, overwriting it if the file exists.
  3723. Optional argument FILENAME specifies file name.
  3724. The directory to save in defaults to `gnus-article-save-directory'."
  3725. (setq filename (gnus-read-save-file-name
  3726. "Save %s in file" filename
  3727. gnus-file-save-name gnus-newsgroup-name
  3728. gnus-current-headers nil 'gnus-newsgroup-last-directory))
  3729. (gnus-summary-save-in-file filename t))
  3730. (put 'gnus-summary-save-body-in-file :decode t)
  3731. (defun gnus-summary-save-body-in-file (&optional filename overwrite)
  3732. "Append this article body to a file.
  3733. Optional argument FILENAME specifies file name.
  3734. The directory to save in defaults to `gnus-article-save-directory'."
  3735. (setq filename (gnus-read-save-file-name
  3736. "Save %s body in file" filename
  3737. gnus-file-save-name gnus-newsgroup-name
  3738. gnus-current-headers 'gnus-newsgroup-last-file))
  3739. (with-current-buffer gnus-save-article-buffer
  3740. (save-excursion
  3741. (save-restriction
  3742. (widen)
  3743. (when (article-goto-body)
  3744. (narrow-to-region (point) (point-max)))
  3745. (when (and overwrite
  3746. (file-exists-p filename))
  3747. (delete-file filename))
  3748. (gnus-output-to-file filename))))
  3749. filename)
  3750. (put 'gnus-summary-write-body-to-file :decode t)
  3751. (put 'gnus-summary-write-body-to-file
  3752. :function 'gnus-summary-save-body-in-file)
  3753. (defun gnus-summary-write-body-to-file (&optional filename)
  3754. "Write this article body to a file, overwriting it if the file exists.
  3755. Optional argument FILENAME specifies file name.
  3756. The directory to save in defaults to `gnus-article-save-directory'."
  3757. (setq filename (gnus-read-save-file-name
  3758. "Save %s body in file" filename
  3759. gnus-file-save-name gnus-newsgroup-name
  3760. gnus-current-headers nil 'gnus-newsgroup-last-directory))
  3761. (gnus-summary-save-body-in-file filename t))
  3762. (put 'gnus-summary-save-in-pipe :decode t)
  3763. (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
  3764. (defun gnus-summary-save-in-pipe (&optional command raw)
  3765. "Pipe this article to subprocess COMMAND.
  3766. Valid values for COMMAND include:
  3767. a string
  3768. The executable command name and possibly arguments.
  3769. nil
  3770. You will be prompted for the command in the minibuffer.
  3771. the symbol `default'
  3772. It will be replaced with the command which the variable
  3773. `gnus-summary-pipe-output-default-command' holds or the command
  3774. last used for saving.
  3775. Non-nil value for RAW overrides `:decode' and `:headers' properties
  3776. and the raw article including all headers will be piped."
  3777. (let ((article (gnus-summary-article-number))
  3778. (decode (unless raw
  3779. (get 'gnus-summary-save-in-pipe :decode)))
  3780. save-buffer default)
  3781. (if article
  3782. (if (vectorp (gnus-summary-article-header article))
  3783. (save-current-buffer
  3784. (gnus-summary-select-article decode decode nil article)
  3785. (insert-buffer-substring
  3786. (prog1
  3787. (if decode
  3788. gnus-article-buffer
  3789. gnus-original-article-buffer)
  3790. (setq save-buffer
  3791. (nnheader-set-temp-buffer " *Gnus Save*"))))
  3792. ;; Remove unwanted headers.
  3793. (when (and (not raw)
  3794. (or (get 'gnus-summary-save-in-pipe :headers)
  3795. (not gnus-save-all-headers)))
  3796. (let ((gnus-visible-headers
  3797. (or (symbol-value (get 'gnus-summary-save-in-pipe
  3798. :headers))
  3799. gnus-saved-headers gnus-visible-headers))
  3800. (gnus-summary-buffer nil))
  3801. (article-hide-headers 1 t))))
  3802. (error "%d is not a real article" article))
  3803. (error "No article to pipe"))
  3804. (setq default (or gnus-summary-pipe-output-default-command
  3805. gnus-last-shell-command))
  3806. (unless (stringp command)
  3807. (setq command
  3808. (if (and (eq command 'default) default)
  3809. default
  3810. (gnus-read-shell-command "Shell command on this article: "
  3811. default))))
  3812. (when (string-equal command "")
  3813. (if default
  3814. (setq command default)
  3815. (error "A command is required")))
  3816. (with-current-buffer save-buffer
  3817. (save-restriction
  3818. (widen)
  3819. (shell-command-on-region (point-min) (point-max) command nil)))
  3820. (gnus-kill-buffer save-buffer))
  3821. (setq gnus-summary-pipe-output-default-command command))
  3822. (defun gnus-summary-pipe-to-muttprint (&optional command)
  3823. "Pipe this article to muttprint."
  3824. (unless (stringp command)
  3825. (setq command (read-string
  3826. "Print using command: " gnus-summary-muttprint-program
  3827. nil gnus-summary-muttprint-program)))
  3828. (let ((gnus-summary-pipe-output-default-command
  3829. gnus-summary-pipe-output-default-command))
  3830. (gnus-summary-save-in-pipe command))
  3831. (setq gnus-summary-muttprint-program command))
  3832. ;;; Article file names when saving.
  3833. (defun gnus-capitalize-newsgroup (newsgroup)
  3834. "Capitalize NEWSGROUP name."
  3835. (when (not (zerop (length newsgroup)))
  3836. (concat (char-to-string (upcase (aref newsgroup 0)))
  3837. (substring newsgroup 1))))
  3838. (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
  3839. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3840. If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
  3841. Otherwise, it is like ~/News/news/group/num."
  3842. (let ((default
  3843. (expand-file-name
  3844. (concat (if (gnus-use-long-file-name 'not-save)
  3845. (gnus-capitalize-newsgroup newsgroup)
  3846. (gnus-newsgroup-directory-form newsgroup))
  3847. "/" (int-to-string (mail-header-number headers)))
  3848. gnus-article-save-directory)))
  3849. (if (and last-file
  3850. (string-equal (file-name-directory default)
  3851. (file-name-directory last-file))
  3852. (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  3853. default
  3854. (or last-file default))))
  3855. (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
  3856. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3857. If variable `gnus-use-long-file-name' is non-nil, it is
  3858. ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
  3859. (let ((default
  3860. (expand-file-name
  3861. (concat (if (gnus-use-long-file-name 'not-save)
  3862. newsgroup
  3863. (gnus-newsgroup-directory-form newsgroup))
  3864. "/" (int-to-string (mail-header-number headers)))
  3865. gnus-article-save-directory)))
  3866. (if (and last-file
  3867. (string-equal (file-name-directory default)
  3868. (file-name-directory last-file))
  3869. (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
  3870. default
  3871. (or last-file default))))
  3872. (defun gnus-plain-save-name (newsgroup headers &optional last-file)
  3873. "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
  3874. If variable `gnus-use-long-file-name' is non-nil, it is
  3875. ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
  3876. (or last-file
  3877. (expand-file-name
  3878. (if (gnus-use-long-file-name 'not-save)
  3879. newsgroup
  3880. (file-relative-name
  3881. (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
  3882. default-directory))
  3883. gnus-article-save-directory)))
  3884. (defun gnus-sender-save-name (newsgroup headers &optional last-file)
  3885. "Generate file name from sender."
  3886. (let ((from (mail-header-from headers)))
  3887. (expand-file-name
  3888. (if (and from (string-match "\\([^ <]+\\)@" from))
  3889. (match-string 1 from)
  3890. "nobody")
  3891. gnus-article-save-directory)))
  3892. (defun article-verify-x-pgp-sig ()
  3893. "Verify X-PGP-Sig."
  3894. ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
  3895. (interactive)
  3896. (if (gnus-buffer-live-p gnus-original-article-buffer)
  3897. (let ((sig (with-current-buffer gnus-original-article-buffer
  3898. (gnus-fetch-field "X-PGP-Sig")))
  3899. items info headers)
  3900. (when (and sig
  3901. mml2015-use
  3902. (mml2015-clear-verify-function))
  3903. (with-temp-buffer
  3904. (insert-buffer-substring gnus-original-article-buffer)
  3905. (setq items (split-string sig))
  3906. (message-narrow-to-head)
  3907. (let ((inhibit-point-motion-hooks t)
  3908. (case-fold-search t))
  3909. ;; Don't verify multiple headers.
  3910. (setq headers (mapconcat (lambda (header)
  3911. (concat header ": "
  3912. (mail-fetch-field header)
  3913. "\n"))
  3914. (split-string (nth 1 items) ",") "")))
  3915. (delete-region (point-min) (point-max))
  3916. (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
  3917. (insert "X-Signed-Headers: " (nth 1 items) "\n")
  3918. (insert headers)
  3919. (widen)
  3920. (forward-line)
  3921. (while (not (eobp))
  3922. (if (looking-at "^-")
  3923. (insert "- "))
  3924. (forward-line))
  3925. (insert "\n-----BEGIN PGP SIGNATURE-----\n")
  3926. (insert "Version: " (car items) "\n\n")
  3927. (insert (mapconcat 'identity (cddr items) "\n"))
  3928. (insert "\n-----END PGP SIGNATURE-----\n")
  3929. (let ((mm-security-handle (list (format "multipart/signed"))))
  3930. (mml2015-clean-buffer)
  3931. (let ((coding-system-for-write (or gnus-newsgroup-charset
  3932. 'iso-8859-1)))
  3933. (funcall (mml2015-clear-verify-function)))
  3934. (setq info
  3935. (or (mm-handle-multipart-ctl-parameter
  3936. mm-security-handle 'gnus-details)
  3937. (mm-handle-multipart-ctl-parameter
  3938. mm-security-handle 'gnus-info)))))
  3939. (when info
  3940. (let ((inhibit-read-only t) bface eface)
  3941. (save-restriction
  3942. (message-narrow-to-head)
  3943. (goto-char (point-max))
  3944. (forward-line -1)
  3945. (setq bface (get-text-property (point-at-bol) 'face)
  3946. eface (get-text-property (1- (point-at-eol)) 'face))
  3947. (message-remove-header "X-Gnus-PGP-Verify")
  3948. (if (re-search-forward "^X-PGP-Sig:" nil t)
  3949. (forward-line)
  3950. (goto-char (point-max)))
  3951. (narrow-to-region (point) (point))
  3952. (insert "X-Gnus-PGP-Verify: " info "\n")
  3953. (goto-char (point-min))
  3954. (forward-line)
  3955. (while (not (eobp))
  3956. (if (not (looking-at "^[ \t]"))
  3957. (insert " "))
  3958. (forward-line))
  3959. ;; Do highlighting.
  3960. (goto-char (point-min))
  3961. (when (looking-at "\\([^:]+\\): *")
  3962. (put-text-property (match-beginning 1) (1+ (match-end 1))
  3963. 'face bface)
  3964. (put-text-property (match-end 0) (point-max)
  3965. 'face eface)))))))))
  3966. (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
  3967. (defun article-verify-cancel-lock ()
  3968. "Verify Cancel-Lock header."
  3969. (interactive)
  3970. (if (gnus-buffer-live-p gnus-original-article-buffer)
  3971. (canlock-verify gnus-original-article-buffer)))
  3972. (eval-and-compile
  3973. (mapc
  3974. (lambda (func)
  3975. (let (afunc gfunc)
  3976. (if (consp func)
  3977. (setq afunc (car func)
  3978. gfunc (cdr func))
  3979. (setq afunc func
  3980. gfunc (intern (format "gnus-%s" func))))
  3981. (defalias gfunc
  3982. (when (fboundp afunc)
  3983. `(lambda (&optional interactive &rest args)
  3984. ,(documentation afunc t)
  3985. (interactive (list t))
  3986. (with-current-buffer gnus-article-buffer
  3987. (if interactive
  3988. (call-interactively ',afunc)
  3989. (apply ',afunc args))))))))
  3990. '(article-hide-headers
  3991. article-verify-x-pgp-sig
  3992. article-verify-cancel-lock
  3993. article-hide-boring-headers
  3994. article-treat-overstrike
  3995. article-treat-ansi-sequences
  3996. article-fill-long-lines
  3997. article-capitalize-sentences
  3998. article-remove-cr
  3999. article-remove-leading-whitespace
  4000. article-display-x-face
  4001. article-display-face
  4002. article-de-quoted-unreadable
  4003. article-de-base64-unreadable
  4004. article-decode-HZ
  4005. article-wash-html
  4006. article-unsplit-urls
  4007. article-hide-list-identifiers
  4008. article-strip-banner
  4009. article-babel
  4010. article-hide-pem
  4011. article-hide-signature
  4012. article-strip-headers-in-body
  4013. article-remove-trailing-blank-lines
  4014. article-strip-leading-blank-lines
  4015. article-strip-multiple-blank-lines
  4016. article-strip-leading-space
  4017. article-strip-trailing-space
  4018. article-strip-blank-lines
  4019. article-strip-all-blank-lines
  4020. article-date-local
  4021. article-date-english
  4022. article-date-iso8601
  4023. article-date-original
  4024. article-treat-date
  4025. article-date-ut
  4026. article-decode-mime-words
  4027. article-decode-charset
  4028. article-decode-encoded-words
  4029. article-date-user
  4030. article-date-lapsed
  4031. article-date-combined-lapsed
  4032. article-emphasize
  4033. article-treat-dumbquotes
  4034. article-treat-non-ascii
  4035. article-normalize-headers
  4036. ;;(article-show-all . gnus-article-show-all-headers)
  4037. )))
  4038. ;;;
  4039. ;;; Gnus article mode
  4040. ;;;
  4041. (put 'gnus-article-mode 'mode-class 'special)
  4042. (set-keymap-parent gnus-article-mode-map widget-keymap)
  4043. (gnus-define-keys gnus-article-mode-map
  4044. " " gnus-article-goto-next-page
  4045. "\177" gnus-article-goto-prev-page
  4046. [delete] gnus-article-goto-prev-page
  4047. [backspace] gnus-article-goto-prev-page
  4048. "\C-c^" gnus-article-refer-article
  4049. "h" gnus-article-show-summary
  4050. "s" gnus-article-show-summary
  4051. "\C-c\C-m" gnus-article-mail
  4052. "?" gnus-article-describe-briefly
  4053. "<" beginning-of-buffer
  4054. ">" end-of-buffer
  4055. "\C-c\C-i" gnus-info-find-node
  4056. "\C-c\C-b" gnus-bug
  4057. "R" gnus-article-reply-with-original
  4058. "F" gnus-article-followup-with-original
  4059. "\C-hk" gnus-article-describe-key
  4060. "\C-hc" gnus-article-describe-key-briefly
  4061. "\C-hb" gnus-article-describe-bindings
  4062. "e" gnus-article-read-summary-keys
  4063. "\C-d" gnus-article-read-summary-keys
  4064. "\M-*" gnus-article-read-summary-keys
  4065. "\M-#" gnus-article-read-summary-keys
  4066. "\M-^" gnus-article-read-summary-keys
  4067. "\M-g" gnus-article-read-summary-keys)
  4068. (substitute-key-definition
  4069. 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
  4070. (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
  4071. "W" gnus-article-wide-reply-with-original)
  4072. (if (featurep 'xemacs)
  4073. (set-keymap-default-binding gnus-article-send-map
  4074. 'gnus-article-read-summary-send-keys)
  4075. (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
  4076. (defun gnus-article-make-menu-bar ()
  4077. (unless (boundp 'gnus-article-commands-menu)
  4078. (gnus-summary-make-menu-bar))
  4079. (unless (boundp 'gnus-article-article-menu)
  4080. (easy-menu-define
  4081. gnus-article-article-menu gnus-article-mode-map ""
  4082. '("Article"
  4083. ["Scroll forwards" gnus-article-goto-next-page t]
  4084. ["Scroll backwards" gnus-article-goto-prev-page t]
  4085. ["Show summary" gnus-article-show-summary t]
  4086. ["Fetch Message-ID at point" gnus-article-refer-article t]
  4087. ["Mail to address at point" gnus-article-mail t]
  4088. ["Send a bug report" gnus-bug t]))
  4089. (easy-menu-define
  4090. gnus-article-treatment-menu gnus-article-mode-map ""
  4091. ;; Fixme: this should use :active (and maybe :visible).
  4092. '("Treatment"
  4093. ["Hide headers" gnus-article-hide-headers t]
  4094. ["Hide signature" gnus-article-hide-signature t]
  4095. ["Hide citation" gnus-article-hide-citation t]
  4096. ["Treat overstrike" gnus-article-treat-overstrike t]
  4097. ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
  4098. ["Remove carriage return" gnus-article-remove-cr t]
  4099. ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
  4100. ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
  4101. ["Remove base64" gnus-article-de-base64-unreadable t]
  4102. ["Treat html" gnus-article-wash-html t]
  4103. ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
  4104. ["Decode HZ" gnus-article-decode-HZ t]))
  4105. ;; Note "Commands" menu is defined in gnus-sum.el for consistency
  4106. ;; Note "Post" menu is defined in gnus-sum.el for consistency
  4107. (gnus-run-hooks 'gnus-article-menu-hook)))
  4108. (defvar bookmark-make-record-function)
  4109. (defvar shr-put-image-function)
  4110. (defun gnus-article-mode ()
  4111. "Major mode for displaying an article.
  4112. All normal editing commands are switched off.
  4113. The following commands are available in addition to all summary mode
  4114. commands:
  4115. \\<gnus-article-mode-map>
  4116. \\[gnus-article-next-page]\t Scroll the article one page forwards
  4117. \\[gnus-article-prev-page]\t Scroll the article one page backwards
  4118. \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
  4119. \\[gnus-article-show-summary]\t Display the summary buffer
  4120. \\[gnus-article-mail]\t Send a reply to the address near point
  4121. \\[gnus-article-describe-briefly]\t Describe the current mode briefly
  4122. \\[gnus-info-find-node]\t Go to the Gnus info node"
  4123. (interactive)
  4124. (kill-all-local-variables)
  4125. (gnus-simplify-mode-line)
  4126. (setq mode-name "Article")
  4127. (setq major-mode 'gnus-article-mode)
  4128. (make-local-variable 'minor-mode-alist)
  4129. (use-local-map gnus-article-mode-map)
  4130. (when (gnus-visual-p 'article-menu 'menu)
  4131. (gnus-article-make-menu-bar)
  4132. (when gnus-summary-tool-bar-map
  4133. (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
  4134. (gnus-update-format-specifications nil 'article-mode)
  4135. (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
  4136. (set (make-local-variable 'gnus-page-broken) nil)
  4137. (make-local-variable 'gnus-article-current-summary)
  4138. (make-local-variable 'gnus-article-mime-handles)
  4139. (make-local-variable 'gnus-article-decoded-p)
  4140. (make-local-variable 'gnus-article-mime-handle-alist)
  4141. (make-local-variable 'gnus-article-wash-types)
  4142. (make-local-variable 'gnus-article-image-alist)
  4143. (make-local-variable 'gnus-article-charset)
  4144. (make-local-variable 'gnus-article-ignored-charsets)
  4145. (set (make-local-variable 'bookmark-make-record-function)
  4146. 'gnus-summary-bookmark-make-record)
  4147. ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
  4148. ;; face.
  4149. (set (make-local-variable 'nobreak-char-display) nil)
  4150. ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
  4151. (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
  4152. (setq cursor-in-non-selected-windows nil)
  4153. (gnus-set-default-directory)
  4154. (buffer-disable-undo)
  4155. (setq buffer-read-only t
  4156. show-trailing-whitespace nil)
  4157. (set-syntax-table gnus-article-mode-syntax-table)
  4158. (mm-enable-multibyte)
  4159. (gnus-run-mode-hooks 'gnus-article-mode-hook))
  4160. (defun gnus-article-setup-buffer ()
  4161. "Initialize the article buffer."
  4162. (let* ((name (if gnus-single-article-buffer "*Article*"
  4163. (concat "*Article "
  4164. (gnus-group-decoded-name gnus-newsgroup-name)
  4165. "*")))
  4166. (original
  4167. (progn (string-match "\\*Article" name)
  4168. (concat " *Original Article"
  4169. (substring name (match-end 0))))))
  4170. (setq gnus-article-buffer name)
  4171. (setq gnus-original-article-buffer original)
  4172. (setq gnus-article-mime-handle-alist nil)
  4173. (with-current-buffer gnus-summary-buffer
  4174. ;; This might be a variable local to the summary buffer.
  4175. (unless gnus-single-article-buffer
  4176. (setq gnus-article-buffer name)
  4177. (setq gnus-original-article-buffer original)
  4178. (gnus-set-global-variables)))
  4179. (gnus-article-setup-highlight-words)
  4180. ;; Init original article buffer.
  4181. (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
  4182. (mm-enable-multibyte)
  4183. (setq major-mode 'gnus-original-article-mode)
  4184. (make-local-variable 'gnus-original-article))
  4185. (if (and (get-buffer name)
  4186. (with-current-buffer name
  4187. (if gnus-article-edit-mode
  4188. (if (y-or-n-p "Article mode edit in progress; discard? ")
  4189. (progn
  4190. (set-buffer-modified-p nil)
  4191. (gnus-kill-buffer name)
  4192. (message "")
  4193. nil)
  4194. (error "Action aborted"))
  4195. t)))
  4196. (with-current-buffer name
  4197. (set (make-local-variable 'gnus-article-edit-mode) nil)
  4198. (gnus-article-stop-animations)
  4199. (when gnus-article-mime-handles
  4200. (mm-destroy-parts gnus-article-mime-handles)
  4201. (setq gnus-article-mime-handles nil))
  4202. ;; Set it to nil in article-buffer!
  4203. (setq gnus-article-mime-handle-alist nil)
  4204. (buffer-disable-undo)
  4205. (setq buffer-read-only t)
  4206. (unless (eq major-mode 'gnus-article-mode)
  4207. (gnus-article-mode))
  4208. (setq truncate-lines gnus-article-truncate-lines)
  4209. (current-buffer))
  4210. (with-current-buffer (gnus-get-buffer-create name)
  4211. (gnus-article-mode)
  4212. (setq truncate-lines gnus-article-truncate-lines)
  4213. (make-local-variable 'gnus-summary-buffer)
  4214. (setq gnus-summary-buffer
  4215. (gnus-summary-buffer-name gnus-newsgroup-name))
  4216. (gnus-summary-set-local-parameters gnus-newsgroup-name)
  4217. (when article-lapsed-timer
  4218. (gnus-stop-date-timer))
  4219. (when gnus-article-update-date-headers
  4220. (gnus-start-date-timer gnus-article-update-date-headers))
  4221. (current-buffer)))))
  4222. (defun gnus-article-stop-animations ()
  4223. (dolist (timer (and (boundp 'timer-list)
  4224. timer-list))
  4225. (when (eq (elt timer 5) 'image-animate-timeout)
  4226. (cancel-timer timer))))
  4227. (defun gnus-stop-downloads ()
  4228. (when (boundp 'url-queue)
  4229. (set (intern "url-queue" obarray) nil)))
  4230. ;; Set article window start at LINE, where LINE is the number of lines
  4231. ;; from the head of the article.
  4232. (defun gnus-article-set-window-start (&optional line)
  4233. (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
  4234. (when article-window
  4235. (set-window-start
  4236. article-window
  4237. (with-current-buffer gnus-article-buffer
  4238. (goto-char (point-min))
  4239. (if (not line)
  4240. (point-min)
  4241. (gnus-message 6 "Moved to bookmark")
  4242. (search-forward "\n\n" nil t)
  4243. (forward-line line)
  4244. (point)))))))
  4245. (defun gnus-article-prepare (article &optional all-headers header)
  4246. "Prepare ARTICLE in article mode buffer.
  4247. ARTICLE should either be an article number or a Message-ID.
  4248. If ARTICLE is an id, HEADER should be the article headers.
  4249. If ALL-HEADERS is non-nil, no headers are hidden."
  4250. (save-excursion
  4251. ;; Make sure we start in a summary buffer.
  4252. (unless (eq major-mode 'gnus-summary-mode)
  4253. (set-buffer gnus-summary-buffer))
  4254. (setq gnus-summary-buffer (current-buffer))
  4255. (let* ((gnus-article (if header (mail-header-number header) article))
  4256. (summary-buffer (current-buffer))
  4257. (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
  4258. (group gnus-newsgroup-name)
  4259. result)
  4260. (save-excursion
  4261. (gnus-article-setup-buffer)
  4262. (set-buffer gnus-article-buffer)
  4263. ;; Deactivate active regions.
  4264. (when (and (boundp 'transient-mark-mode)
  4265. transient-mark-mode)
  4266. (setq mark-active nil))
  4267. (if (not (setq result (let ((inhibit-read-only t))
  4268. (gnus-request-article-this-buffer
  4269. article group))))
  4270. ;; There is no such article.
  4271. (save-excursion
  4272. (when (and (numberp article)
  4273. (not (memq article gnus-newsgroup-sparse)))
  4274. (setq gnus-article-current
  4275. (cons gnus-newsgroup-name article))
  4276. (set-buffer gnus-summary-buffer)
  4277. (setq gnus-current-article article)
  4278. (if (and (memq article gnus-newsgroup-undownloaded)
  4279. (not (gnus-online (gnus-find-method-for-group
  4280. gnus-newsgroup-name))))
  4281. (progn
  4282. (gnus-summary-set-agent-mark article)
  4283. (message "Message marked for downloading"))
  4284. (gnus-summary-mark-article article gnus-canceled-mark)
  4285. (unless (memq article gnus-newsgroup-sparse)
  4286. (gnus-error 1 "No such article (may have expired or been canceled)")))))
  4287. (if (or (eq result 'pseudo)
  4288. (eq result 'nneething))
  4289. (progn
  4290. (with-current-buffer summary-buffer
  4291. (push article gnus-newsgroup-history)
  4292. (setq gnus-last-article gnus-current-article
  4293. gnus-current-article 0
  4294. gnus-current-headers nil
  4295. gnus-article-current nil)
  4296. (if (eq result 'nneething)
  4297. (gnus-configure-windows 'summary)
  4298. (gnus-configure-windows 'article))
  4299. (gnus-set-global-variables))
  4300. (let ((gnus-article-mime-handle-alist-1
  4301. gnus-article-mime-handle-alist))
  4302. (gnus-set-mode-line 'article)))
  4303. ;; The result from the `request' was an actual article -
  4304. ;; or at least some text that is now displayed in the
  4305. ;; article buffer.
  4306. (when (and (numberp article)
  4307. (not (eq article gnus-current-article)))
  4308. ;; Seems like a new article has been selected.
  4309. ;; `gnus-current-article' must be an article number.
  4310. (with-current-buffer summary-buffer
  4311. (push article gnus-newsgroup-history)
  4312. (setq gnus-last-article gnus-current-article
  4313. gnus-current-article article
  4314. gnus-current-headers
  4315. (gnus-summary-article-header gnus-current-article)
  4316. gnus-article-current
  4317. (cons gnus-newsgroup-name gnus-current-article))
  4318. (unless (vectorp gnus-current-headers)
  4319. (setq gnus-current-headers nil))
  4320. (gnus-summary-goto-subject gnus-current-article)
  4321. (when (gnus-summary-show-thread)
  4322. ;; If the summary buffer really was folded, the
  4323. ;; previous goto may not actually have gone to
  4324. ;; the right article, but the thread root instead.
  4325. ;; So we go again.
  4326. (gnus-summary-goto-subject gnus-current-article))
  4327. (gnus-run-hooks 'gnus-mark-article-hook)
  4328. (gnus-set-mode-line 'summary)
  4329. (when (gnus-visual-p 'article-highlight 'highlight)
  4330. (gnus-run-hooks 'gnus-visual-mark-article-hook))
  4331. ;; Set the global newsgroup variables here.
  4332. (gnus-set-global-variables)
  4333. (setq gnus-have-all-headers
  4334. (or all-headers gnus-show-all-headers))))
  4335. (save-excursion
  4336. (gnus-configure-windows 'article))
  4337. (when (or (numberp article)
  4338. (stringp article))
  4339. (gnus-article-prepare-display)
  4340. ;; Do page break.
  4341. (goto-char (point-min))
  4342. (when gnus-break-pages
  4343. (gnus-narrow-to-page)))
  4344. (let ((gnus-article-mime-handle-alist-1
  4345. gnus-article-mime-handle-alist))
  4346. (gnus-set-mode-line 'article))
  4347. (article-goto-body)
  4348. (unless (bobp)
  4349. (forward-line -1))
  4350. (set-window-point (get-buffer-window (current-buffer)) (point))
  4351. (gnus-configure-windows 'article)
  4352. (gnus-run-hooks 'gnus-article-prepare-hook)
  4353. t))))))
  4354. ;;;###autoload
  4355. (defun gnus-article-prepare-display ()
  4356. "Make the current buffer look like a nice article."
  4357. ;; Hooks for getting information from the article.
  4358. ;; This hook must be called before being narrowed.
  4359. (let ((gnus-article-buffer (current-buffer))
  4360. buffer-read-only
  4361. (inhibit-read-only t))
  4362. (unless (eq major-mode 'gnus-article-mode)
  4363. (gnus-article-mode))
  4364. (setq buffer-read-only nil
  4365. gnus-article-wash-types nil
  4366. gnus-article-image-alist nil)
  4367. (gnus-run-hooks 'gnus-tmp-internal-hook)
  4368. (when gnus-display-mime-function
  4369. (funcall gnus-display-mime-function))))
  4370. ;;;
  4371. ;;; Gnus Sticky Article Mode
  4372. ;;;
  4373. (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
  4374. "Mode for sticky articles."
  4375. ;; Release bindings that won't work.
  4376. (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
  4377. gnus-sticky-article-mode-map)
  4378. (substitute-key-definition 'gnus-article-refer-article 'undefined
  4379. gnus-sticky-article-mode-map)
  4380. (dolist (k '("e" "h" "s" "F" "R"))
  4381. (define-key gnus-sticky-article-mode-map k nil))
  4382. (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
  4383. (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
  4384. (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
  4385. (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
  4386. (defun gnus-sticky-article (arg)
  4387. "Make the current article sticky.
  4388. If a prefix ARG is given, ask for a name for this sticky article buffer."
  4389. (interactive "P")
  4390. (gnus-summary-show-thread)
  4391. (gnus-summary-select-article nil nil 'pseudo)
  4392. (let (new-art-buf-name)
  4393. (gnus-eval-in-buffer-window gnus-article-buffer
  4394. (setq new-art-buf-name
  4395. (concat
  4396. "*Sticky Article: "
  4397. (if arg
  4398. (read-from-minibuffer "Sticky article buffer name: ")
  4399. (gnus-with-article-headers
  4400. (gnus-article-goto-header "subject")
  4401. (setq new-art-buf-name
  4402. (buffer-substring-no-properties
  4403. (line-beginning-position) (line-end-position)))
  4404. (goto-char (point-min))
  4405. (gnus-article-goto-header "from")
  4406. (setq new-art-buf-name
  4407. (concat
  4408. new-art-buf-name ", "
  4409. (buffer-substring-no-properties
  4410. (line-beginning-position) (line-end-position))))
  4411. (goto-char (point-min))
  4412. (gnus-article-goto-header "date")
  4413. (setq new-art-buf-name
  4414. (concat
  4415. new-art-buf-name ", "
  4416. (buffer-substring-no-properties
  4417. (line-beginning-position) (line-end-position))))))
  4418. "*"))
  4419. (if (and (gnus-buffer-live-p new-art-buf-name)
  4420. (with-current-buffer new-art-buf-name
  4421. (eq major-mode 'gnus-sticky-article-mode)))
  4422. (switch-to-buffer new-art-buf-name)
  4423. (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
  4424. (gnus-sticky-article-mode))
  4425. (setq gnus-article-buffer new-art-buf-name))
  4426. (gnus-summary-recenter)
  4427. (gnus-summary-position-point))
  4428. (defun gnus-kill-sticky-article-buffer (&optional buffer)
  4429. "Kill the given sticky article BUFFER.
  4430. If none is given, assume the current buffer and kill it if it has
  4431. `gnus-sticky-article-mode'."
  4432. (interactive)
  4433. (unless buffer
  4434. (setq buffer (current-buffer)))
  4435. (with-current-buffer buffer
  4436. (when (eq major-mode 'gnus-sticky-article-mode)
  4437. (gnus-kill-buffer buffer))))
  4438. (defun gnus-kill-sticky-article-buffers (arg)
  4439. "Kill all sticky article buffers.
  4440. If a prefix ARG is given, ask for confirmation."
  4441. (interactive "P")
  4442. (dolist (buf (gnus-buffers))
  4443. (with-current-buffer buf
  4444. (when (eq major-mode 'gnus-sticky-article-mode)
  4445. (if (not arg)
  4446. (gnus-kill-buffer buf)
  4447. (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
  4448. (gnus-kill-buffer buf)))))))
  4449. ;;;
  4450. ;;; Gnus MIME viewing functions
  4451. ;;;
  4452. (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
  4453. "Format of the MIME buttons.
  4454. Valid specifiers include:
  4455. %t The MIME type
  4456. %T MIME type, along with additional info
  4457. %n The `name' parameter
  4458. %d The description, if any
  4459. %l The length of the encoded part
  4460. %p The part identifier number
  4461. %e Dots if the part isn't displayed
  4462. General format specifiers can also be used. See Info node
  4463. `(gnus)Formatting Variables'.")
  4464. (defvar gnus-mime-button-line-format-alist
  4465. '((?t gnus-tmp-type ?s)
  4466. (?T gnus-tmp-type-long ?s)
  4467. (?n gnus-tmp-name ?s)
  4468. (?d gnus-tmp-description ?s)
  4469. (?p gnus-tmp-id ?s)
  4470. (?l gnus-tmp-length ?d)
  4471. (?e gnus-tmp-dots ?s)))
  4472. (defvar gnus-mime-button-commands
  4473. '((gnus-article-press-button "\r" "Toggle Display")
  4474. (gnus-mime-view-part "v" "View Interactively...")
  4475. (gnus-mime-view-part-as-type "t" "View As Type...")
  4476. (gnus-mime-view-part-as-charset "C" "View As charset...")
  4477. (gnus-mime-save-part "o" "Save...")
  4478. (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
  4479. (gnus-mime-replace-part "r" "Replace part")
  4480. (gnus-mime-delete-part "d" "Delete part")
  4481. (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
  4482. (gnus-mime-inline-part "i" "View As Text, In This Buffer")
  4483. (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
  4484. (gnus-mime-view-part-externally "e" "View Externally")
  4485. (gnus-mime-print-part "p" "Print")
  4486. (gnus-mime-pipe-part "|" "Pipe To Command...")
  4487. (gnus-mime-action-on-part "." "Take action on the part...")))
  4488. (defun gnus-article-mime-part-status ()
  4489. (if gnus-article-mime-handle-alist-1
  4490. (if (eq 1 (length gnus-article-mime-handle-alist-1))
  4491. " (1 part)"
  4492. (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
  4493. ""))
  4494. (defvar gnus-mime-button-map
  4495. (let ((map (make-sparse-keymap)))
  4496. (define-key map gnus-mouse-2 'gnus-article-push-button)
  4497. (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
  4498. (dolist (c gnus-mime-button-commands)
  4499. (define-key map (cadr c) (car c)))
  4500. map))
  4501. (easy-menu-define
  4502. gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
  4503. `("MIME Part"
  4504. ,@(mapcar (lambda (c)
  4505. (vector (caddr c) (car c) :active t))
  4506. gnus-mime-button-commands)))
  4507. (defvar gnus-url-button-commands
  4508. '((gnus-article-copy-string "u" "Copy URL to kill ring")))
  4509. (defvar gnus-url-button-map
  4510. (let ((map (make-sparse-keymap)))
  4511. (dolist (c gnus-url-button-commands)
  4512. (define-key map (cadr c) (car c)))
  4513. map))
  4514. (easy-menu-define
  4515. gnus-url-button-menu gnus-url-button-map "URL button menu."
  4516. `("Url Button"
  4517. ,@(mapcar (lambda (c)
  4518. (vector (caddr c) (car c) :active t))
  4519. gnus-url-button-commands)))
  4520. (defmacro gnus-bind-safe-url-regexp (&rest body)
  4521. "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
  4522. `(let ((mm-w3m-safe-url-regexp
  4523. (let ((group (if (and (eq major-mode 'gnus-article-mode)
  4524. (gnus-buffer-live-p
  4525. gnus-article-current-summary))
  4526. (with-current-buffer gnus-article-current-summary
  4527. gnus-newsgroup-name)
  4528. gnus-newsgroup-name)))
  4529. (if (cond ((not group)
  4530. ;; Maybe we're in a mml-preview buffer
  4531. ;; and no group is selected.
  4532. t)
  4533. ((stringp gnus-safe-html-newsgroups)
  4534. (string-match gnus-safe-html-newsgroups group))
  4535. ((consp gnus-safe-html-newsgroups)
  4536. (member group gnus-safe-html-newsgroups)))
  4537. nil
  4538. mm-w3m-safe-url-regexp))))
  4539. ,@body))
  4540. (defun gnus-mime-button-menu (event prefix)
  4541. "Construct a context-sensitive menu of MIME commands."
  4542. (interactive "e\nP")
  4543. (save-window-excursion
  4544. (let ((pos (event-start event)))
  4545. (select-window (posn-window pos))
  4546. (goto-char (posn-point pos))
  4547. (gnus-article-check-buffer)
  4548. (popup-menu gnus-mime-button-menu nil prefix))))
  4549. (defun gnus-mime-view-all-parts (&optional handles)
  4550. "View all the MIME parts."
  4551. (interactive)
  4552. (with-current-buffer gnus-article-buffer
  4553. (let ((handles (or handles gnus-article-mime-handles))
  4554. (mail-parse-charset gnus-newsgroup-charset)
  4555. (mail-parse-ignored-charsets
  4556. (with-current-buffer gnus-summary-buffer
  4557. gnus-newsgroup-ignored-charsets)))
  4558. (when handles
  4559. (mm-remove-parts handles)
  4560. (goto-char (point-min))
  4561. (or (search-forward "\n\n") (goto-char (point-max)))
  4562. (let ((inhibit-read-only t))
  4563. (delete-region (point) (point-max))
  4564. (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
  4565. (defun gnus-article-jump-to-part (n)
  4566. "Jump to MIME part N."
  4567. (interactive "P")
  4568. (let ((parts (with-current-buffer gnus-article-buffer
  4569. (length gnus-article-mime-handle-alist))))
  4570. (when (zerop parts)
  4571. (error "No such part"))
  4572. (pop-to-buffer gnus-article-buffer)
  4573. (or n
  4574. (setq n (if (= parts 1)
  4575. 1
  4576. (read-number (format "Jump to part (1..%s): " parts)))))
  4577. (unless (and (integerp n) (<= n parts) (>= n 1))
  4578. (setq n
  4579. (progn
  4580. (gnus-message 7 "Invalid part `%s', using %s instead."
  4581. n parts)
  4582. parts)))
  4583. (gnus-message 9 "Jumping to part %s." n)
  4584. (cond ((>= gnus-auto-select-part 1)
  4585. (while (and (<= n parts)
  4586. (not (gnus-article-goto-part n)))
  4587. (setq n (1+ n))))
  4588. ((< gnus-auto-select-part 0)
  4589. (while (and (>= n 1)
  4590. (not (gnus-article-goto-part n)))
  4591. (setq n (1- n))))
  4592. (t
  4593. (gnus-article-goto-part n)))))
  4594. (defvar gnus-mime-buttonized-part-id nil
  4595. "ID of a mime part that should be buttonized.
  4596. `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
  4597. (eval-when-compile
  4598. (defsubst gnus-article-edit-part (handles &optional current-id)
  4599. "Edit an article in order to delete a mime part.
  4600. This function is exclusively used by `gnus-mime-save-part-and-strip'
  4601. and `gnus-mime-delete-part', and not provided at run-time normally."
  4602. (gnus-article-edit-article
  4603. `(lambda ()
  4604. (buffer-disable-undo)
  4605. (erase-buffer)
  4606. (let ((mail-parse-charset (or gnus-article-charset
  4607. ',gnus-newsgroup-charset))
  4608. (mail-parse-ignored-charsets
  4609. (or gnus-article-ignored-charsets
  4610. ',gnus-newsgroup-ignored-charsets))
  4611. (mbl mml-buffer-list))
  4612. (setq mml-buffer-list nil)
  4613. (insert-buffer-substring gnus-original-article-buffer)
  4614. (mime-to-mml ',handles)
  4615. (setq gnus-article-mime-handles nil)
  4616. (let ((mbl1 mml-buffer-list))
  4617. (setq mml-buffer-list mbl)
  4618. (set (make-local-variable 'mml-buffer-list) mbl1))
  4619. (gnus-make-local-hook 'kill-buffer-hook)
  4620. (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
  4621. `(lambda (no-highlight)
  4622. (let ((mail-parse-charset (or gnus-article-charset
  4623. ',gnus-newsgroup-charset))
  4624. (message-options message-options)
  4625. (message-options-set-recipient)
  4626. (mail-parse-ignored-charsets
  4627. (or gnus-article-ignored-charsets
  4628. ',gnus-newsgroup-ignored-charsets)))
  4629. (mml-to-mime)
  4630. (mml-destroy-buffers)
  4631. (remove-hook 'kill-buffer-hook
  4632. 'mml-destroy-buffers t)
  4633. (kill-local-variable 'mml-buffer-list))
  4634. (gnus-summary-edit-article-done
  4635. ,(or (mail-header-references gnus-current-headers) "")
  4636. ,(gnus-group-read-only-p)
  4637. ,gnus-summary-buffer no-highlight))
  4638. t)
  4639. ;; Force buttonizing this part.
  4640. (let ((gnus-mime-buttonized-part-id current-id))
  4641. (gnus-article-edit-done))
  4642. (gnus-configure-windows 'article)
  4643. (when (and current-id (integerp gnus-auto-select-part))
  4644. (gnus-article-jump-to-part
  4645. (min (max (+ current-id gnus-auto-select-part) 1)
  4646. (with-current-buffer gnus-article-buffer
  4647. (length gnus-article-mime-handle-alist)))))))
  4648. (defun gnus-mime-replace-part (file)
  4649. "Replace MIME part under point with an external body."
  4650. ;; Useful if file has already been saved to disk
  4651. (interactive
  4652. (list
  4653. (read-file-name "Replace MIME part with file: "
  4654. (or mm-default-directory default-directory)
  4655. nil nil)))
  4656. (gnus-mime-save-part-and-strip file))
  4657. (defun gnus-mime-save-part-and-strip (&optional file)
  4658. "Save the MIME part under point then replace it with an external body.
  4659. If FILE is given, use it for the external part."
  4660. (interactive)
  4661. (gnus-article-check-buffer)
  4662. (when (gnus-group-read-only-p)
  4663. (error "The current group does not support deleting of parts"))
  4664. (when (mm-complicated-handles gnus-article-mime-handles)
  4665. (error "\
  4666. The current article has a complicated MIME structure, giving up..."))
  4667. (let* ((data (get-text-property (point) 'gnus-data))
  4668. (id (get-text-property (point) 'gnus-part))
  4669. param
  4670. (handles gnus-article-mime-handles))
  4671. (unless file
  4672. (setq file
  4673. (and data (mm-save-part data "Delete MIME part and save to: "))))
  4674. (when file
  4675. (with-current-buffer (mm-handle-buffer data)
  4676. (erase-buffer)
  4677. (insert "Content-Type: " (mm-handle-media-type data))
  4678. (mml-insert-parameter-string (cdr (mm-handle-type data))
  4679. '(charset))
  4680. ;; Add a filename for the sake of saving the part again.
  4681. (mml-insert-parameter
  4682. (mail-header-encode-parameter "name" (file-name-nondirectory file)))
  4683. (insert "\n")
  4684. (insert "Content-ID: " (message-make-message-id) "\n")
  4685. (insert "Content-Transfer-Encoding: binary\n")
  4686. (insert "\n"))
  4687. (setcdr data
  4688. (cdr (mm-make-handle nil
  4689. `("message/external-body"
  4690. (access-type . "LOCAL-FILE")
  4691. (name . ,file)))))
  4692. ;; (set-buffer gnus-summary-buffer)
  4693. (gnus-article-edit-part handles id))))
  4694. ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
  4695. ;; parts...>') but with stripping would be nice.
  4696. (defun gnus-mime-delete-part ()
  4697. "Delete the MIME part under point.
  4698. Replace it with some information about the removed part."
  4699. (interactive)
  4700. (gnus-article-check-buffer)
  4701. (when (gnus-group-read-only-p)
  4702. (error "The current group does not support deleting of parts"))
  4703. (when (mm-complicated-handles gnus-article-mime-handles)
  4704. (error "\
  4705. The current article has a complicated MIME structure, giving up..."))
  4706. (when (or gnus-expert-user
  4707. (gnus-yes-or-no-p "\
  4708. Deleting parts may malfunction or destroy the article; continue? "))
  4709. (let* ((data (get-text-property (point) 'gnus-data))
  4710. (id (get-text-property (point) 'gnus-part))
  4711. (handles gnus-article-mime-handles)
  4712. (description
  4713. (let ((desc (mm-handle-description data)))
  4714. (when desc
  4715. (mail-decode-encoded-word-string desc))))
  4716. (filename (or (mm-handle-filename data) "(none)"))
  4717. (type (mm-handle-media-type data)))
  4718. (unless data
  4719. (error "No MIME part under point"))
  4720. (with-current-buffer (mm-handle-buffer data)
  4721. (let ((bsize (buffer-size)))
  4722. (erase-buffer)
  4723. (insert
  4724. (concat
  4725. ",----\n"
  4726. "| The following attachment has been deleted:\n"
  4727. "|\n"
  4728. "| Type: " type "\n"
  4729. "| Filename: " filename "\n"
  4730. "| Size (encoded): " (format "%s byte%s\n"
  4731. bsize (if (= bsize 1)
  4732. ""
  4733. "s"))
  4734. (when description
  4735. (concat "| Description: " description "\n"))
  4736. "`----\n"))
  4737. (setcdr data
  4738. (cdr (mm-make-handle
  4739. nil `("text/plain" (charset . gnus-decoded)) nil nil
  4740. (list "attachment")
  4741. (format "Deleted attachment (%s bytes)" bsize))))))
  4742. ;; (set-buffer gnus-summary-buffer)
  4743. (gnus-article-edit-part handles id))))
  4744. (defun gnus-mime-save-part ()
  4745. "Save the MIME part under point."
  4746. (interactive)
  4747. (gnus-article-check-buffer)
  4748. (let ((data (get-text-property (point) 'gnus-data)))
  4749. (when data
  4750. (mm-save-part data))))
  4751. (defun gnus-mime-pipe-part (&optional cmd)
  4752. "Pipe the MIME part under point to a process.
  4753. Use CMD as the process."
  4754. (interactive)
  4755. (gnus-article-check-buffer)
  4756. (let ((data (get-text-property (point) 'gnus-data)))
  4757. (when data
  4758. (mm-pipe-part data cmd))))
  4759. (defun gnus-mime-view-part ()
  4760. "Interactively choose a viewing method for the MIME part under point."
  4761. (interactive)
  4762. (gnus-article-check-buffer)
  4763. (let ((data (get-text-property (point) 'gnus-data)))
  4764. (when data
  4765. (setq gnus-article-mime-handles
  4766. (mm-merge-handles
  4767. gnus-article-mime-handles (setq data (copy-sequence data))))
  4768. (mm-interactively-view-part data))))
  4769. (defun gnus-mime-view-part-as-type-internal ()
  4770. (gnus-article-check-buffer)
  4771. (let* ((handle (get-text-property (point) 'gnus-data))
  4772. (name (or
  4773. ;; Content-Type: foo/bar; name=...
  4774. (mail-content-type-get (mm-handle-type handle) 'name)
  4775. ;; Content-Disposition: attachment; filename=...
  4776. (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
  4777. (def-type (and name (mm-default-file-encoding name))))
  4778. (or (and def-type (cons def-type 0))
  4779. (and handle
  4780. (equal (mm-handle-media-supertype handle) "text")
  4781. '("text/plain" . 0))
  4782. '("application/octet-stream" . 0))))
  4783. (defun gnus-mime-view-part-as-type (&optional mime-type pred)
  4784. "Choose a MIME media type, and view the part as such.
  4785. If non-nil, PRED is a predicate to use during completion to limit the
  4786. available media-types."
  4787. (interactive)
  4788. (unless mime-type
  4789. (setq mime-type
  4790. (let ((default (gnus-mime-view-part-as-type-internal)))
  4791. (gnus-completing-read
  4792. "View as MIME type"
  4793. (if pred
  4794. (gnus-remove-if-not pred (mailcap-mime-types))
  4795. (mailcap-mime-types))
  4796. nil nil nil
  4797. (car default)))))
  4798. (gnus-article-check-buffer)
  4799. (let ((handle (get-text-property (point) 'gnus-data)))
  4800. (when handle
  4801. (when (equal (mm-handle-media-type handle) "message/external-body")
  4802. (unless (mm-handle-cache handle)
  4803. (mm-extern-cache-contents handle))
  4804. (setq handle (mm-handle-cache handle)))
  4805. (setq handle
  4806. (mm-make-handle (mm-handle-buffer handle)
  4807. (cons mime-type (cdr (mm-handle-type handle)))
  4808. (mm-handle-encoding handle)
  4809. (mm-handle-undisplayer handle)
  4810. (mm-handle-disposition handle)
  4811. (mm-handle-description handle)
  4812. nil
  4813. (mm-handle-id handle)))
  4814. (setq gnus-article-mime-handles
  4815. (mm-merge-handles gnus-article-mime-handles handle))
  4816. (when (mm-handle-displayed-p handle)
  4817. (mm-remove-part handle))
  4818. (gnus-mm-display-part handle))))
  4819. (defun gnus-mime-copy-part (&optional handle arg)
  4820. "Put the MIME part under point into a new buffer.
  4821. If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
  4822. are decompressed."
  4823. (interactive (list nil current-prefix-arg))
  4824. (gnus-article-check-buffer)
  4825. (unless handle
  4826. (setq handle (get-text-property (point) 'gnus-data)))
  4827. (when handle
  4828. (let ((filename (mm-handle-filename handle))
  4829. contents dont-decode charset coding-system)
  4830. (mm-with-unibyte-buffer
  4831. (mm-insert-part handle)
  4832. (setq contents (or (condition-case nil
  4833. (mm-decompress-buffer filename nil 'sig)
  4834. (error
  4835. (setq dont-decode t)
  4836. nil))
  4837. (buffer-string))))
  4838. (setq filename (cond (filename (file-name-nondirectory filename))
  4839. (dont-decode "*raw data*")
  4840. (t "*decoded*")))
  4841. (cond
  4842. (dont-decode)
  4843. ((not arg)
  4844. (unless (setq charset (mail-content-type-get
  4845. (mm-handle-type handle) 'charset))
  4846. (unless (setq coding-system (mm-with-unibyte-buffer
  4847. (insert contents)
  4848. (mm-find-buffer-file-coding-system)))
  4849. (setq charset gnus-newsgroup-charset))))
  4850. ((numberp arg)
  4851. (setq charset (or (cdr (assq arg
  4852. gnus-summary-show-article-charset-alist))
  4853. (mm-read-coding-system "Charset: ")))))
  4854. (switch-to-buffer (generate-new-buffer filename))
  4855. (if (or coding-system
  4856. (and charset
  4857. (setq coding-system (mm-charset-to-coding-system charset))
  4858. (not (eq coding-system 'ascii))))
  4859. (progn
  4860. (mm-enable-multibyte)
  4861. (insert (mm-decode-coding-string contents coding-system))
  4862. (setq buffer-file-coding-system
  4863. (if (boundp 'last-coding-system-used)
  4864. (symbol-value 'last-coding-system-used)
  4865. coding-system)))
  4866. (mm-disable-multibyte)
  4867. (insert contents)
  4868. (setq buffer-file-coding-system mm-binary-coding-system))
  4869. ;; We do it this way to make `normal-mode' set the appropriate mode.
  4870. (unwind-protect
  4871. (progn
  4872. (setq buffer-file-name (expand-file-name filename))
  4873. (normal-mode))
  4874. (setq buffer-file-name nil))
  4875. (goto-char (point-min)))))
  4876. (defun gnus-mime-print-part (&optional handle filename)
  4877. "Print the MIME part under point."
  4878. (interactive (list nil (ps-print-preprint current-prefix-arg)))
  4879. (gnus-article-check-buffer)
  4880. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  4881. (contents (and handle (mm-get-part handle)))
  4882. (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
  4883. (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
  4884. (when contents
  4885. (if printer
  4886. (unwind-protect
  4887. (progn
  4888. (mm-save-part-to-file handle file)
  4889. (call-process shell-file-name nil
  4890. (generate-new-buffer " *mm*")
  4891. nil
  4892. shell-command-switch
  4893. (mm-mailcap-command
  4894. printer file (mm-handle-type handle))))
  4895. (delete-file file))
  4896. (with-temp-buffer
  4897. (insert contents)
  4898. (gnus-print-buffer))
  4899. (ps-despool filename)))))
  4900. (defun gnus-mime-inline-part (&optional handle arg)
  4901. "Insert the MIME part under point into the current buffer.
  4902. Compressed files like .gz and .bz2 are decompressed."
  4903. (interactive (list nil current-prefix-arg))
  4904. (gnus-article-check-buffer)
  4905. (unless handle
  4906. (setq handle (get-text-property (point) 'gnus-data)))
  4907. (when handle
  4908. (let ((b (point))
  4909. (inhibit-read-only t)
  4910. contents charset coding-system)
  4911. (if (and (not arg) (mm-handle-undisplayer handle))
  4912. (mm-remove-part handle)
  4913. (mm-with-unibyte-buffer
  4914. (mm-insert-part handle)
  4915. (setq contents
  4916. (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
  4917. (buffer-string))))
  4918. (cond
  4919. ((not arg)
  4920. (unless (setq charset (mail-content-type-get
  4921. (mm-handle-type handle) 'charset))
  4922. (unless (setq coding-system
  4923. (mm-with-unibyte-buffer
  4924. (insert contents)
  4925. (mm-find-buffer-file-coding-system)))
  4926. (setq charset gnus-newsgroup-charset))))
  4927. ((numberp arg)
  4928. (if (mm-handle-undisplayer handle)
  4929. (mm-remove-part handle))
  4930. (setq charset
  4931. (or (cdr (assq arg
  4932. gnus-summary-show-article-charset-alist))
  4933. (mm-read-coding-system "Charset: "))))
  4934. (t
  4935. (if (mm-handle-undisplayer handle)
  4936. (mm-remove-part handle))))
  4937. (forward-line 2)
  4938. (mm-display-inline handle)
  4939. (goto-char b)))))
  4940. (defun gnus-mime-set-charset-parameters (handle charset)
  4941. "Set CHARSET to parameters in HANDLE.
  4942. CHARSET may either be a string or a symbol."
  4943. (unless (stringp charset)
  4944. (setq charset (symbol-name charset)))
  4945. (if (stringp (car handle))
  4946. (dolist (h (cdr handle))
  4947. (gnus-mime-set-charset-parameters h charset))
  4948. (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
  4949. "message/external-body")
  4950. (progn
  4951. (unless (mm-handle-cache handle)
  4952. (mm-extern-cache-contents handle))
  4953. (mm-handle-cache handle))
  4954. handle)))
  4955. (param (assq 'charset (cdr type))))
  4956. (if param
  4957. (setcdr param charset)
  4958. (setcdr type (cons (cons 'charset charset) (cdr type)))))))
  4959. (defun gnus-mime-view-part-as-charset (&optional handle arg)
  4960. "Insert the MIME part under point into the current buffer using the
  4961. specified charset."
  4962. (interactive (list nil current-prefix-arg))
  4963. (gnus-article-check-buffer)
  4964. (let ((handle (or handle (get-text-property (point) 'gnus-data)))
  4965. (fun (get-text-property (point) 'gnus-callback))
  4966. (gnus-newsgroup-ignored-charsets 'gnus-all)
  4967. charset form preferred parts)
  4968. (when handle
  4969. (when (prog1
  4970. (and fun
  4971. (setq charset
  4972. (or (cdr (assq
  4973. arg
  4974. gnus-summary-show-article-charset-alist))
  4975. (mm-read-coding-system "Charset: "))))
  4976. (if (mm-handle-undisplayer handle)
  4977. (mm-remove-part handle)))
  4978. (gnus-mime-set-charset-parameters handle charset)
  4979. (when (and (consp (setq form (cdr-safe fun)))
  4980. (setq form (ignore-errors
  4981. (assq 'gnus-mime-display-alternative form)))
  4982. (setq preferred (caddr form))
  4983. (progn
  4984. (when (eq (car preferred) 'quote)
  4985. (setq preferred (cadr preferred)))
  4986. (not (equal preferred
  4987. (get-text-property (point) 'gnus-data))))
  4988. (setq parts (get-text-property (point) 'gnus-part))
  4989. (setq parts (cdr (assq parts
  4990. gnus-article-mime-handle-alist)))
  4991. (equal (mm-handle-media-type parts) "multipart/alternative")
  4992. (setq parts (reverse (cdr parts))))
  4993. (setcar (cddr form)
  4994. (list 'quote (or (cadr (member preferred parts))
  4995. (car parts)))))
  4996. (funcall fun handle)))))
  4997. (defun gnus-mime-view-part-externally (&optional handle)
  4998. "View the MIME part under point with an external viewer."
  4999. (interactive)
  5000. (gnus-article-check-buffer)
  5001. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  5002. (mm-user-display-methods nil)
  5003. (mm-inlined-types nil)
  5004. (mail-parse-charset gnus-newsgroup-charset)
  5005. (mail-parse-ignored-charsets
  5006. (with-current-buffer gnus-summary-buffer
  5007. gnus-newsgroup-ignored-charsets))
  5008. (type (mm-handle-media-type handle))
  5009. (method (mailcap-mime-info type))
  5010. (mm-enable-external t))
  5011. (if (not (stringp method))
  5012. (gnus-mime-view-part-as-type
  5013. nil (lambda (type) (stringp (mailcap-mime-info type))))
  5014. (when handle
  5015. (mm-display-part handle nil t)))))
  5016. (defun gnus-mime-view-part-internally (&optional handle)
  5017. "View the MIME part under point with an internal viewer.
  5018. If no internal viewer is available, use an external viewer."
  5019. (interactive)
  5020. (gnus-article-check-buffer)
  5021. (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
  5022. (mm-inlined-types '(".*"))
  5023. (mm-inline-large-images t)
  5024. (mail-parse-charset gnus-newsgroup-charset)
  5025. (mail-parse-ignored-charsets
  5026. (with-current-buffer gnus-summary-buffer
  5027. gnus-newsgroup-ignored-charsets))
  5028. (inhibit-read-only t))
  5029. (if (not (mm-inlinable-p handle))
  5030. (gnus-mime-view-part-as-type
  5031. nil (lambda (type) (mm-inlinable-p handle type)))
  5032. (when handle
  5033. (gnus-bind-safe-url-regexp (mm-display-part handle))))))
  5034. (defun gnus-mime-action-on-part (&optional action)
  5035. "Do something with the MIME attachment at \(point\)."
  5036. (interactive
  5037. (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
  5038. (gnus-article-check-buffer)
  5039. (let ((action-pair (assoc action gnus-mime-action-alist)))
  5040. (if action-pair
  5041. (funcall (cdr action-pair)))))
  5042. (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
  5043. "Call FUNCTION on MIME part N.
  5044. Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
  5045. If INTERACTIVE, call FUNCTION interactively."
  5046. (let (window frame)
  5047. ;; Check whether the article is displayed.
  5048. (unless (and (gnus-buffer-live-p gnus-article-buffer)
  5049. (setq window (get-buffer-window gnus-article-buffer t))
  5050. (frame-visible-p (setq frame (window-frame window))))
  5051. (error "No article is displayed"))
  5052. (with-current-buffer gnus-article-buffer
  5053. ;; Check whether the article displays the right contents.
  5054. (unless (with-current-buffer gnus-summary-buffer
  5055. (eq gnus-current-article (gnus-summary-article-number)))
  5056. (error "You should select the right article first"))
  5057. (if n
  5058. (setq n (prefix-numeric-value n))
  5059. (let ((pt (point)))
  5060. (setq n (or (get-text-property pt 'gnus-part)
  5061. (and (not (bobp))
  5062. (get-text-property (1- pt) 'gnus-part))
  5063. (get-text-property (prog2
  5064. (forward-line 1)
  5065. (point)
  5066. (goto-char pt))
  5067. 'gnus-part)
  5068. (get-text-property
  5069. (or (and (setq pt (previous-single-property-change
  5070. pt 'gnus-part))
  5071. (1- pt))
  5072. (next-single-property-change (point) 'gnus-part)
  5073. (point))
  5074. 'gnus-part)
  5075. 1))))
  5076. ;; Check whether the specified part exists.
  5077. (when (> n (length gnus-article-mime-handle-alist))
  5078. (error "No such part")))
  5079. (unless
  5080. (progn
  5081. ;; To select the window is needed so that the cursor
  5082. ;; might be visible on the MIME button.
  5083. (select-window (prog1
  5084. window
  5085. (setq window (selected-window))
  5086. ;; Article may be displayed in the other frame.
  5087. (gnus-select-frame-set-input-focus
  5088. (prog1
  5089. frame
  5090. (setq frame (selected-frame))))))
  5091. (when (gnus-article-goto-part n)
  5092. ;; We point the cursor and the arrow at the MIME button
  5093. ;; when the `function' prompt the user for something.
  5094. (unless (and (pos-visible-in-window-p)
  5095. (> (count-lines (point) (window-end))
  5096. (/ (1- (window-height)) 3)))
  5097. (recenter (/ (1- (window-height)) 3)))
  5098. (let ((cursor-in-non-selected-windows t)
  5099. (overlay-arrow-string "=>")
  5100. (overlay-arrow-position (point-marker)))
  5101. (unwind-protect
  5102. (cond
  5103. ((and no-handle interactive)
  5104. (call-interactively function))
  5105. (no-handle
  5106. (funcall function))
  5107. (interactive
  5108. (call-interactively
  5109. function (get-text-property (point) 'gnus-data)))
  5110. (t
  5111. (funcall function
  5112. (get-text-property (point) 'gnus-data))))
  5113. (set-marker overlay-arrow-position nil)
  5114. (unless gnus-auto-select-part
  5115. (gnus-select-frame-set-input-focus frame)
  5116. (select-window window))))
  5117. t))
  5118. (if gnus-inhibit-mime-unbuttonizing
  5119. ;; This is the default though the program shouldn't reach here.
  5120. (error "No such part")
  5121. ;; The part which doesn't have the MIME button is selected.
  5122. ;; So, we display all the buttons and redo it.
  5123. (let ((gnus-inhibit-mime-unbuttonizing t))
  5124. (gnus-summary-show-article)
  5125. (gnus-article-part-wrapper n function no-handle))))))
  5126. (defun gnus-article-pipe-part (n)
  5127. "Pipe MIME part N, which is the numerical prefix."
  5128. (interactive "P")
  5129. (gnus-article-part-wrapper n 'mm-pipe-part))
  5130. (defun gnus-article-save-part (n)
  5131. "Save MIME part N, which is the numerical prefix."
  5132. (interactive "P")
  5133. (gnus-article-part-wrapper n 'mm-save-part))
  5134. (defun gnus-article-interactively-view-part (n)
  5135. "View MIME part N interactively, which is the numerical prefix."
  5136. (interactive "P")
  5137. (gnus-article-part-wrapper n 'mm-interactively-view-part))
  5138. (defun gnus-article-copy-part (n)
  5139. "Copy MIME part N, which is the numerical prefix."
  5140. (interactive "P")
  5141. (gnus-article-part-wrapper n 'gnus-mime-copy-part))
  5142. (defun gnus-article-view-part-as-charset (n)
  5143. "View MIME part N using a specified charset.
  5144. N is the numerical prefix."
  5145. (interactive "P")
  5146. (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
  5147. (defun gnus-article-view-part-externally (n)
  5148. "View MIME part N externally, which is the numerical prefix."
  5149. (interactive "P")
  5150. (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
  5151. (defun gnus-article-inline-part (n)
  5152. "Inline MIME part N, which is the numerical prefix."
  5153. (interactive "P")
  5154. (gnus-article-part-wrapper n 'gnus-mime-inline-part))
  5155. (defun gnus-article-save-part-and-strip (n)
  5156. "Save MIME part N and replace it with an external body.
  5157. N is the numerical prefix."
  5158. (interactive "P")
  5159. (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
  5160. (defun gnus-article-replace-part (n)
  5161. "Replace MIME part N with an external body.
  5162. N is the numerical prefix."
  5163. (interactive "P")
  5164. (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
  5165. (defun gnus-article-delete-part (n)
  5166. "Delete MIME part N and add some information about the removed part.
  5167. N is the numerical prefix."
  5168. (interactive "P")
  5169. (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
  5170. (defun gnus-article-view-part-as-type (n)
  5171. "Choose a MIME media type, and view part N as such.
  5172. N is the numerical prefix."
  5173. (interactive "P")
  5174. (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
  5175. (defun gnus-article-mime-match-handle-first (condition)
  5176. (if condition
  5177. (let (n)
  5178. (dolist (ihandle gnus-article-mime-handle-alist)
  5179. (if (and (cond
  5180. ((functionp condition)
  5181. (funcall condition (cdr ihandle)))
  5182. ((eq condition 'undisplayed)
  5183. (not (or (mm-handle-undisplayer (cdr ihandle))
  5184. (equal (mm-handle-media-type (cdr ihandle))
  5185. "multipart/alternative"))))
  5186. ((eq condition 'undisplayed-alternative)
  5187. (not (mm-handle-undisplayer (cdr ihandle))))
  5188. (t t))
  5189. (gnus-article-goto-part (car ihandle))
  5190. (or (not n) (< (car ihandle) n)))
  5191. (setq n (car ihandle))))
  5192. (or n 1))
  5193. 1))
  5194. (defun gnus-article-view-part (&optional n)
  5195. "View MIME part N, which is the numerical prefix.
  5196. If the part is already shown, hide the part. If N is nil, view
  5197. all parts."
  5198. (interactive "P")
  5199. (with-current-buffer gnus-article-buffer
  5200. (or (numberp n) (setq n (gnus-article-mime-match-handle-first
  5201. gnus-article-mime-match-handle-function)))
  5202. (when (> n (length gnus-article-mime-handle-alist))
  5203. (error "No such part"))
  5204. (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
  5205. (when (gnus-article-goto-part n)
  5206. (if (equal (car handle) "multipart/alternative")
  5207. (gnus-article-press-button)
  5208. (when (eq (gnus-mm-display-part handle) 'internal)
  5209. (gnus-set-window-start)))))))
  5210. (defsubst gnus-article-mime-total-parts ()
  5211. (if (bufferp (car gnus-article-mime-handles))
  5212. 1 ;; single part
  5213. (1- (length gnus-article-mime-handles))))
  5214. (defun gnus-mm-display-part (handle)
  5215. "Display HANDLE and fix MIME button."
  5216. (let ((id (get-text-property (point) 'gnus-part))
  5217. (point (point))
  5218. (inhibit-read-only t))
  5219. (forward-line 1)
  5220. (prog1
  5221. (let ((window (selected-window))
  5222. (mail-parse-charset gnus-newsgroup-charset)
  5223. (mail-parse-ignored-charsets
  5224. (if (gnus-buffer-live-p gnus-summary-buffer)
  5225. (with-current-buffer gnus-summary-buffer
  5226. gnus-newsgroup-ignored-charsets)
  5227. nil)))
  5228. (save-excursion
  5229. (unwind-protect
  5230. (let ((win (gnus-get-buffer-window (current-buffer) t))
  5231. (beg (point)))
  5232. (when win
  5233. (select-window win))
  5234. (goto-char point)
  5235. (forward-line)
  5236. (if (mm-handle-displayed-p handle)
  5237. ;; This will remove the part.
  5238. (mm-display-part handle)
  5239. (save-restriction
  5240. (narrow-to-region (point)
  5241. (if (eobp) (point) (1+ (point))))
  5242. (gnus-bind-safe-url-regexp (mm-display-part handle))
  5243. ;; We narrow to the part itself and
  5244. ;; then call the treatment functions.
  5245. (goto-char (point-min))
  5246. (forward-line 1)
  5247. (narrow-to-region (point) (point-max))
  5248. (gnus-treat-article
  5249. nil id
  5250. (gnus-article-mime-total-parts)
  5251. (mm-handle-media-type handle)))))
  5252. (if (window-live-p window)
  5253. (select-window window)))))
  5254. (goto-char point)
  5255. (gnus-delete-line)
  5256. (gnus-insert-mime-button
  5257. handle id (list (mm-handle-displayed-p handle)))
  5258. (goto-char point))))
  5259. (defun gnus-article-goto-part (n)
  5260. "Go to MIME part N."
  5261. (when gnus-break-pages
  5262. (widen))
  5263. (prog1
  5264. (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
  5265. part handle end next handles)
  5266. (when start
  5267. (goto-char start)
  5268. (if (setq handle (get-text-property start 'gnus-data))
  5269. start
  5270. ;; Go to the displayed subpart, assuming this is
  5271. ;; multipart/alternative.
  5272. (setq part start
  5273. end (point-at-eol))
  5274. (while (and (not handle)
  5275. part
  5276. (< part end)
  5277. (setq next (text-property-not-all part end
  5278. 'gnus-data nil)))
  5279. (setq part next
  5280. handle (get-text-property part 'gnus-data))
  5281. (push (cons handle part) handles)
  5282. (unless (mm-handle-displayed-p handle)
  5283. (setq handle nil
  5284. part (text-property-any part end 'gnus-data nil))))
  5285. (unless handle
  5286. ;; No subpart is displayed, so we find preferred one.
  5287. (setq part
  5288. (cdr (assq (mm-preferred-alternative
  5289. (nreverse (mapcar 'car handles)))
  5290. handles))))
  5291. (if part
  5292. (goto-char (1+ part))
  5293. start))))
  5294. (when gnus-break-pages
  5295. (gnus-narrow-to-page))))
  5296. (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
  5297. (let ((gnus-tmp-name
  5298. (or (mm-handle-filename handle)
  5299. (mail-content-type-get (mm-handle-type handle) 'url)
  5300. ""))
  5301. (gnus-tmp-type (mm-handle-media-type handle))
  5302. (gnus-tmp-description (or (mm-handle-description handle) ""))
  5303. (gnus-tmp-dots
  5304. (if (if displayed (car displayed)
  5305. (mm-handle-displayed-p handle))
  5306. "" "..."))
  5307. (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
  5308. (buffer-size)))
  5309. gnus-tmp-type-long b e)
  5310. (when (string-match ".*/" gnus-tmp-name)
  5311. (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
  5312. (setq gnus-tmp-type-long (concat gnus-tmp-type
  5313. (and (not (equal gnus-tmp-name ""))
  5314. (concat "; " gnus-tmp-name))))
  5315. (unless (equal gnus-tmp-description "")
  5316. (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
  5317. (unless (bolp)
  5318. (insert "\n"))
  5319. (setq b (point))
  5320. (gnus-eval-format
  5321. gnus-mime-button-line-format gnus-mime-button-line-format-alist
  5322. `(keymap ,gnus-mime-button-map
  5323. gnus-callback gnus-mm-display-part
  5324. gnus-part ,gnus-tmp-id
  5325. article-type annotation
  5326. gnus-data ,handle
  5327. rear-nonsticky t))
  5328. (setq e (if (bolp)
  5329. ;; Exclude a newline.
  5330. (1- (point))
  5331. (point)))
  5332. (when gnus-article-button-face
  5333. (gnus-overlay-put (gnus-make-overlay b e nil t)
  5334. 'face gnus-article-button-face))
  5335. (widget-convert-button
  5336. 'link b e
  5337. :mime-handle handle
  5338. :action 'gnus-widget-press-button
  5339. :button-keymap gnus-mime-button-map
  5340. :help-echo
  5341. (lambda (widget)
  5342. ;; Needed to properly clear the message due to a bug in
  5343. ;; wid-edit (XEmacs only).
  5344. (if (boundp 'help-echo-owns-message)
  5345. (setq help-echo-owns-message t))
  5346. (format
  5347. "%S: %s the MIME part; %S: more options"
  5348. (aref gnus-mouse-2 0)
  5349. (if (mm-handle-displayed-p (widget-get widget :mime-handle))
  5350. "hide" "show")
  5351. (aref gnus-down-mouse-3 0))))))
  5352. (defun gnus-widget-press-button (elems el)
  5353. (goto-char (widget-get elems :from))
  5354. (gnus-article-press-button))
  5355. (defvar gnus-displaying-mime nil)
  5356. (defun gnus-display-mime (&optional ihandles)
  5357. "Display the MIME parts."
  5358. (save-excursion
  5359. (save-selected-window
  5360. (let ((window (get-buffer-window gnus-article-buffer))
  5361. (point (point)))
  5362. (when window
  5363. (select-window window)
  5364. ;; We have to do this since selecting the window
  5365. ;; may change the point. So we set the window point.
  5366. (set-window-point window point)))
  5367. (let ((handles ihandles)
  5368. (inhibit-read-only t)
  5369. handle)
  5370. (cond (handles)
  5371. ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
  5372. (when gnus-article-emulate-mime
  5373. (mm-uu-dissect-text-parts handles)))
  5374. (gnus-article-emulate-mime
  5375. (setq handles (mm-uu-dissect))))
  5376. (when (and (not ihandles)
  5377. (not gnus-displaying-mime))
  5378. ;; Top-level call; we clean up.
  5379. (when gnus-article-mime-handles
  5380. (mm-destroy-parts gnus-article-mime-handles)
  5381. (setq gnus-article-mime-handle-alist nil));; A trick.
  5382. (setq gnus-article-mime-handles handles)
  5383. ;; We allow users to glean info from the handles.
  5384. (when gnus-article-mime-part-function
  5385. (gnus-mime-part-function handles)))
  5386. (if (and handles
  5387. (or (not (stringp (car handles)))
  5388. (cdr handles)))
  5389. (progn
  5390. (when (and (not ihandles)
  5391. (not gnus-displaying-mime))
  5392. ;; Clean up for mime parts.
  5393. (article-goto-body)
  5394. (delete-region (point) (point-max)))
  5395. (let ((gnus-displaying-mime t))
  5396. (gnus-mime-display-part handles)))
  5397. (save-restriction
  5398. (article-goto-body)
  5399. (narrow-to-region (point) (point-max))
  5400. (gnus-treat-article nil 1 1 "text/plain")
  5401. (widen)))
  5402. (unless ihandles
  5403. ;; Highlight the headers.
  5404. (save-excursion
  5405. (save-restriction
  5406. (article-goto-body)
  5407. (narrow-to-region (point-min) (point))
  5408. (gnus-article-save-original-date
  5409. (gnus-treat-article 'head)))))))
  5410. ;; Cope with broken MIME messages.
  5411. (goto-char (point-max))
  5412. (unless (bolp)
  5413. (insert "\n"))))
  5414. (defcustom gnus-mime-display-multipart-as-mixed nil
  5415. "Display \"multipart\" parts as \"multipart/mixed\".
  5416. If t, it overrides nil values of
  5417. `gnus-mime-display-multipart-alternative-as-mixed' and
  5418. `gnus-mime-display-multipart-related-as-mixed'."
  5419. :group 'gnus-article-mime
  5420. :type 'boolean)
  5421. (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
  5422. "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
  5423. :version "22.1"
  5424. :group 'gnus-article-mime
  5425. :type 'boolean)
  5426. (defcustom gnus-mime-display-multipart-related-as-mixed nil
  5427. "Display \"multipart/related\" parts as \"multipart/mixed\".
  5428. If displaying \"text/html\" is discouraged \(see
  5429. `mm-discouraged-alternatives'\) images or other material inside a
  5430. \"multipart/related\" part might be overlooked when this variable is nil."
  5431. :version "22.1"
  5432. :group 'gnus-article-mime
  5433. :type 'boolean)
  5434. (defun gnus-mime-display-part (handle)
  5435. (cond
  5436. ;; Maybe a broken MIME message.
  5437. ((null handle))
  5438. ;; Single part.
  5439. ((not (stringp (car handle)))
  5440. (gnus-mime-display-single handle))
  5441. ;; User-defined multipart
  5442. ((cdr (assoc (car handle) gnus-mime-multipart-functions))
  5443. (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
  5444. handle))
  5445. ;; multipart/alternative
  5446. ((and (equal (car handle) "multipart/alternative")
  5447. (not (or gnus-mime-display-multipart-as-mixed
  5448. gnus-mime-display-multipart-alternative-as-mixed)))
  5449. (let ((id (1+ (length gnus-article-mime-handle-alist))))
  5450. (push (cons id handle) gnus-article-mime-handle-alist)
  5451. (gnus-mime-display-alternative (cdr handle) nil nil id)))
  5452. ;; multipart/related
  5453. ((and (equal (car handle) "multipart/related")
  5454. (not (or gnus-mime-display-multipart-as-mixed
  5455. gnus-mime-display-multipart-related-as-mixed)))
  5456. ;;;!!!We should find the start part, but we just default
  5457. ;;;!!!to the first part.
  5458. ;;(gnus-mime-display-part (cadr handle))
  5459. ;;;!!! Most multipart/related is an HTML message plus images.
  5460. ;;;!!! Unfortunately we are unable to let W3 display those
  5461. ;;;!!! included images, so we just display it as a mixed multipart.
  5462. ;;(gnus-mime-display-mixed (cdr handle))
  5463. ;;;!!! No, w3 can display everything just fine.
  5464. (gnus-mime-display-part (cadr handle)))
  5465. ((equal (car handle) "multipart/signed")
  5466. (gnus-add-wash-type 'signed)
  5467. (gnus-mime-display-security handle))
  5468. ((equal (car handle) "multipart/encrypted")
  5469. (gnus-add-wash-type 'encrypted)
  5470. (gnus-mime-display-security handle))
  5471. ;; Other multiparts are handled like multipart/mixed.
  5472. (t
  5473. (gnus-mime-display-mixed (cdr handle)))))
  5474. (defun gnus-mime-part-function (handles)
  5475. (if (stringp (car handles))
  5476. (mapcar 'gnus-mime-part-function (cdr handles))
  5477. (funcall gnus-article-mime-part-function handles)))
  5478. (defun gnus-mime-display-mixed (handles)
  5479. (mapcar 'gnus-mime-display-part handles))
  5480. (defun gnus-mime-display-single (handle)
  5481. (let ((type (mm-handle-media-type handle))
  5482. (ignored gnus-ignored-mime-types)
  5483. (not-attachment t)
  5484. (move nil)
  5485. display text)
  5486. (catch 'ignored
  5487. (progn
  5488. (while ignored
  5489. (when (string-match (pop ignored) type)
  5490. (throw 'ignored nil)))
  5491. (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
  5492. (with-current-buffer gnus-summary-buffer
  5493. gnus-inhibit-images)
  5494. gnus-inhibit-images)
  5495. (string-match "\\`image/" type)))
  5496. (setq not-attachment
  5497. (and (not (mm-inline-override-p handle))
  5498. (or (not (mm-handle-disposition handle))
  5499. (equal (car (mm-handle-disposition handle))
  5500. "inline")
  5501. (mm-attachment-override-p handle))))
  5502. (mm-automatic-display-p handle)
  5503. (or (and
  5504. (mm-inlinable-p handle)
  5505. (mm-inlined-p handle))
  5506. (mm-automatic-external-display-p type)))
  5507. (setq display t)
  5508. (when (equal (mm-handle-media-supertype handle) "text")
  5509. (setq text t)))
  5510. (let ((id (1+ (length gnus-article-mime-handle-alist)))
  5511. beg)
  5512. (push (cons id handle) gnus-article-mime-handle-alist)
  5513. (when (and display
  5514. (equal (mm-handle-media-supertype handle) "message"))
  5515. (insert-char
  5516. ?\n
  5517. (cond ((not (bolp)) 2)
  5518. ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
  5519. (t 1))))
  5520. (when (or (not display)
  5521. (not (gnus-unbuttonized-mime-type-p type))
  5522. (eq id gnus-mime-buttonized-part-id))
  5523. (gnus-insert-mime-button
  5524. handle id (list (or display (and not-attachment text))))
  5525. (gnus-article-insert-newline)
  5526. ;; Remember modify the number of forward lines.
  5527. (setq move t))
  5528. (setq beg (point))
  5529. (cond
  5530. (display
  5531. (when move
  5532. (forward-line -1)
  5533. (setq beg (point)))
  5534. (let ((mail-parse-charset gnus-newsgroup-charset)
  5535. (mail-parse-ignored-charsets
  5536. (save-excursion (condition-case ()
  5537. (set-buffer gnus-summary-buffer)
  5538. (error))
  5539. gnus-newsgroup-ignored-charsets)))
  5540. (gnus-bind-safe-url-regexp (mm-display-part handle t)))
  5541. (goto-char (point-max)))
  5542. ((and text not-attachment)
  5543. (when move
  5544. (forward-line -1)
  5545. (setq beg (point)))
  5546. (gnus-article-insert-newline)
  5547. (mm-display-inline handle)
  5548. (goto-char (point-max))))
  5549. ;; Do highlighting.
  5550. (save-excursion
  5551. (save-restriction
  5552. (narrow-to-region beg (point))
  5553. (if (eq handle gnus-article-mime-handles)
  5554. ;; The format=flowed case.
  5555. (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
  5556. ;; Don't count signature parts that are never displayed.
  5557. ;; The part number should be re-calculated supposing this
  5558. ;; might be a message/rfc822 part.
  5559. (let (handles)
  5560. (dolist (part gnus-article-mime-handles)
  5561. (unless (or (stringp part)
  5562. (equal (car (mm-handle-type part))
  5563. "application/pgp-signature"))
  5564. (push part handles)))
  5565. (gnus-treat-article
  5566. nil (length (memq handle handles)) (length handles)
  5567. (mm-handle-media-type handle)))))))))))
  5568. (defun gnus-unbuttonized-mime-type-p (type)
  5569. "Say whether TYPE is to be unbuttonized."
  5570. (unless gnus-inhibit-mime-unbuttonizing
  5571. (when (catch 'found
  5572. (let ((types gnus-unbuttonized-mime-types))
  5573. (while types
  5574. (when (string-match (pop types) type)
  5575. (throw 'found t)))))
  5576. (not (catch 'found
  5577. (let ((types gnus-buttonized-mime-types))
  5578. (while types
  5579. (when (string-match (pop types) type)
  5580. (throw 'found t)))))))))
  5581. (defun gnus-article-insert-newline ()
  5582. "Insert a newline, but mark it as undeletable."
  5583. (gnus-put-text-property
  5584. (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
  5585. (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
  5586. (let* ((preferred (or preferred (mm-preferred-alternative handles)))
  5587. (ihandles handles)
  5588. (point (point))
  5589. handle (inhibit-read-only t) from props begend not-pref)
  5590. (save-window-excursion
  5591. (save-restriction
  5592. (when ibegend
  5593. (narrow-to-region (car ibegend)
  5594. (or (cdr ibegend)
  5595. (progn
  5596. (goto-char (car ibegend))
  5597. (forward-line 2)
  5598. (point))))
  5599. (delete-region (point-min) (point-max))
  5600. (mm-remove-parts handles))
  5601. (setq begend (list (point-marker)))
  5602. ;; Do the toggle.
  5603. (unless (setq not-pref (cadr (member preferred ihandles)))
  5604. (setq not-pref (car ihandles)))
  5605. (when (or ibegend
  5606. (not preferred)
  5607. (not (gnus-unbuttonized-mime-type-p
  5608. "multipart/alternative")))
  5609. (gnus-add-text-properties
  5610. (setq from (point))
  5611. (progn
  5612. (insert (format "%d. " id))
  5613. (point))
  5614. `(gnus-callback
  5615. (lambda (handles)
  5616. (unless ,(not ibegend)
  5617. (setq gnus-article-mime-handle-alist
  5618. ',gnus-article-mime-handle-alist))
  5619. (gnus-mime-display-alternative
  5620. ',ihandles ',not-pref ',begend ,id))
  5621. keymap ,gnus-mime-button-map
  5622. ,gnus-mouse-face-prop ,gnus-article-mouse-face
  5623. face ,gnus-article-button-face
  5624. gnus-part ,id
  5625. article-type multipart
  5626. rear-nonsticky t))
  5627. (widget-convert-button 'link from (point)
  5628. :action 'gnus-widget-press-button
  5629. :button-keymap gnus-widget-button-keymap)
  5630. ;; Do the handles
  5631. (while (setq handle (pop handles))
  5632. (gnus-add-text-properties
  5633. (setq from (point))
  5634. (progn
  5635. (insert (format "(%c) %-18s"
  5636. (if (equal handle preferred) ?* ? )
  5637. (mm-handle-media-type handle)))
  5638. (point))
  5639. `(gnus-callback
  5640. (lambda (handles)
  5641. (unless ,(not ibegend)
  5642. (setq gnus-article-mime-handle-alist
  5643. ',gnus-article-mime-handle-alist))
  5644. (gnus-mime-display-alternative
  5645. ',ihandles ',handle ',begend ,id))
  5646. keymap ,gnus-mime-button-map
  5647. ,gnus-mouse-face-prop ,gnus-article-mouse-face
  5648. face ,gnus-article-button-face
  5649. gnus-part ,id
  5650. gnus-data ,handle
  5651. rear-nonsticky t))
  5652. (widget-convert-button 'link from (point)
  5653. :action 'gnus-widget-press-button
  5654. :button-keymap gnus-widget-button-keymap)
  5655. (insert " "))
  5656. (insert "\n\n"))
  5657. (when preferred
  5658. (if (stringp (car preferred))
  5659. (gnus-display-mime preferred)
  5660. (let ((mail-parse-charset gnus-newsgroup-charset)
  5661. (mail-parse-ignored-charsets
  5662. (with-current-buffer gnus-summary-buffer
  5663. gnus-newsgroup-ignored-charsets)))
  5664. (gnus-bind-safe-url-regexp (mm-display-part preferred))
  5665. ;; Do highlighting.
  5666. (save-excursion
  5667. (save-restriction
  5668. (narrow-to-region (car begend) (point-max))
  5669. (gnus-treat-article
  5670. nil (length gnus-article-mime-handle-alist)
  5671. (gnus-article-mime-total-parts)
  5672. (mm-handle-media-type preferred))))))
  5673. (goto-char (point-max))
  5674. (setcdr begend (point-marker)))))
  5675. (when ibegend
  5676. (goto-char point))))
  5677. (defconst gnus-article-wash-status-strings
  5678. (let ((alist '((cite "c" "Possible hidden citation text"
  5679. " " "All citation text visible")
  5680. (headers "h" "Hidden headers"
  5681. " " "All headers visible.")
  5682. (pgp "p" "Encrypted or signed message status hidden"
  5683. " " "No hidden encryption nor digital signature status")
  5684. (signature "s" "Signature has been hidden"
  5685. " " "Signature is visible")
  5686. (overstrike "o" "Overstrike (^H) characters applied"
  5687. " " "No overstrike characters applied")
  5688. (emphasis "e" "/*_Emphasis_*/ characters applied"
  5689. " " "No /*_emphasis_*/ characters applied")))
  5690. result)
  5691. (dolist (entry alist result)
  5692. (let ((key (nth 0 entry))
  5693. (on (copy-sequence (nth 1 entry)))
  5694. (on-help (nth 2 entry))
  5695. (off (copy-sequence (nth 3 entry)))
  5696. (off-help (nth 4 entry)))
  5697. (put-text-property 0 1 'help-echo on-help on)
  5698. (put-text-property 0 1 'help-echo off-help off)
  5699. (push (list key on off) result))))
  5700. "Alist of strings describing wash status in the mode line.
  5701. Each entry has the form (KEY ON OF), where the KEY is a symbol
  5702. representing the particular washing function, ON is the string to use
  5703. in the article mode line when the washing function is active, and OFF
  5704. is the string to use when it is inactive.")
  5705. (defun gnus-article-wash-status-entry (key value)
  5706. (let ((entry (assoc key gnus-article-wash-status-strings)))
  5707. (if value (nth 1 entry) (nth 2 entry))))
  5708. (defun gnus-article-wash-status ()
  5709. "Return a string which display status of article washing."
  5710. (with-current-buffer gnus-article-buffer
  5711. (let ((cite (memq 'cite gnus-article-wash-types))
  5712. (headers (memq 'headers gnus-article-wash-types))
  5713. (boring (memq 'boring-headers gnus-article-wash-types))
  5714. (pgp (memq 'pgp gnus-article-wash-types))
  5715. (pem (memq 'pem gnus-article-wash-types))
  5716. (signed (memq 'signed gnus-article-wash-types))
  5717. (encrypted (memq 'encrypted gnus-article-wash-types))
  5718. (signature (memq 'signature gnus-article-wash-types))
  5719. (overstrike (memq 'overstrike gnus-article-wash-types))
  5720. (emphasis (memq 'emphasis gnus-article-wash-types)))
  5721. (concat
  5722. (gnus-article-wash-status-entry 'cite cite)
  5723. (gnus-article-wash-status-entry 'headers (or headers boring))
  5724. (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
  5725. (gnus-article-wash-status-entry 'signature signature)
  5726. (gnus-article-wash-status-entry 'overstrike overstrike)
  5727. (gnus-article-wash-status-entry 'emphasis emphasis)))))
  5728. (defun gnus-add-wash-type (type)
  5729. "Add a washing of TYPE to the current status."
  5730. (add-to-list 'gnus-article-wash-types type))
  5731. (defun gnus-delete-wash-type (type)
  5732. "Add a washing of TYPE to the current status."
  5733. (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
  5734. (defun gnus-add-image (category image)
  5735. "Add IMAGE of CATEGORY to the list of displayed images."
  5736. (let ((entry (assq category gnus-article-image-alist)))
  5737. (unless entry
  5738. (setq entry (list category))
  5739. (push entry gnus-article-image-alist))
  5740. (nconc entry (list image))))
  5741. (defun gnus-delete-images (category)
  5742. "Delete all images in CATEGORY."
  5743. (let ((entry (assq category gnus-article-image-alist)))
  5744. (dolist (image (cdr entry))
  5745. (gnus-remove-image image category))
  5746. (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
  5747. (gnus-delete-wash-type category)))
  5748. (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
  5749. (defun gnus-article-maybe-hide-headers ()
  5750. "Hide unwanted headers if `gnus-have-all-headers' is nil.
  5751. Provided for backwards compatibility."
  5752. (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
  5753. (not (with-current-buffer gnus-summary-buffer
  5754. gnus-have-all-headers)))
  5755. (not gnus-inhibit-hiding))
  5756. (gnus-article-hide-headers)))
  5757. (declare-function shr-put-image "shr" (data alt))
  5758. (defun gnus-shr-put-image (data alt)
  5759. "Put image DATA with a string ALT. Enable image to be deleted."
  5760. (let ((image (shr-put-image data (propertize (or alt "*")
  5761. 'gnus-image-category 'shr))))
  5762. (when image
  5763. (gnus-add-image 'shr image))))
  5764. ;;; Article savers.
  5765. (defun gnus-output-to-file (file-name)
  5766. "Append the current article to a file named FILE-NAME.
  5767. If `gnus-article-save-coding-system' is non-nil, it is used to encode
  5768. text and used as the value of the coding cookie which is added to the
  5769. top of a file. Otherwise, this function saves a raw article without
  5770. the coding cookie."
  5771. (let* ((artbuf (current-buffer))
  5772. (file-name-coding-system nnmail-pathname-coding-system)
  5773. (coding gnus-article-save-coding-system)
  5774. (coding-system-for-read (if coding
  5775. nil ;; Rely on the coding cookie.
  5776. mm-text-coding-system))
  5777. (coding-system-for-write (or coding
  5778. mm-text-coding-system-for-write
  5779. mm-text-coding-system))
  5780. (exists (file-exists-p file-name)))
  5781. (with-temp-buffer
  5782. (when exists
  5783. (insert-file-contents file-name)
  5784. (goto-char (point-min))
  5785. ;; Remove the existing coding cookie.
  5786. (when (looking-at "X-Gnus-Coding-System: .+\n\n")
  5787. (delete-region (match-beginning 0) (match-end 0))))
  5788. (goto-char (point-max))
  5789. (insert-buffer-substring artbuf)
  5790. ;; Append newline at end of the buffer as separator, and then
  5791. ;; save it to file.
  5792. (goto-char (point-max))
  5793. (insert "\n")
  5794. (when coding
  5795. ;; If the coding system is not suitable to encode the text,
  5796. ;; ask a user for a proper one.
  5797. (when (fboundp 'select-safe-coding-system)
  5798. (setq coding (coding-system-base
  5799. (save-window-excursion
  5800. (select-safe-coding-system (point-min) (point-max)
  5801. coding))))
  5802. (setq coding-system-for-write
  5803. (or (cdr (assq coding '((mule-utf-8 . utf-8))))
  5804. coding)))
  5805. (goto-char (point-min))
  5806. ;; Add the coding cookie.
  5807. (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
  5808. coding-system-for-write)))
  5809. (if exists
  5810. (progn
  5811. (write-region (point-min) (point-max) file-name nil 'no-message)
  5812. (message "Appended to %s" file-name))
  5813. (write-region (point-min) (point-max) file-name))))
  5814. t)
  5815. (defun gnus-narrow-to-page (&optional arg)
  5816. "Narrow the article buffer to a page.
  5817. If given a numerical ARG, move forward ARG pages."
  5818. (interactive "P")
  5819. (setq arg (if arg (prefix-numeric-value arg) 0))
  5820. (with-current-buffer gnus-article-buffer
  5821. (widen)
  5822. ;; Remove any old next/prev buttons.
  5823. (when (gnus-visual-p 'page-marker)
  5824. (let ((inhibit-read-only t))
  5825. (gnus-remove-text-with-property 'gnus-prev)
  5826. (gnus-remove-text-with-property 'gnus-next)))
  5827. (let (st nd pt)
  5828. (when (save-excursion
  5829. (cond ((< arg 0)
  5830. (if (re-search-backward page-delimiter nil 'move (abs arg))
  5831. (prog1
  5832. (setq nd (match-beginning 0)
  5833. pt nd)
  5834. (when (re-search-backward page-delimiter nil t)
  5835. (setq st (match-end 0))))
  5836. (when (re-search-forward page-delimiter nil t)
  5837. (setq nd (match-beginning 0)
  5838. pt (point-min)))))
  5839. ((> arg 0)
  5840. (if (re-search-forward page-delimiter nil 'move arg)
  5841. (prog1
  5842. (setq st (match-end 0)
  5843. pt st)
  5844. (when (re-search-forward page-delimiter nil t)
  5845. (setq nd (match-beginning 0))))
  5846. (when (re-search-backward page-delimiter nil t)
  5847. (setq st (match-end 0)
  5848. pt (point-max)))))
  5849. (t
  5850. (when (re-search-backward page-delimiter nil t)
  5851. (goto-char (setq st (match-end 0))))
  5852. (when (re-search-forward page-delimiter nil t)
  5853. (setq nd (match-beginning 0)))
  5854. (or st nd))))
  5855. (setq gnus-page-broken t)
  5856. (when pt (goto-char pt))
  5857. (narrow-to-region (or st (point-min)) (or nd (point-max)))
  5858. (when (gnus-visual-p 'page-marker)
  5859. (save-excursion
  5860. (when nd
  5861. (goto-char nd)
  5862. (gnus-insert-next-page-button))
  5863. (when st
  5864. (goto-char st)
  5865. (gnus-insert-prev-page-button))))))))
  5866. ;; Article mode commands
  5867. (defun gnus-article-goto-next-page ()
  5868. "Show the next page of the article."
  5869. (interactive)
  5870. (when (gnus-article-next-page)
  5871. (goto-char (point-min))
  5872. (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
  5873. (defun gnus-article-goto-prev-page ()
  5874. "Show the previous page of the article."
  5875. (interactive)
  5876. (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
  5877. (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
  5878. (gnus-article-prev-page nil)))
  5879. ;; This is cleaner but currently breaks `gnus-pick-mode':
  5880. ;;
  5881. ;; (defun gnus-article-goto-next-page ()
  5882. ;; "Show the next page of the article."
  5883. ;; (interactive)
  5884. ;; (gnus-eval-in-buffer-window gnus-summary-buffer
  5885. ;; (gnus-summary-next-page)))
  5886. ;;
  5887. ;; (defun gnus-article-goto-prev-page ()
  5888. ;; "Show the next page of the article."
  5889. ;; (interactive)
  5890. ;; (gnus-eval-in-buffer-window gnus-summary-buffer
  5891. ;; (gnus-summary-prev-page)))
  5892. (defun gnus-article-next-page (&optional lines)
  5893. "Show the next page of the current article.
  5894. If end of article, return non-nil. Otherwise return nil.
  5895. Argument LINES specifies lines to be scrolled up."
  5896. (interactive "p")
  5897. (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
  5898. (if (and (not (and gnus-article-over-scroll
  5899. (> (count-lines (window-start) (point-max))
  5900. (if (featurep 'xemacs)
  5901. (or lines (1- (window-height)))
  5902. (+ (or lines (1- (window-height))) scroll-margin)))))
  5903. (save-excursion
  5904. (end-of-line)
  5905. (and (pos-visible-in-window-p) ;Not continuation line.
  5906. (>= (point) (point-max)))))
  5907. ;; Nothing in this page.
  5908. (if (or (not gnus-page-broken)
  5909. (save-excursion
  5910. (save-restriction
  5911. (widen)
  5912. (forward-line)
  5913. (eobp)))) ;Real end-of-buffer?
  5914. (progn
  5915. (when gnus-article-over-scroll
  5916. (gnus-article-next-page-1 lines))
  5917. t) ;Nothing more.
  5918. (gnus-narrow-to-page 1) ;Go to next page.
  5919. nil)
  5920. ;; More in this page.
  5921. (gnus-article-next-page-1 lines)
  5922. nil))
  5923. (defun gnus-article-beginning-of-window ()
  5924. "Move point to the beginning of the window.
  5925. In Emacs, the point is placed at the line number which `scroll-margin'
  5926. specifies."
  5927. (if (featurep 'xemacs)
  5928. (move-to-window-line 0)
  5929. ;; There is an obscure bug in Emacs that makes it impossible to
  5930. ;; scroll past big pictures in the article buffer. Try to fix
  5931. ;; this by adding a sanity check by counting the lines visible.
  5932. (when (> (count-lines (window-start) (window-end)) 30)
  5933. (move-to-window-line
  5934. (min (max 0 scroll-margin)
  5935. (max 1 (- (window-height)
  5936. (if mode-line-format 1 0)
  5937. (if header-line-format 1 0)
  5938. 2)))))))
  5939. (defun gnus-article-next-page-1 (lines)
  5940. (condition-case ()
  5941. (let ((scroll-in-place nil)
  5942. (auto-window-vscroll nil))
  5943. (scroll-up lines))
  5944. (end-of-buffer
  5945. ;; Long lines may cause an end-of-buffer error.
  5946. (goto-char (point-max))))
  5947. (gnus-article-beginning-of-window))
  5948. (defun gnus-article-prev-page (&optional lines)
  5949. "Show previous page of current article.
  5950. Argument LINES specifies lines to be scrolled down."
  5951. (interactive "p")
  5952. (move-to-window-line 0)
  5953. (if (and gnus-page-broken
  5954. (bobp)
  5955. (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
  5956. (progn
  5957. (gnus-narrow-to-page -1) ;Go to previous page.
  5958. (goto-char (point-max))
  5959. (recenter (if gnus-article-over-scroll
  5960. (if lines
  5961. (max (if (featurep 'xemacs)
  5962. lines
  5963. (+ lines scroll-margin))
  5964. 3)
  5965. (- (window-height) 2))
  5966. -1)))
  5967. (prog1
  5968. (condition-case ()
  5969. (let ((scroll-in-place nil))
  5970. (scroll-down lines))
  5971. (beginning-of-buffer
  5972. (goto-char (point-min))))
  5973. (gnus-article-beginning-of-window))))
  5974. (defun gnus-article-only-boring-p ()
  5975. "Decide whether there is only boring text remaining in the article.
  5976. Something \"interesting\" is a word of at least two letters that does
  5977. not have a face in `gnus-article-boring-faces'."
  5978. (when (and gnus-article-skip-boring
  5979. (boundp 'gnus-article-boring-faces)
  5980. (symbol-value 'gnus-article-boring-faces))
  5981. (save-excursion
  5982. (let ((inhibit-point-motion-hooks t))
  5983. (catch 'only-boring
  5984. (while (re-search-forward "\\b\\w\\w" nil t)
  5985. (forward-char -1)
  5986. (when (not (gnus-intersection
  5987. (gnus-faces-at (point))
  5988. (symbol-value 'gnus-article-boring-faces)))
  5989. (throw 'only-boring nil)))
  5990. (throw 'only-boring t))))))
  5991. (defun gnus-article-refer-article ()
  5992. "Read article specified by message-id around point."
  5993. (interactive)
  5994. (save-excursion
  5995. (re-search-backward "[ \t]\\|^" (point-at-bol) t)
  5996. (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
  5997. (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
  5998. (let ((msg-id (concat "<" (match-string 0) ">")))
  5999. (set-buffer gnus-summary-buffer)
  6000. (gnus-summary-refer-article msg-id))
  6001. (error "No references around point"))))
  6002. (defun gnus-article-show-summary ()
  6003. "Reconfigure windows to show summary buffer."
  6004. (interactive)
  6005. (if (not (gnus-buffer-live-p gnus-summary-buffer))
  6006. (error "There is no summary buffer for this article buffer")
  6007. (gnus-article-set-globals)
  6008. (gnus-configure-windows 'article)
  6009. (gnus-summary-goto-subject gnus-current-article)
  6010. (gnus-summary-position-point)))
  6011. (defun gnus-article-describe-briefly ()
  6012. "Describe article mode commands briefly."
  6013. (interactive)
  6014. (gnus-message 6 "%s" (substitute-command-keys "\\<gnus-article-mode-map>\\[gnus-article-goto-next-page]:Next page \\[gnus-article-goto-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help")))
  6015. (defun gnus-article-check-buffer ()
  6016. "Beep if not in an article buffer."
  6017. (unless (equal major-mode 'gnus-article-mode)
  6018. (error "Command invoked outside of a Gnus article buffer")))
  6019. (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
  6020. "Read a summary buffer key sequence and execute it from the article buffer."
  6021. (interactive "P")
  6022. (gnus-article-check-buffer)
  6023. (let ((nosaves
  6024. '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
  6025. "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
  6026. "=" "^" "\M-^" "|"))
  6027. (nosave-but-article
  6028. '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
  6029. "An" "Ap" [?A (meta return)] [?A delete]))
  6030. (nosave-in-article
  6031. '("AS" "\C-d"))
  6032. (up-to-top
  6033. '("n" "Gn" "p" "Gp"))
  6034. keys new-sum-point)
  6035. (with-current-buffer gnus-article-current-summary
  6036. (let (gnus-pick-mode)
  6037. (setq unread-command-events (nconc unread-command-events
  6038. (list (or key last-command-event)))
  6039. keys (if (featurep 'xemacs)
  6040. (events-to-keys (read-key-sequence nil t))
  6041. (read-key-sequence nil t)))))
  6042. (message "")
  6043. (cond
  6044. ((eq (aref keys (1- (length keys))) ?\C-h)
  6045. (gnus-article-describe-bindings (substring keys 0 -1)))
  6046. ((or (member keys nosaves)
  6047. (member keys nosave-but-article)
  6048. (member keys nosave-in-article))
  6049. (let (func)
  6050. (save-window-excursion
  6051. (pop-to-buffer gnus-article-current-summary)
  6052. ;; We disable the pick minor mode commands.
  6053. (let (gnus-pick-mode)
  6054. (setq func (key-binding keys t))))
  6055. (if (or (not func)
  6056. (numberp func))
  6057. (ding)
  6058. (unless (member keys nosave-in-article)
  6059. (set-buffer gnus-article-current-summary))
  6060. (when (get func 'disabled)
  6061. (error "Function %s disabled" func))
  6062. (call-interactively func)
  6063. (setq new-sum-point (point)))
  6064. (when (member keys nosave-but-article)
  6065. (pop-to-buffer gnus-article-buffer))))
  6066. (t
  6067. ;; These commands should restore window configuration.
  6068. (let ((obuf (current-buffer))
  6069. (owin (current-window-configuration))
  6070. win func in-buffer selected new-sum-start new-sum-hscroll err)
  6071. (cond (not-restore-window
  6072. (pop-to-buffer gnus-article-current-summary)
  6073. (setq win (selected-window)))
  6074. ((setq win (get-buffer-window gnus-article-current-summary))
  6075. (select-window win))
  6076. (t
  6077. (let ((summary-buffer gnus-article-current-summary))
  6078. (gnus-configure-windows 'article)
  6079. (unless (setq win (get-buffer-window summary-buffer 'visible))
  6080. (let ((gnus-buffer-configuration
  6081. '((article ((vertical 1.0
  6082. (summary 0.25 point)
  6083. (article 1.0)))))))
  6084. (gnus-configure-windows 'article))
  6085. (setq win (get-buffer-window summary-buffer 'visible)))
  6086. (gnus-select-frame-set-input-focus (window-frame win))
  6087. (select-window win))))
  6088. (setq in-buffer (current-buffer))
  6089. ;; We disable the pick minor mode commands.
  6090. (setq func (let (gnus-pick-mode)
  6091. (key-binding keys t)))
  6092. (when (get func 'disabled)
  6093. (error "Function %s disabled" func))
  6094. (if (and func
  6095. (functionp func)
  6096. (condition-case code
  6097. (progn
  6098. (call-interactively func)
  6099. t)
  6100. (error
  6101. (setq err code)
  6102. nil)))
  6103. (progn
  6104. (when (eq win (selected-window))
  6105. (setq new-sum-point (point)
  6106. new-sum-start (window-start win)
  6107. new-sum-hscroll (window-hscroll win)))
  6108. (when (or (eq in-buffer (current-buffer))
  6109. (when (eq obuf (current-buffer))
  6110. (set-buffer in-buffer)
  6111. t))
  6112. (setq selected (gnus-summary-select-article))
  6113. (set-buffer obuf)
  6114. (unless not-restore-window
  6115. (set-window-configuration owin))
  6116. (when (and (eq selected 'old)
  6117. new-sum-point)
  6118. (set-window-start (get-buffer-window (current-buffer))
  6119. 1)
  6120. (set-window-point (get-buffer-window (current-buffer))
  6121. (if (article-goto-body)
  6122. (1- (point))
  6123. (point))))
  6124. (when (and (not not-restore-window)
  6125. new-sum-point
  6126. (window-live-p win)
  6127. (with-current-buffer (window-buffer win)
  6128. (eq major-mode 'gnus-summary-mode)))
  6129. (set-window-point win new-sum-point)
  6130. (set-window-start win new-sum-start)
  6131. (set-window-hscroll win new-sum-hscroll))))
  6132. (set-window-configuration owin)
  6133. (if err
  6134. (signal (car err) (cdr err))
  6135. (ding))))))))
  6136. (defun gnus-article-read-summary-send-keys ()
  6137. (interactive)
  6138. (let ((unread-command-events (list (gnus-character-to-event ?S))))
  6139. (gnus-article-read-summary-keys)))
  6140. (defun gnus-article-describe-key (key)
  6141. "Display documentation of the function invoked by KEY.
  6142. KEY is a string or a vector."
  6143. (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
  6144. (read-key-sequence "Describe key: "))))
  6145. (gnus-article-check-buffer)
  6146. (if (memq (key-binding key t) '(gnus-article-read-summary-keys
  6147. gnus-article-read-summary-send-keys))
  6148. (with-current-buffer gnus-article-current-summary
  6149. (setq unread-command-events
  6150. (if (featurep 'xemacs)
  6151. (append key nil)
  6152. (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
  6153. (list 'meta (- x 128))
  6154. x))
  6155. key)))
  6156. (let ((cursor-in-echo-area t)
  6157. gnus-pick-mode)
  6158. (describe-key (read-key-sequence nil t))))
  6159. (describe-key key)))
  6160. (defun gnus-article-describe-key-briefly (key &optional insert)
  6161. "Display documentation of the function invoked by KEY.
  6162. KEY is a string or a vector."
  6163. (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
  6164. (read-key-sequence "Describe key: "))
  6165. current-prefix-arg))
  6166. (gnus-article-check-buffer)
  6167. (if (memq (key-binding key t) '(gnus-article-read-summary-keys
  6168. gnus-article-read-summary-send-keys))
  6169. (with-current-buffer gnus-article-current-summary
  6170. (setq unread-command-events
  6171. (if (featurep 'xemacs)
  6172. (append key nil)
  6173. (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
  6174. (list 'meta (- x 128))
  6175. x))
  6176. key)))
  6177. (let ((cursor-in-echo-area t)
  6178. gnus-pick-mode)
  6179. (describe-key-briefly (read-key-sequence nil t) insert)))
  6180. (describe-key-briefly key insert)))
  6181. ;;`gnus-agent-mode' in gnus-agent.el will define it.
  6182. (defvar gnus-agent-summary-mode)
  6183. (defvar gnus-draft-mode)
  6184. ;; Calling help-buffer will autoload help-mode.
  6185. (defvar help-xref-stack-item)
  6186. ;; Emacs 22 doesn't load it in the batch mode.
  6187. (eval-when-compile
  6188. (autoload 'help-buffer "help-mode"))
  6189. (defun gnus-article-describe-bindings (&optional prefix)
  6190. "Show a list of all defined keys, and their definitions.
  6191. The optional argument PREFIX, if non-nil, should be a key sequence;
  6192. then we display only bindings that start with that prefix."
  6193. (interactive)
  6194. (gnus-article-check-buffer)
  6195. (let ((keymap (copy-keymap gnus-article-mode-map))
  6196. (map (copy-keymap gnus-article-send-map))
  6197. (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
  6198. parent agent draft)
  6199. (define-key keymap "S" map)
  6200. (define-key map [t] nil)
  6201. (with-current-buffer gnus-article-current-summary
  6202. (set-keymap-parent
  6203. keymap
  6204. (if (setq parent (keymap-parent gnus-article-mode-map))
  6205. (prog1
  6206. (setq parent (copy-keymap parent))
  6207. (set-keymap-parent parent (current-local-map)))
  6208. (current-local-map)))
  6209. (set-keymap-parent map (key-binding "S"))
  6210. (let (key def gnus-pick-mode)
  6211. (while sumkeys
  6212. (setq key (pop sumkeys))
  6213. (cond ((and (vectorp key) (= (length key) 1)
  6214. (consp (setq def (aref key 0)))
  6215. (numberp (car def)) (numberp (cdr def)))
  6216. (when (< (max (car def) (cdr def)) 128)
  6217. (setq sumkeys
  6218. (append (mapcar
  6219. #'vector
  6220. (nreverse (gnus-uncompress-range def)))
  6221. sumkeys))))
  6222. ((setq def (key-binding key))
  6223. (unless (eq def 'undefined)
  6224. (define-key keymap key def))))))
  6225. (when (boundp 'gnus-agent-summary-mode)
  6226. (setq agent gnus-agent-summary-mode))
  6227. (when (boundp 'gnus-draft-mode)
  6228. (setq draft gnus-draft-mode)))
  6229. (with-temp-buffer
  6230. (use-local-map keymap)
  6231. (set (make-local-variable 'gnus-agent-summary-mode) agent)
  6232. (set (make-local-variable 'gnus-draft-mode) draft)
  6233. (describe-bindings prefix))
  6234. (let ((item `((lambda (prefix)
  6235. (with-current-buffer ,(current-buffer)
  6236. (gnus-article-describe-bindings prefix)))
  6237. ,prefix)))
  6238. (with-current-buffer (let (help-xref-following) (help-buffer))
  6239. (setq help-xref-stack-item item)))))
  6240. (defun gnus-article-reply-with-original (&optional wide)
  6241. "Start composing a reply mail to the current message.
  6242. The text in the region will be yanked. If the region isn't active,
  6243. the entire article will be yanked."
  6244. (interactive)
  6245. (let ((article (cdr gnus-article-current))
  6246. contents)
  6247. (if (not (gnus-region-active-p))
  6248. (with-current-buffer gnus-summary-buffer
  6249. (gnus-summary-reply (list (list article)) wide))
  6250. (setq contents (buffer-substring (point) (mark t)))
  6251. ;; Deactivate active regions.
  6252. (when (and (boundp 'transient-mark-mode)
  6253. transient-mark-mode)
  6254. (setq mark-active nil))
  6255. (with-current-buffer gnus-summary-buffer
  6256. (gnus-summary-reply
  6257. (list (list article contents)) wide)))))
  6258. (defun gnus-article-wide-reply-with-original ()
  6259. "Start composing a wide reply mail to the current message.
  6260. The text in the region will be yanked. If the region isn't active,
  6261. the entire article will be yanked."
  6262. (interactive)
  6263. (gnus-article-reply-with-original t))
  6264. (defun gnus-article-followup-with-original ()
  6265. "Compose a followup to the current article.
  6266. The text in the region will be yanked. If the region isn't active,
  6267. the entire article will be yanked."
  6268. (interactive)
  6269. (let ((article (cdr gnus-article-current))
  6270. contents)
  6271. (if (not (gnus-region-active-p))
  6272. (with-current-buffer gnus-summary-buffer
  6273. (gnus-summary-followup (list (list article))))
  6274. (setq contents (buffer-substring (point) (mark t)))
  6275. ;; Deactivate active regions.
  6276. (when (and (boundp 'transient-mark-mode)
  6277. transient-mark-mode)
  6278. (setq mark-active nil))
  6279. (with-current-buffer gnus-summary-buffer
  6280. (gnus-summary-followup
  6281. (list (list article contents)))))))
  6282. (defun gnus-article-hide (&optional arg force)
  6283. "Hide all the gruft in the current article.
  6284. This means that signatures, cited text and (some) headers will be
  6285. hidden.
  6286. If given a prefix, show the hidden text instead."
  6287. (interactive (append (gnus-article-hidden-arg) (list 'force)))
  6288. (gnus-article-hide-headers arg)
  6289. (gnus-article-hide-list-identifiers arg)
  6290. (gnus-article-hide-citation-maybe arg force)
  6291. (gnus-article-hide-signature arg))
  6292. (defun gnus-article-maybe-highlight ()
  6293. "Do some article highlighting if article highlighting is requested."
  6294. (when (gnus-visual-p 'article-highlight 'highlight)
  6295. (gnus-article-highlight-some)))
  6296. (defun gnus-check-group-server ()
  6297. ;; Make sure the connection to the server is alive.
  6298. (unless (gnus-server-opened
  6299. (gnus-find-method-for-group gnus-newsgroup-name))
  6300. (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
  6301. (gnus-request-group gnus-newsgroup-name t)))
  6302. (eval-when-compile
  6303. (autoload 'nneething-get-file-name "nneething"))
  6304. (defun gnus-request-article-this-buffer (article group)
  6305. "Get an article and insert it into this buffer."
  6306. (let (do-update-line sparse-header)
  6307. (prog1
  6308. (save-excursion
  6309. (erase-buffer)
  6310. (gnus-kill-all-overlays)
  6311. (setq group (or group gnus-newsgroup-name))
  6312. ;; Using `gnus-request-article' directly will insert the article into
  6313. ;; `nntp-server-buffer' - so we'll save some time by not having to
  6314. ;; copy it from the server buffer into the article buffer.
  6315. ;; We only request an article by message-id when we do not have the
  6316. ;; headers for it, so we'll have to get those.
  6317. (when (stringp article)
  6318. (gnus-read-header article))
  6319. ;; If the article number is negative, that means that this article
  6320. ;; doesn't belong in this newsgroup (possibly), so we find its
  6321. ;; message-id and request it by id instead of number.
  6322. (when (and (numberp article)
  6323. gnus-summary-buffer
  6324. (get-buffer gnus-summary-buffer)
  6325. (gnus-buffer-exists-p gnus-summary-buffer))
  6326. (with-current-buffer gnus-summary-buffer
  6327. (let ((header (gnus-summary-article-header article)))
  6328. (when (< article 0)
  6329. (cond
  6330. ((memq article gnus-newsgroup-sparse)
  6331. ;; This is a sparse gap article.
  6332. (setq do-update-line article)
  6333. (setq article (mail-header-id header))
  6334. (setq sparse-header (gnus-read-header article))
  6335. (setq gnus-newsgroup-sparse
  6336. (delq article gnus-newsgroup-sparse)))
  6337. ((vectorp header)
  6338. ;; It's a real article.
  6339. (setq article (mail-header-id header)))
  6340. (t
  6341. ;; It is an extracted pseudo-article.
  6342. (setq article 'pseudo)
  6343. (gnus-request-pseudo-article header))))
  6344. (let ((method (gnus-find-method-for-group
  6345. gnus-newsgroup-name)))
  6346. (when (and (eq (car method) 'nneething)
  6347. (vectorp header))
  6348. (let ((dir (nneething-get-file-name
  6349. (mail-header-id header))))
  6350. (when (and (stringp dir)
  6351. (file-directory-p dir))
  6352. (setq article 'nneething)
  6353. (gnus-group-enter-directory dir))))))))
  6354. (cond
  6355. ;; Refuse to select canceled articles.
  6356. ((and (numberp article)
  6357. gnus-summary-buffer
  6358. (get-buffer gnus-summary-buffer)
  6359. (gnus-buffer-exists-p gnus-summary-buffer)
  6360. (eq (cdr (with-current-buffer gnus-summary-buffer
  6361. (assq article gnus-newsgroup-reads)))
  6362. gnus-canceled-mark))
  6363. nil)
  6364. ;; We first check `gnus-original-article-buffer'.
  6365. ((and (get-buffer gnus-original-article-buffer)
  6366. (numberp article)
  6367. (with-current-buffer gnus-original-article-buffer
  6368. (and (equal (car gnus-original-article) group)
  6369. (eq (cdr gnus-original-article) article))))
  6370. ;; `insert-buffer-substring' would incorrectly use the
  6371. ;; equivalent of string-make-multibyte which amount to decoding
  6372. ;; with locale-coding-system, causing failure of
  6373. ;; subsequent decoding.
  6374. (insert (mm-string-to-multibyte
  6375. (with-current-buffer gnus-original-article-buffer
  6376. (buffer-substring (point-min) (point-max)))))
  6377. 'article)
  6378. ;; Check the backlog.
  6379. ((and gnus-keep-backlog
  6380. (gnus-backlog-request-article group article (current-buffer)))
  6381. 'article)
  6382. ;; Check asynchronous pre-fetch.
  6383. ((gnus-async-request-fetched-article group article (current-buffer))
  6384. (gnus-async-prefetch-next group article gnus-summary-buffer)
  6385. (when (and (numberp article) gnus-keep-backlog)
  6386. (gnus-backlog-enter-article group article (current-buffer)))
  6387. 'article)
  6388. ;; Check the cache.
  6389. ((and gnus-use-cache
  6390. (numberp article)
  6391. (gnus-cache-request-article article group))
  6392. 'article)
  6393. ;; Check the agent cache.
  6394. ((gnus-agent-request-article article group)
  6395. 'article)
  6396. ;; Get the article and put into the article buffer.
  6397. ((or (stringp article)
  6398. (numberp article))
  6399. (let ((gnus-override-method gnus-override-method)
  6400. (methods (and (stringp article)
  6401. (with-current-buffer gnus-summary-buffer
  6402. (gnus-refer-article-methods))))
  6403. (backend (car (gnus-find-method-for-group
  6404. gnus-newsgroup-name)))
  6405. result
  6406. (inhibit-read-only t))
  6407. (when (and (null gnus-override-method)
  6408. methods)
  6409. (setq gnus-override-method (pop methods)))
  6410. (while (not result)
  6411. (erase-buffer)
  6412. (gnus-kill-all-overlays)
  6413. (let ((gnus-newsgroup-name group))
  6414. (gnus-check-group-server))
  6415. (cond
  6416. ((gnus-request-article article group (current-buffer))
  6417. (when (numberp article)
  6418. (gnus-async-prefetch-next group article
  6419. gnus-summary-buffer)
  6420. (when gnus-keep-backlog
  6421. (gnus-backlog-enter-article
  6422. group article (current-buffer)))
  6423. (when (and gnus-agent
  6424. (gnus-agent-group-covered-p group))
  6425. (gnus-agent-store-article article group)))
  6426. (setq result 'article))
  6427. (methods
  6428. (setq gnus-override-method (pop methods)))
  6429. ((not (string-match "^400 "
  6430. (nnheader-get-report backend)))
  6431. ;; If we get 400 server disconnect, reconnect and
  6432. ;; retry; otherwise, assume the article has expired.
  6433. (setq result 'done))))
  6434. (and (eq result 'article) 'article)))
  6435. ;; It was a pseudo.
  6436. (t article)))
  6437. ;; Associate this article with the current summary buffer.
  6438. (setq gnus-article-current-summary gnus-summary-buffer)
  6439. ;; Take the article from the original article buffer
  6440. ;; and place it in the buffer it's supposed to be in.
  6441. (when (and (get-buffer gnus-article-buffer)
  6442. (equal (buffer-name (current-buffer))
  6443. (buffer-name (get-buffer gnus-article-buffer))))
  6444. (save-excursion
  6445. (if (get-buffer gnus-original-article-buffer)
  6446. (set-buffer gnus-original-article-buffer)
  6447. (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
  6448. (buffer-disable-undo)
  6449. (setq major-mode 'gnus-original-article-mode)
  6450. (setq buffer-read-only t))
  6451. (let ((inhibit-read-only t))
  6452. (erase-buffer)
  6453. (insert-buffer-substring gnus-article-buffer))
  6454. (setq gnus-original-article (cons group article)))
  6455. ;; Decode charsets.
  6456. (run-hooks 'gnus-article-decode-hook)
  6457. ;; Mark article as decoded or not.
  6458. (setq gnus-article-decoded-p gnus-article-decode-hook))
  6459. ;; Update sparse articles.
  6460. (when (and do-update-line
  6461. (or (numberp article)
  6462. (stringp article)))
  6463. (let ((buf (current-buffer)))
  6464. (set-buffer gnus-summary-buffer)
  6465. (gnus-summary-update-article do-update-line sparse-header)
  6466. (gnus-summary-goto-subject do-update-line nil t)
  6467. (set-window-point (gnus-get-buffer-window (current-buffer) t)
  6468. (point))
  6469. (set-buffer buf))))))
  6470. (defun gnus-block-private-groups (group)
  6471. (if (gnus-news-group-p group)
  6472. ;; Block nothing in news groups.
  6473. nil
  6474. ;; Block everything anywhere else.
  6475. "."))
  6476. (defun gnus-blocked-images ()
  6477. (if (functionp gnus-blocked-images)
  6478. (funcall gnus-blocked-images gnus-newsgroup-name)
  6479. gnus-blocked-images))
  6480. ;;;
  6481. ;;; Article editing
  6482. ;;;
  6483. (defcustom gnus-article-edit-mode-hook nil
  6484. "Hook run in article edit mode buffers."
  6485. :group 'gnus-article-various
  6486. :type 'hook)
  6487. (defvar gnus-article-edit-done-function nil)
  6488. (defvar gnus-article-edit-mode-map nil)
  6489. ;; Should we be using derived.el for this?
  6490. (unless gnus-article-edit-mode-map
  6491. (setq gnus-article-edit-mode-map (make-keymap))
  6492. (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
  6493. (gnus-define-keys gnus-article-edit-mode-map
  6494. "\C-c?" describe-mode
  6495. "\C-c\C-c" gnus-article-edit-done
  6496. "\C-c\C-k" gnus-article-edit-exit
  6497. "\C-c\C-f\C-t" message-goto-to
  6498. "\C-c\C-f\C-o" message-goto-from
  6499. "\C-c\C-f\C-b" message-goto-bcc
  6500. ;;"\C-c\C-f\C-w" message-goto-fcc
  6501. "\C-c\C-f\C-c" message-goto-cc
  6502. "\C-c\C-f\C-s" message-goto-subject
  6503. "\C-c\C-f\C-r" message-goto-reply-to
  6504. "\C-c\C-f\C-n" message-goto-newsgroups
  6505. "\C-c\C-f\C-d" message-goto-distribution
  6506. "\C-c\C-f\C-f" message-goto-followup-to
  6507. "\C-c\C-f\C-m" message-goto-mail-followup-to
  6508. "\C-c\C-f\C-k" message-goto-keywords
  6509. "\C-c\C-f\C-u" message-goto-summary
  6510. "\C-c\C-f\C-i" message-insert-or-toggle-importance
  6511. "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
  6512. "\C-c\C-b" message-goto-body
  6513. "\C-c\C-i" message-goto-signature
  6514. "\C-c\C-t" message-insert-to
  6515. "\C-c\C-n" message-insert-newsgroups
  6516. "\C-c\C-o" message-sort-headers
  6517. "\C-c\C-e" message-elide-region
  6518. "\C-c\C-v" message-delete-not-region
  6519. "\C-c\C-z" message-kill-to-signature
  6520. "\M-\r" message-newline-and-reformat
  6521. "\C-c\C-a" mml-attach-file
  6522. "\C-a" message-beginning-of-line
  6523. "\t" message-tab
  6524. "\M-;" comment-region)
  6525. (gnus-define-keys (gnus-article-edit-wash-map
  6526. "\C-c\C-w" gnus-article-edit-mode-map)
  6527. "f" gnus-article-edit-full-stops))
  6528. (easy-menu-define
  6529. gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
  6530. '("Field"
  6531. ["Fetch To" message-insert-to t]
  6532. ["Fetch Newsgroups" message-insert-newsgroups t]
  6533. "----"
  6534. ["To" message-goto-to t]
  6535. ["From" message-goto-from t]
  6536. ["Subject" message-goto-subject t]
  6537. ["Cc" message-goto-cc t]
  6538. ["Reply-To" message-goto-reply-to t]
  6539. ["Summary" message-goto-summary t]
  6540. ["Keywords" message-goto-keywords t]
  6541. ["Newsgroups" message-goto-newsgroups t]
  6542. ["Followup-To" message-goto-followup-to t]
  6543. ["Mail-Followup-To" message-goto-mail-followup-to t]
  6544. ["Distribution" message-goto-distribution t]
  6545. ["Body" message-goto-body t]
  6546. ["Signature" message-goto-signature t]))
  6547. (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
  6548. "Major mode for editing articles.
  6549. This is an extended text-mode.
  6550. \\{gnus-article-edit-mode-map}"
  6551. (make-local-variable 'gnus-article-edit-done-function)
  6552. (make-local-variable 'gnus-prev-winconf)
  6553. (set (make-local-variable 'font-lock-defaults)
  6554. '(message-font-lock-keywords t))
  6555. (set (make-local-variable 'mail-header-separator) "")
  6556. (set (make-local-variable 'gnus-article-edit-mode) t)
  6557. (easy-menu-add message-mode-field-menu message-mode-map)
  6558. (mml-mode)
  6559. (setq buffer-read-only nil)
  6560. (buffer-enable-undo)
  6561. (widen))
  6562. (defun gnus-article-edit (&optional force)
  6563. "Edit the current article.
  6564. This will have permanent effect only in mail groups.
  6565. If FORCE is non-nil, allow editing of articles even in read-only
  6566. groups."
  6567. (interactive "P")
  6568. (when (and (not force)
  6569. (gnus-group-read-only-p))
  6570. (error "The current newsgroup does not support article editing"))
  6571. (gnus-article-date-original)
  6572. (gnus-article-edit-article
  6573. 'ignore
  6574. `(lambda (no-highlight)
  6575. 'ignore
  6576. (gnus-summary-edit-article-done
  6577. ,(or (mail-header-references gnus-current-headers) "")
  6578. ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
  6579. (defun gnus-article-edit-article (start-func exit-func &optional quiet)
  6580. "Start editing the contents of the current article buffer."
  6581. (let ((winconf (current-window-configuration)))
  6582. (set-buffer gnus-article-buffer)
  6583. (let ((message-auto-save-directory
  6584. ;; Don't associate the article buffer with a draft file.
  6585. nil))
  6586. (gnus-article-edit-mode))
  6587. (funcall start-func)
  6588. (set-buffer-modified-p nil)
  6589. (gnus-configure-windows 'edit-article)
  6590. (setq gnus-article-edit-done-function exit-func)
  6591. (setq gnus-prev-winconf winconf)
  6592. (unless quiet
  6593. (gnus-message 6 "C-c C-c to end edits"))))
  6594. (defun gnus-article-edit-done (&optional arg)
  6595. "Update the article edits and exit."
  6596. (interactive "P")
  6597. (let ((func gnus-article-edit-done-function)
  6598. (buf (current-buffer))
  6599. (start (window-start))
  6600. (p (point))
  6601. (winconf gnus-prev-winconf))
  6602. (widen) ;; Widen it in case that users narrowed the buffer.
  6603. (funcall func arg)
  6604. (set-buffer buf)
  6605. ;; The cache and backlog have to be flushed somewhat.
  6606. (when gnus-keep-backlog
  6607. (gnus-backlog-remove-article
  6608. (car gnus-article-current) (cdr gnus-article-current)))
  6609. ;; Flush original article as well.
  6610. (gnus-flush-original-article-buffer)
  6611. (when gnus-use-cache
  6612. (gnus-cache-update-article
  6613. (car gnus-article-current) (cdr gnus-article-current)))
  6614. ;; We remove all text props from the article buffer.
  6615. (kill-all-local-variables)
  6616. (set-text-properties (point-min) (point-max) nil)
  6617. (gnus-article-mode)
  6618. (set-window-configuration winconf)
  6619. (set-buffer buf)
  6620. (set-window-start (get-buffer-window buf) start)
  6621. (set-window-point (get-buffer-window buf) (point)))
  6622. (gnus-summary-show-article))
  6623. (defun gnus-flush-original-article-buffer ()
  6624. (when (get-buffer gnus-original-article-buffer)
  6625. (with-current-buffer gnus-original-article-buffer
  6626. (setq gnus-original-article nil))))
  6627. (defun gnus-article-edit-exit ()
  6628. "Exit the article editing without updating."
  6629. (interactive)
  6630. (when (or (not (buffer-modified-p))
  6631. (yes-or-no-p "Article modified; kill anyway? "))
  6632. (let ((curbuf (current-buffer))
  6633. (p (point))
  6634. (window-start (window-start)))
  6635. (erase-buffer)
  6636. (if (gnus-buffer-live-p gnus-original-article-buffer)
  6637. (insert-buffer-substring gnus-original-article-buffer))
  6638. (let ((winconf gnus-prev-winconf))
  6639. (kill-all-local-variables)
  6640. (gnus-article-mode)
  6641. (set-window-configuration winconf)
  6642. ;; Tippy-toe some to make sure that point remains where it was.
  6643. (save-current-buffer
  6644. (set-buffer curbuf)
  6645. (set-window-start (get-buffer-window (current-buffer)) window-start)
  6646. (goto-char p))))
  6647. (gnus-summary-show-article)))
  6648. (defun gnus-article-edit-full-stops ()
  6649. "Interactively repair spacing at end of sentences."
  6650. (interactive)
  6651. (save-excursion
  6652. (goto-char (point-min))
  6653. (search-forward-regexp "^$" nil t)
  6654. (let ((case-fold-search nil))
  6655. (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
  6656. ;;;
  6657. ;;; Article highlights
  6658. ;;;
  6659. ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
  6660. ;;; Internal Variables:
  6661. (defcustom gnus-button-url-regexp
  6662. (concat
  6663. "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
  6664. "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
  6665. "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
  6666. (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
  6667. (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
  6668. (punct "!?:;.,"))
  6669. (concat
  6670. "\\(?:"
  6671. ;; Match paired parentheses, e.g. in Wikipedia URLs:
  6672. ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
  6673. "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
  6674. "\\|"
  6675. "[" chars punct "]+" "[" chars "]"
  6676. "\\)"))
  6677. (concat ;; XEmacs 21.4 doesn't support POSIX.
  6678. "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
  6679. "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
  6680. "\\)")
  6681. "Regular expression that matches URLs."
  6682. :group 'gnus-article-buttons
  6683. :type 'regexp)
  6684. (defcustom gnus-button-valid-fqdn-regexp
  6685. message-valid-fqdn-regexp
  6686. "Regular expression that matches a valid FQDN."
  6687. :version "22.1"
  6688. :group 'gnus-article-buttons
  6689. :type 'regexp)
  6690. ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
  6691. (defcustom gnus-button-valid-localpart-regexp
  6692. "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
  6693. "Regular expression that matches a localpart of mail addresses or MIDs."
  6694. :version "22.1"
  6695. :group 'gnus-article-buttons
  6696. :type 'regexp)
  6697. (defcustom gnus-button-man-handler 'manual-entry
  6698. "Function to use for displaying man pages.
  6699. The function must take at least one argument with a string naming the
  6700. man page."
  6701. :version "22.1"
  6702. :type '(choice (function-item :tag "Man" manual-entry)
  6703. (function-item :tag "Woman" woman)
  6704. (function :tag "Other"))
  6705. :group 'gnus-article-buttons)
  6706. (defcustom gnus-button-mid-or-mail-regexp
  6707. (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
  6708. gnus-button-valid-fqdn-regexp
  6709. ">?\\)\\b")
  6710. "Regular expression that matches a message ID or a mail address."
  6711. :version "22.1"
  6712. :group 'gnus-article-buttons
  6713. :type 'regexp)
  6714. (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
  6715. "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
  6716. Strings like this can be either a message ID or a mail address. If it is one
  6717. of the symbols `mid' or `mail', Gnus will always assume that the string is a
  6718. message ID or a mail address, respectively. If this variable is set to the
  6719. symbol `ask', always query the user what do do. If it is a function, this
  6720. function will be called with the string as its only argument. The function
  6721. must return `mid', `mail', `invalid' or `ask'."
  6722. :version "22.1"
  6723. :group 'gnus-article-buttons
  6724. :type '(choice (function-item :tag "Heuristic function"
  6725. gnus-button-mid-or-mail-heuristic)
  6726. (const ask)
  6727. (const mid)
  6728. (const mail)))
  6729. (defcustom gnus-button-mid-or-mail-heuristic-alist
  6730. '((-10.0 . ".+\\$.+@")
  6731. (-10.0 . "#")
  6732. (-10.0 . "\\*")
  6733. (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
  6734. (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
  6735. (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
  6736. (-1.0 . "^[^a-z]+@")
  6737. ;;
  6738. (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
  6739. (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
  6740. (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
  6741. (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
  6742. ;;
  6743. (-2.0 . "^[0-9]")
  6744. (-1.0 . "^[0-9][0-9]")
  6745. ;;
  6746. ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
  6747. (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
  6748. ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
  6749. (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
  6750. ;;
  6751. (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
  6752. (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
  6753. ;; "[0-9]{8,}.*\@"
  6754. (-3.0
  6755. . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
  6756. ;; "[0-9]{12,}.*\@"
  6757. ;; compensation for TDMA dated mail addresses:
  6758. (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
  6759. ;;
  6760. (-20.0 . "\\.fsf@") ;; Gnus
  6761. (-20.0 . "^slrn")
  6762. (-20.0 . "^Pine")
  6763. (-20.0 . "^alpine\\.")
  6764. (-20.0 . "_-_") ;; Subject change in thread
  6765. ;;
  6766. (-20.0 . "\\.ln@") ;; leafnode
  6767. (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
  6768. (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
  6769. ;;
  6770. ;; (5.0 . "") ;; $local_part_len <= 7
  6771. (10.0 . "^[^0-9]+@")
  6772. (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
  6773. ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
  6774. (3.0 . "\@stud")
  6775. ;;
  6776. (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
  6777. ;;
  6778. (0.5 . "^[A-Z][a-z]")
  6779. (0.5 . "^[A-Z][a-z][a-z]")
  6780. (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
  6781. (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
  6782. "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
  6783. A negative RATE indicates a message IDs, whereas a positive indicates a mail
  6784. address. The REGEXP is processed with `case-fold-search' set to nil."
  6785. :version "22.1"
  6786. :group 'gnus-article-buttons
  6787. :type '(repeat (cons (number :tag "Rate")
  6788. (regexp :tag "Regexp"))))
  6789. (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
  6790. "Guess whether MID-OR-MAIL is a message ID or a mail address.
  6791. Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
  6792. address, `ask' if unsure and `invalid' if the string is invalid."
  6793. (let ((case-fold-search nil)
  6794. (list gnus-button-mid-or-mail-heuristic-alist)
  6795. (result 0) rate regexp lpartlen elem)
  6796. (setq lpartlen
  6797. (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
  6798. (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
  6799. ;; Certain special cases...
  6800. (when (string-match
  6801. (concat
  6802. "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
  6803. "^[0-9]+\\.[0-9]+@compuserve\\|"
  6804. "@public\\.gmane\\.org")
  6805. mid-or-mail)
  6806. (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
  6807. (setq result 'mail))
  6808. (when (string-match "@.*@\\| " mid-or-mail)
  6809. (gnus-message 8 "`%s' is invalid." mid-or-mail)
  6810. (setq result 'invalid))
  6811. ;; Nothing more to do, if result is not a number here...
  6812. (when (numberp result)
  6813. (while list
  6814. (setq elem (car list)
  6815. rate (car elem)
  6816. regexp (cdr elem)
  6817. list (cdr list))
  6818. (when (string-match regexp mid-or-mail)
  6819. (setq result (+ result rate))
  6820. (gnus-message
  6821. 9 "`%s' matched `%s', rate `%s', result `%s'."
  6822. mid-or-mail regexp rate result)))
  6823. (when (<= lpartlen 7)
  6824. (setq result (+ result 5.0))
  6825. (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
  6826. mid-or-mail result))
  6827. (when (>= lpartlen 12)
  6828. (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
  6829. (cond
  6830. ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
  6831. ;; Long local part should contain realname if e-mail address,
  6832. ;; too many digits: message-id.
  6833. ;; $score -= 5.0 + 0.1 * $local_part_len;
  6834. (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
  6835. (setq result (+ result rate))
  6836. (gnus-message
  6837. 9 "Many digits in `%s', rate `%s', result `%s'."
  6838. mid-or-mail rate result))
  6839. ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
  6840. mid-or-mail)
  6841. ;; Too few vowels [^aeiouy]{4,}.*\@
  6842. (setq result (+ result -5.0))
  6843. (gnus-message
  6844. 9 "Few vowels in `%s', rate `%s', result `%s'."
  6845. mid-or-mail -5.0 result))
  6846. (t
  6847. (setq result (+ result 5.0))
  6848. (gnus-message
  6849. 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
  6850. (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
  6851. ;; Maybe we should make this a customizable alist: (condition . 'result)
  6852. (cond
  6853. ((symbolp result) result)
  6854. ;; Now convert number into proper results:
  6855. ((< result -10.0) 'mid)
  6856. ((> result 10.0) 'mail)
  6857. (t 'ask))))
  6858. (defun gnus-button-handle-mid-or-mail (mid-or-mail)
  6859. (let* ((pref gnus-button-prefer-mid-or-mail) guessed
  6860. (url-mid (concat "news" ":" mid-or-mail))
  6861. (url-mailto (concat "mailto" ":" mid-or-mail)))
  6862. (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
  6863. (when (fboundp pref)
  6864. (setq guessed
  6865. ;; get rid of surrounding angles...
  6866. (funcall pref
  6867. (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
  6868. (if (or (eq 'mid guessed) (eq 'mail guessed))
  6869. (setq pref guessed)
  6870. (setq pref 'ask)))
  6871. (if (eq pref 'ask)
  6872. (save-window-excursion
  6873. (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
  6874. (setq pref 'mail)
  6875. (setq pref 'mid))))
  6876. (cond ((eq pref 'mid)
  6877. (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
  6878. (gnus-button-handle-news url-mid))
  6879. ((eq pref 'mail)
  6880. (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
  6881. (gnus-url-mailto url-mailto))
  6882. (t (gnus-message 3 "Invalid string.")))))
  6883. (defun gnus-button-handle-custom (fun arg)
  6884. "Call function FUN on argument ARG.
  6885. Both FUN and ARG are supposed to be strings. ARG will be passed
  6886. as a symbol to FUN."
  6887. (funcall (intern fun)
  6888. (if (string-match "^customize-apropos" fun)
  6889. arg
  6890. (intern arg))))
  6891. (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
  6892. (defun gnus-button-handle-describe-function (url)
  6893. "Call `describe-function' when pushing the corresponding URL button."
  6894. (describe-function
  6895. (intern
  6896. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
  6897. (defun gnus-button-handle-describe-variable (url)
  6898. "Call `describe-variable' when pushing the corresponding URL button."
  6899. (describe-variable
  6900. (intern
  6901. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
  6902. (defun gnus-button-handle-symbol (url)
  6903. "Display help on variable or function.
  6904. Calls `describe-variable' or `describe-function'."
  6905. (let ((sym (intern url)))
  6906. (cond
  6907. ((fboundp sym) (describe-function sym))
  6908. ((boundp sym) (describe-variable sym))
  6909. (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
  6910. (defun gnus-button-handle-describe-key (url)
  6911. "Call `describe-key' when pushing the corresponding URL button."
  6912. (let* ((key-string
  6913. (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
  6914. (keys (ignore-errors (eval `(kbd ,key-string)))))
  6915. (if keys
  6916. (describe-key keys)
  6917. (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
  6918. (defun gnus-button-handle-apropos (url)
  6919. "Call `apropos' when pushing the corresponding URL button."
  6920. (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  6921. (defun gnus-button-handle-apropos-command (url)
  6922. "Call `apropos' when pushing the corresponding URL button."
  6923. (apropos-command
  6924. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  6925. (defun gnus-button-handle-apropos-variable (url)
  6926. "Call `apropos' when pushing the corresponding URL button."
  6927. (funcall
  6928. (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
  6929. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  6930. (defun gnus-button-handle-apropos-documentation (url)
  6931. "Call `apropos' when pushing the corresponding URL button."
  6932. (funcall
  6933. (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
  6934. (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
  6935. (defun gnus-button-handle-library (url)
  6936. "Call `locate-library' when pushing the corresponding URL button."
  6937. (gnus-message 9 "url=`%s'" url)
  6938. (let* ((lib (locate-library url))
  6939. (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
  6940. (if (not lib)
  6941. (gnus-message 1 "Cannot locale library `%s'." url)
  6942. (find-file-read-only file))))
  6943. (defcustom gnus-button-man-level 5
  6944. "*Integer that says how many man-related buttons Gnus will show.
  6945. The higher the number, the more buttons will appear and the more false
  6946. positives are possible. Note that you can set this variable local to
  6947. specific groups. Setting it higher in Unix groups is probably a good idea.
  6948. See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
  6949. how to set variables in specific groups."
  6950. :version "22.1"
  6951. :group 'gnus-article-buttons
  6952. :link '(custom-manual "(gnus)Group Parameters")
  6953. :type 'integer)
  6954. (defcustom gnus-button-emacs-level 5
  6955. "*Integer that says how many emacs-related buttons Gnus will show.
  6956. The higher the number, the more buttons will appear and the more false
  6957. positives are possible. Note that you can set this variable local to
  6958. specific groups. Setting it higher in Emacs or Gnus related groups is
  6959. probably a good idea. See Info node `(gnus)Group Parameters' and the variable
  6960. `gnus-parameters' on how to set variables in specific groups."
  6961. :version "22.1"
  6962. :group 'gnus-article-buttons
  6963. :link '(custom-manual "(gnus)Group Parameters")
  6964. :type 'integer)
  6965. (defcustom gnus-button-message-level 5
  6966. "*Integer that says how many buttons for news or mail messages will appear.
  6967. The higher the number, the more buttons will appear and the more false
  6968. positives are possible."
  6969. ;; mail addresses, MIDs, URLs for news, ...
  6970. :version "22.1"
  6971. :group 'gnus-article-buttons
  6972. :type 'integer)
  6973. (defcustom gnus-button-browse-level 5
  6974. "*Integer that says how many buttons for browsing will appear.
  6975. The higher the number, the more buttons will appear and the more false
  6976. positives are possible."
  6977. ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
  6978. :version "22.1"
  6979. :group 'gnus-article-buttons
  6980. :type 'integer)
  6981. (defcustom gnus-button-alist
  6982. '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
  6983. 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
  6984. ((concat "\\b\\(nntp\\|news\\):\\("
  6985. gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
  6986. 0 t gnus-button-handle-news 2)
  6987. ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
  6988. 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
  6989. ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
  6990. 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
  6991. ;; RFC 2392 (Don't allow `/' in domain part --> CID)
  6992. ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
  6993. 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
  6994. ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
  6995. 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
  6996. ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
  6997. 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
  6998. ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
  6999. 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
  7000. ;; RFC 2368 (The mailto URL scheme)
  7001. ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
  7002. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  7003. ("\\bmailto:\\([^ \n\t]+\\)"
  7004. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  7005. ;; Info Konqueror style <info:/foo/bar baz>.
  7006. ;; Must come before " Gnus home-grown style".
  7007. ("\\binfo://?\\([^'\">\n\t]+\\)"
  7008. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
  7009. ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
  7010. ("\\binfo://\\([^'\">\n\t ]+\\)"
  7011. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
  7012. ;; Info GNOME style <info:foo#bar_baz>
  7013. ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
  7014. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
  7015. ;; Info KDE style <info:(foo)bar baz>
  7016. ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
  7017. 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
  7018. ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
  7019. (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
  7020. ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\([ \t\n,]*\\)\\)?"
  7021. ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
  7022. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
  7023. ;; This is custom
  7024. ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
  7025. (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
  7026. ;; Emacs help commands
  7027. ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7028. ;; regexp doesn't match arguments containing ` '.
  7029. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
  7030. ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7031. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
  7032. ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7033. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
  7034. ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7035. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
  7036. ;; The following entries may lead to many false positives so don't enable
  7037. ;; them by default (use a high button level).
  7038. ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
  7039. ;; Exclude [.?] for URLs in gmane.emacs.cvs
  7040. 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
  7041. ("`\\([a-z][-a-z0-9]+\\.el\\)'"
  7042. 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
  7043. ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
  7044. 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
  7045. ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
  7046. 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
  7047. ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
  7048. 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
  7049. ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7050. 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
  7051. ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7052. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
  7053. ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
  7054. 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
  7055. ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
  7056. ;; Unlike the other regexps we really have to require quoting
  7057. ;; here to determine where it ends.
  7058. 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
  7059. ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
  7060. ("<URL: *\\([^\n<>]*\\)>"
  7061. 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
  7062. ;; RFC 2396 (2.4.3., delims) ...
  7063. ("\"URL: *\\([^\n\"]*\\)\""
  7064. 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
  7065. ;; Raw URLs.
  7066. (gnus-button-url-regexp
  7067. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7068. ;; man pages
  7069. ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
  7070. 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
  7071. gnus-button-handle-man 1)
  7072. ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
  7073. ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
  7074. 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
  7075. gnus-button-handle-man 1)
  7076. ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
  7077. ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
  7078. ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
  7079. 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
  7080. ;; Recognizing patches to .el files. This is somewhat obscure,
  7081. ;; but considering the percentage of Gnus users who hack Emacs
  7082. ;; Lisp files...
  7083. ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
  7084. (>= gnus-button-message-level 4) gnus-button-patch 1 2)
  7085. ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
  7086. (>= gnus-button-message-level 4) gnus-button-patch 1 2)
  7087. ;; MID or mail: To avoid too many false positives we don't try to catch
  7088. ;; all kind of allowed MIDs or mail addresses. Domain part must contain
  7089. ;; at least one dot. TLD must contain two or three chars or be a know TLD
  7090. ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
  7091. ;; so that non-ambiguous entries (see above) match first.
  7092. (gnus-button-mid-or-mail-regexp
  7093. 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
  7094. "*Alist of regexps matching buttons in article bodies.
  7095. Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
  7096. REGEXP: is the string (case insensitive) matching text around the button (can
  7097. also be Lisp expression evaluating to a string),
  7098. BUTTON: is the number of the regexp grouping actually matching the button,
  7099. FORM: is a Lisp expression which must eval to true for the button to
  7100. be added,
  7101. CALLBACK: is the function to call when the user push this button, and each
  7102. PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
  7103. CALLBACK can also be a variable, in that case the value of that
  7104. variable it the real callback function."
  7105. :group 'gnus-article-buttons
  7106. :type '(repeat (list (choice regexp variable sexp)
  7107. (integer :tag "Button")
  7108. (sexp :tag "Form")
  7109. (function :tag "Callback")
  7110. (repeat :tag "Par"
  7111. :inline t
  7112. (integer :tag "Regexp group")))))
  7113. (put 'gnus-button-alist 'risky-local-variable t)
  7114. (defcustom gnus-header-button-alist
  7115. '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
  7116. 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
  7117. ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
  7118. 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
  7119. ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
  7120. 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
  7121. ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
  7122. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7123. ("^Subject:" gnus-button-url-regexp
  7124. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7125. ("^[^:]+:" gnus-button-url-regexp
  7126. 0 (>= gnus-button-browse-level 0) browse-url 0)
  7127. ("^OpenPGP:.*url=" gnus-button-url-regexp
  7128. 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
  7129. ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
  7130. 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
  7131. ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
  7132. 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
  7133. "*Alist of headers and regexps to match buttons in article heads.
  7134. This alist is very similar to `gnus-button-alist', except that each
  7135. alist has an additional HEADER element first in each entry:
  7136. \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
  7137. HEADER is a regexp to match a header. For a fuller explanation, see
  7138. `gnus-button-alist'."
  7139. :group 'gnus-article-buttons
  7140. :group 'gnus-article-headers
  7141. :type '(repeat (list (regexp :tag "Header")
  7142. (choice regexp variable)
  7143. (integer :tag "Button")
  7144. (sexp :tag "Form")
  7145. (function :tag "Callback")
  7146. (repeat :tag "Par"
  7147. :inline t
  7148. (integer :tag "Regexp group")))))
  7149. (put 'gnus-header-button-alist 'risky-local-variable t)
  7150. ;;; Commands:
  7151. (defun gnus-article-push-button (event)
  7152. "Check text under the mouse pointer for a callback function.
  7153. If the text under the mouse pointer has a `gnus-callback' property,
  7154. call it with the value of the `gnus-data' text property."
  7155. (interactive "e")
  7156. (set-buffer (window-buffer (posn-window (event-start event))))
  7157. (let* ((pos (posn-point (event-start event)))
  7158. (data (get-text-property pos 'gnus-data))
  7159. (fun (get-text-property pos 'gnus-callback)))
  7160. (goto-char pos)
  7161. (when fun
  7162. (funcall fun data))))
  7163. (defun gnus-article-press-button ()
  7164. "Check text at point for a callback function.
  7165. If the text at point has a `gnus-callback' property,
  7166. call it with the value of the `gnus-data' text property."
  7167. (interactive)
  7168. (let ((data (get-text-property (point) 'gnus-data))
  7169. (fun (get-text-property (point) 'gnus-callback)))
  7170. (when fun
  7171. (funcall fun data))))
  7172. (defun gnus-article-highlight (&optional force)
  7173. "Highlight current article.
  7174. This function calls `gnus-article-highlight-headers',
  7175. `gnus-article-highlight-citation',
  7176. `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
  7177. do the highlighting. See the documentation for those functions."
  7178. (interactive (list 'force))
  7179. (gnus-article-highlight-headers)
  7180. (gnus-article-highlight-citation force)
  7181. (gnus-article-highlight-signature)
  7182. (gnus-article-add-buttons)
  7183. (gnus-article-add-buttons-to-head))
  7184. (defun gnus-article-highlight-some (&optional force)
  7185. "Highlight current article.
  7186. This function calls `gnus-article-highlight-headers',
  7187. `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
  7188. do the highlighting. See the documentation for those functions."
  7189. (interactive (list 'force))
  7190. (gnus-article-highlight-headers)
  7191. (gnus-article-highlight-signature)
  7192. (gnus-article-add-buttons))
  7193. (defun gnus-article-highlight-headers ()
  7194. "Highlight article headers as specified by `gnus-header-face-alist'."
  7195. (interactive)
  7196. (gnus-with-article-headers
  7197. (let (regexp header-face field-face from hpoints fpoints)
  7198. (dolist (entry gnus-header-face-alist)
  7199. (goto-char (point-min))
  7200. (setq regexp (concat "^\\("
  7201. (if (string-equal "" (nth 0 entry))
  7202. "[^\t ]"
  7203. (nth 0 entry))
  7204. "\\)")
  7205. header-face (nth 1 entry)
  7206. field-face (nth 2 entry))
  7207. (while (and (re-search-forward regexp nil t)
  7208. (not (eobp)))
  7209. (beginning-of-line)
  7210. (setq from (point))
  7211. (unless (search-forward ":" nil t)
  7212. (forward-char 1))
  7213. (when (and header-face
  7214. (not (memq (point) hpoints)))
  7215. (push (point) hpoints)
  7216. (gnus-put-text-property from (point) 'face header-face))
  7217. (when (and field-face
  7218. (not (memq (setq from (point)) fpoints)))
  7219. (push from fpoints)
  7220. (if (re-search-forward "^[^ \t]" nil t)
  7221. (forward-char -2)
  7222. (goto-char (point-max)))
  7223. (gnus-put-text-property from (point) 'face field-face)))))))
  7224. (defun gnus-article-highlight-signature ()
  7225. "Highlight the signature in an article.
  7226. It does this by highlighting everything after
  7227. `gnus-signature-separator' using the face `gnus-signature'."
  7228. (interactive)
  7229. (gnus-with-article-buffer
  7230. (let ((inhibit-point-motion-hooks t))
  7231. (save-restriction
  7232. (when (and gnus-signature-face
  7233. (gnus-article-narrow-to-signature))
  7234. (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
  7235. 'face gnus-signature-face)
  7236. (widen)
  7237. (gnus-article-search-signature)
  7238. (let ((start (match-beginning 0))
  7239. (end (set-marker (make-marker) (1+ (match-end 0)))))
  7240. (gnus-article-add-button start (1- end) 'gnus-signature-toggle
  7241. end)))))))
  7242. (defun gnus-button-in-region-p (b e prop)
  7243. "Say whether PROP exists in the region."
  7244. (text-property-not-all b e prop nil))
  7245. (defun gnus-article-add-buttons ()
  7246. "Find external references in the article and make buttons of them.
  7247. \"External references\" are things like Message-IDs and URLs, as
  7248. specified by `gnus-button-alist'."
  7249. (interactive)
  7250. (gnus-with-article-buffer
  7251. (let ((inhibit-point-motion-hooks t)
  7252. (case-fold-search t)
  7253. (alist gnus-button-alist)
  7254. beg entry regexp)
  7255. ;; We skip the headers.
  7256. (article-goto-body)
  7257. (setq beg (point))
  7258. (while (setq entry (pop alist))
  7259. (setq regexp (eval (car entry)))
  7260. (goto-char beg)
  7261. (while (re-search-forward regexp nil t)
  7262. (let ((start (match-beginning (nth 1 entry)))
  7263. (end (match-end (nth 1 entry)))
  7264. (from (match-beginning 0)))
  7265. (when (and (eval (nth 2 entry))
  7266. (not (gnus-button-in-region-p
  7267. start end 'gnus-callback)))
  7268. ;; That optional form returned non-nil, so we add the
  7269. ;; button.
  7270. (setq from (set-marker (make-marker) from))
  7271. (unless (and (eq (car entry) 'gnus-button-url-regexp)
  7272. (gnus-article-extend-url-button from start end))
  7273. (gnus-article-add-button start end
  7274. 'gnus-button-push (list from entry))
  7275. (gnus-put-text-property
  7276. start end
  7277. 'gnus-string (buffer-substring-no-properties
  7278. start end))))))))))
  7279. (defun gnus-article-extend-url-button (beg start end)
  7280. "Extend url button if url is folded into two or more lines.
  7281. Return non-nil if button is extended. BEG is a marker that points to
  7282. the beginning position of a text containing url. START and END are
  7283. the endpoints of a url button before it is extended. The concatenated
  7284. url is put as the `gnus-button-url' overlay property on the button."
  7285. (let ((opoint (point))
  7286. (points (list start end))
  7287. url delim regexp)
  7288. (prog1
  7289. (when (and (progn
  7290. (goto-char end)
  7291. (not (looking-at "[\t ]*[\">]")))
  7292. (progn
  7293. (goto-char start)
  7294. (string-match
  7295. "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
  7296. (buffer-substring (point-at-bol) start)))
  7297. (progn
  7298. (setq url (list (buffer-substring start end))
  7299. delim (if (match-beginning 1) ">" "\""))
  7300. (beginning-of-line)
  7301. (setq regexp (concat
  7302. (when (and (looking-at
  7303. message-cite-prefix-regexp)
  7304. (< (match-end 0) start))
  7305. (regexp-quote (match-string 0)))
  7306. "\
  7307. \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
  7308. delim "\\)"))
  7309. (while (progn
  7310. (forward-line 1)
  7311. (and (looking-at regexp)
  7312. (prog1
  7313. (match-beginning 1)
  7314. (push (or (match-string 2)
  7315. (match-string 1))
  7316. url)
  7317. (push (setq end (or (match-end 2)
  7318. (match-end 1)))
  7319. points)
  7320. (push (or (match-beginning 2)
  7321. (match-beginning 1))
  7322. points)))))
  7323. (match-beginning 2)))
  7324. (let (gnus-article-mouse-face widget-mouse-face)
  7325. (while points
  7326. (gnus-article-add-button (pop points) (pop points)
  7327. 'gnus-button-push beg)))
  7328. (let ((overlay (gnus-make-overlay start end)))
  7329. (gnus-overlay-put overlay 'evaporate t)
  7330. (gnus-overlay-put overlay 'gnus-button-url
  7331. (list (mapconcat 'identity (nreverse url) "")))
  7332. (when gnus-article-mouse-face
  7333. (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
  7334. t)
  7335. (goto-char opoint))))
  7336. ;; Add buttons to the head of an article.
  7337. (defun gnus-article-add-buttons-to-head ()
  7338. "Add buttons to the head of the article."
  7339. (interactive)
  7340. (gnus-with-article-headers
  7341. (let (beg end)
  7342. (dolist (entry gnus-header-button-alist)
  7343. ;; Each alist entry.
  7344. (goto-char (point-min))
  7345. (while (re-search-forward (car entry) nil t)
  7346. ;; Each header matching the entry.
  7347. (setq beg (match-beginning 0))
  7348. (setq end (or (and (re-search-forward "^[^ \t]" nil t)
  7349. (match-beginning 0))
  7350. (point-max)))
  7351. (goto-char beg)
  7352. (while (re-search-forward (eval (nth 1 entry)) end t)
  7353. ;; Each match within a header.
  7354. (let* ((entry (cdr entry))
  7355. (start (match-beginning (nth 1 entry)))
  7356. (end (match-end (nth 1 entry)))
  7357. (form (nth 2 entry)))
  7358. (goto-char (match-end 0))
  7359. (when (eval form)
  7360. (gnus-article-add-button
  7361. start end (nth 3 entry)
  7362. (buffer-substring (match-beginning (nth 4 entry))
  7363. (match-end (nth 4 entry)))))))
  7364. (goto-char end))))))
  7365. ;;; External functions:
  7366. (defun gnus-article-add-button (from to fun &optional data text)
  7367. "Create a button between FROM and TO with callback FUN and data DATA."
  7368. (when gnus-article-button-face
  7369. (gnus-overlay-put (gnus-make-overlay from to nil t)
  7370. 'face gnus-article-button-face))
  7371. (gnus-add-text-properties
  7372. from to
  7373. (nconc (and gnus-article-mouse-face
  7374. (list gnus-mouse-face-prop gnus-article-mouse-face))
  7375. (list 'gnus-callback fun)
  7376. (and data (list 'gnus-data data))))
  7377. (widget-convert-button 'link from to :action 'gnus-widget-press-button
  7378. :help-echo (or text "Follow the link")
  7379. :keymap gnus-url-button-map
  7380. :button-keymap gnus-widget-button-keymap))
  7381. (defun gnus-article-copy-string ()
  7382. "Copy the string in the button to the kill ring."
  7383. (interactive)
  7384. (gnus-article-check-buffer)
  7385. (let ((data (get-text-property (point) 'gnus-string)))
  7386. (when data
  7387. (with-temp-buffer
  7388. (insert data)
  7389. (copy-region-as-kill (point-min) (point-max))
  7390. (message "Copied %s" data)))))
  7391. ;;; Internal functions:
  7392. (defun gnus-article-set-globals ()
  7393. (with-current-buffer gnus-summary-buffer
  7394. (gnus-set-global-variables)))
  7395. (defun gnus-signature-toggle (end)
  7396. (gnus-with-article-buffer
  7397. (let ((inhibit-point-motion-hooks t))
  7398. (if (text-property-any end (point-max) 'article-type 'signature)
  7399. (progn
  7400. (gnus-delete-wash-type 'signature)
  7401. (gnus-remove-text-properties-when
  7402. 'article-type 'signature end (point-max)
  7403. (cons 'article-type (cons 'signature
  7404. gnus-hidden-properties))))
  7405. (gnus-add-wash-type 'signature)
  7406. (gnus-add-text-properties-when
  7407. 'article-type nil end (point-max)
  7408. (cons 'article-type (cons 'signature
  7409. gnus-hidden-properties)))))
  7410. (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
  7411. (gnus-set-mode-line 'article))))
  7412. (defun gnus-button-push (marker-and-entry)
  7413. ;; Push button starting at MARKER.
  7414. (save-excursion
  7415. (let* ((marker (car marker-and-entry))
  7416. (entry (cadr marker-and-entry))
  7417. (regexp (car entry))
  7418. (inhibit-point-motion-hooks t))
  7419. (goto-char marker)
  7420. ;; This is obviously true, or something bad is happening :)
  7421. ;; But we need it to have the match-data
  7422. (when (looking-at (or (if (symbolp regexp)
  7423. (symbol-value regexp)
  7424. regexp)))
  7425. (let ((fun (nth 3 entry))
  7426. (args (or (and (eq (car entry) 'gnus-button-url-regexp)
  7427. (get-char-property marker 'gnus-button-url))
  7428. (mapcar (lambda (group)
  7429. (let ((string (match-string group)))
  7430. (set-text-properties
  7431. 0 (length string) nil string)
  7432. string))
  7433. (nthcdr 4 entry)))))
  7434. (cond
  7435. ((fboundp fun)
  7436. (apply fun args))
  7437. ((and (boundp fun)
  7438. (fboundp (symbol-value fun)))
  7439. (apply (symbol-value fun) args))
  7440. (t
  7441. (gnus-message 1 "You must define `%S' to use this button"
  7442. (cons fun args)))))))))
  7443. (defun gnus-parse-news-url (url)
  7444. (let (scheme server port group message-id articles)
  7445. (with-temp-buffer
  7446. (insert url)
  7447. (goto-char (point-min))
  7448. (when (looking-at "\\([A-Za-z]+\\):")
  7449. (setq scheme (match-string 1))
  7450. (goto-char (match-end 0)))
  7451. (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
  7452. (setq server (match-string 1))
  7453. (setq port (if (stringp (match-string 3))
  7454. (string-to-number (match-string 3))
  7455. (match-string 3)))
  7456. (goto-char (match-end 0)))
  7457. (cond
  7458. ((looking-at "\\(.*@.*\\)")
  7459. (setq message-id (match-string 1)))
  7460. ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
  7461. (setq group (match-string 1)
  7462. articles (split-string (match-string 2) "-")))
  7463. ((looking-at "\\([^/]+\\)/?")
  7464. (setq group (match-string 1)))
  7465. (t
  7466. (error "Unknown news URL syntax"))))
  7467. (list scheme server port group message-id articles)))
  7468. (defun gnus-button-handle-news (url)
  7469. "Fetch a news URL."
  7470. (destructuring-bind (scheme server port group message-id articles)
  7471. (gnus-parse-news-url url)
  7472. (cond
  7473. (message-id
  7474. (with-current-buffer gnus-summary-buffer
  7475. (if server
  7476. (let ((gnus-refer-article-method
  7477. (nconc (list (list 'nntp server))
  7478. gnus-refer-article-method))
  7479. (nntp-port-number (or port "nntp")))
  7480. (gnus-message 7 "Fetching %s with %s"
  7481. message-id gnus-refer-article-method)
  7482. (gnus-summary-refer-article message-id))
  7483. (gnus-summary-refer-article message-id))))
  7484. (group
  7485. (gnus-button-fetch-group url)))))
  7486. (defun gnus-button-patch (library line)
  7487. "Visit an Emacs Lisp library LIBRARY on line LINE."
  7488. (interactive)
  7489. (let ((file (locate-library (file-name-nondirectory library))))
  7490. (unless file
  7491. (error "Couldn't find library %s" library))
  7492. (find-file file)
  7493. (goto-char (point-min))
  7494. (forward-line (1- (string-to-number line)))))
  7495. (defun gnus-button-handle-man (url)
  7496. "Fetch a man page."
  7497. (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
  7498. (when (eq gnus-button-man-handler 'woman)
  7499. (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
  7500. (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
  7501. (funcall gnus-button-man-handler url))
  7502. (defun gnus-button-handle-info-url (url)
  7503. "Fetch an info URL."
  7504. (setq url (mm-subst-char-in-string ?+ ?\ url))
  7505. (cond
  7506. ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
  7507. (gnus-info-find-node
  7508. (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
  7509. "Gnus")
  7510. ")" (gnus-url-unhex-string (match-string 2 url)))))
  7511. ((string-match "([^)\"]+)[^\"]+" url)
  7512. (setq url
  7513. (gnus-replace-in-string
  7514. (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
  7515. (gnus-info-find-node url))
  7516. (t (error "Can't parse %s" url))))
  7517. (defun gnus-button-handle-info-url-gnome (url)
  7518. "Fetch GNOME style info URL."
  7519. (setq url (mm-subst-char-in-string ?_ ?\ url))
  7520. (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
  7521. (gnus-info-find-node
  7522. (concat "("
  7523. (gnus-url-unhex-string
  7524. (match-string 1 url))
  7525. ")"
  7526. (or (gnus-url-unhex-string
  7527. (match-string 2 url))
  7528. "Top")))
  7529. (error "Can't parse %s" url)))
  7530. (defun gnus-button-handle-info-url-kde (url)
  7531. "Fetch KDE style info URL."
  7532. (gnus-info-find-node (gnus-url-unhex-string url)))
  7533. ;; (info) will autoload info.el
  7534. (declare-function Info-menu "info" (menu-item &optional fork))
  7535. (declare-function Info-index-next "info" (num))
  7536. (defun gnus-button-handle-info-keystrokes (url)
  7537. "Call `info' when pushing the corresponding URL button."
  7538. ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
  7539. (let (node indx comma)
  7540. (if (string-match
  7541. (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
  7542. "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
  7543. "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
  7544. "\\(?:[ \t\n,]*\\)\\)?")
  7545. url)
  7546. (setq node (match-string 2 url)
  7547. indx (match-string 3 url))
  7548. (error "Can't parse %s" url))
  7549. (info)
  7550. (Info-directory)
  7551. (Info-menu node)
  7552. (when (> (length indx) 0)
  7553. (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
  7554. "\\([ \t\n,]*\\)")
  7555. indx)
  7556. (setq comma (match-string 2 indx))
  7557. (setq indx (match-string 1 indx))
  7558. (Info-index indx)
  7559. (when comma
  7560. (dotimes (i (with-temp-buffer
  7561. (insert comma)
  7562. ;; Note: the XEmacs version of `how-many' takes
  7563. ;; no optional argument.
  7564. (goto-char (point-min))
  7565. (how-many ",")))
  7566. (Info-index-next 1)))
  7567. nil)))
  7568. (autoload 'pgg-snarf-keys-region "pgg")
  7569. ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
  7570. (declare-function pgg-display-output-buffer "pgg" (start end status))
  7571. (defun gnus-button-openpgp (url)
  7572. "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
  7573. (with-temp-buffer
  7574. (mm-url-insert-file-contents-external url)
  7575. (pgg-snarf-keys-region (point-min) (point-max))
  7576. (pgg-display-output-buffer nil nil nil)))
  7577. (defun gnus-button-message-id (message-id)
  7578. "Fetch MESSAGE-ID."
  7579. (with-current-buffer gnus-summary-buffer
  7580. (gnus-summary-refer-article message-id)))
  7581. (defun gnus-button-fetch-group (address &rest ignore)
  7582. "Fetch GROUP specified by ADDRESS."
  7583. (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
  7584. address)
  7585. ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
  7586. ;; for nntp:// and news://
  7587. (setq address (match-string 3 address)))
  7588. (if (not (string-match "[:/]" address))
  7589. ;; This is just a simple group url.
  7590. (gnus-group-read-ephemeral-group address gnus-select-method)
  7591. (if (not
  7592. (string-match
  7593. "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
  7594. address))
  7595. (error "Can't parse %s" address)
  7596. (gnus-group-read-ephemeral-group
  7597. (match-string 4 address)
  7598. `(nntp ,(match-string 1 address)
  7599. (nntp-address ,(match-string 1 address))
  7600. (nntp-port-number ,(if (match-end 3)
  7601. (match-string 3 address)
  7602. "nntp")))
  7603. nil nil nil
  7604. (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
  7605. (defun gnus-url-parse-query-string (query &optional downcase)
  7606. (let (retval pairs cur key val)
  7607. (setq pairs (split-string query "&"))
  7608. (while pairs
  7609. (setq cur (car pairs)
  7610. pairs (cdr pairs))
  7611. (if (not (string-match "=" cur))
  7612. nil ; Grace
  7613. (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
  7614. val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
  7615. (if downcase
  7616. (setq key (downcase key)))
  7617. (setq cur (assoc key retval))
  7618. (if cur
  7619. (setcdr cur (cons val (cdr cur)))
  7620. (setq retval (cons (list key val) retval)))))
  7621. retval))
  7622. (defun gnus-url-mailto (url)
  7623. ;; Send mail to someone
  7624. (setq url (replace-regexp-in-string "\n" " " url))
  7625. (when (string-match "mailto:/*\\(.*\\)" url)
  7626. (setq url (substring url (match-beginning 1) nil)))
  7627. (let (to args subject func)
  7628. (setq args (gnus-url-parse-query-string
  7629. (if (string-match "^\\?" url)
  7630. (substring url 1)
  7631. (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
  7632. (concat "to=" (match-string 1 url) "&"
  7633. (match-string 2 url))
  7634. (concat "to=" url))))
  7635. subject (cdr-safe (assoc "subject" args)))
  7636. (gnus-msg-mail)
  7637. (while args
  7638. (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
  7639. (if (fboundp func)
  7640. (funcall func)
  7641. (message-position-on-field (caar args)))
  7642. (insert (gnus-replace-in-string
  7643. (mapconcat 'identity (reverse (cdar args)) ", ")
  7644. "\r\n" "\n" t))
  7645. (setq args (cdr args)))
  7646. (if subject
  7647. (message-goto-body)
  7648. (message-goto-subject))))
  7649. (defun gnus-button-embedded-url (address)
  7650. "Activate ADDRESS with `browse-url'."
  7651. (browse-url (gnus-strip-whitespace address)))
  7652. ;;; Next/prev buttons in the article buffer.
  7653. (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
  7654. (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
  7655. (defvar gnus-prev-page-map
  7656. (let ((map (make-sparse-keymap)))
  7657. (define-key map gnus-mouse-2 'gnus-button-prev-page)
  7658. (define-key map "\r" 'gnus-button-prev-page)
  7659. map))
  7660. (defvar gnus-next-page-map
  7661. (let ((map (make-sparse-keymap)))
  7662. (define-key map gnus-mouse-2 'gnus-button-next-page)
  7663. (define-key map "\r" 'gnus-button-next-page)
  7664. map))
  7665. (defun gnus-insert-prev-page-button ()
  7666. (let ((b (point)) e
  7667. (inhibit-read-only t))
  7668. (gnus-eval-format
  7669. gnus-prev-page-line-format nil
  7670. `(keymap ,gnus-prev-page-map
  7671. gnus-prev t
  7672. gnus-callback gnus-article-button-prev-page
  7673. article-type annotation))
  7674. (setq e (if (bolp)
  7675. ;; Exclude a newline.
  7676. (1- (point))
  7677. (point)))
  7678. (when gnus-article-button-face
  7679. (gnus-overlay-put (gnus-make-overlay b e nil t)
  7680. 'face gnus-article-button-face))
  7681. (widget-convert-button
  7682. 'link b e
  7683. :action 'gnus-button-prev-page
  7684. :button-keymap gnus-prev-page-map)))
  7685. (defun gnus-button-next-page (&optional args more-args)
  7686. "Go to the next page."
  7687. (interactive)
  7688. (let ((win (selected-window)))
  7689. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7690. (gnus-article-next-page)
  7691. (select-window win)))
  7692. (defun gnus-button-prev-page (&optional args more-args)
  7693. "Go to the prev page."
  7694. (interactive)
  7695. (let ((win (selected-window)))
  7696. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7697. (gnus-article-prev-page)
  7698. (select-window win)))
  7699. (defun gnus-insert-next-page-button ()
  7700. (let ((b (point)) e
  7701. (inhibit-read-only t))
  7702. (gnus-eval-format gnus-next-page-line-format nil
  7703. `(keymap ,gnus-next-page-map
  7704. gnus-next t
  7705. gnus-callback gnus-article-button-next-page
  7706. article-type annotation))
  7707. (setq e (if (bolp)
  7708. ;; Exclude a newline.
  7709. (1- (point))
  7710. (point)))
  7711. (when gnus-article-button-face
  7712. (gnus-overlay-put (gnus-make-overlay b e nil t)
  7713. 'face gnus-article-button-face))
  7714. (widget-convert-button
  7715. 'link b e
  7716. :action 'gnus-button-next-page
  7717. :button-keymap gnus-next-page-map)))
  7718. (defun gnus-article-button-next-page (arg)
  7719. "Go to the next page."
  7720. (interactive "P")
  7721. (let ((win (selected-window)))
  7722. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7723. (gnus-article-next-page)
  7724. (select-window win)))
  7725. (defun gnus-article-button-prev-page (arg)
  7726. "Go to the prev page."
  7727. (interactive "P")
  7728. (let ((win (selected-window)))
  7729. (select-window (gnus-get-buffer-window gnus-article-buffer t))
  7730. (gnus-article-prev-page)
  7731. (select-window win)))
  7732. (defvar gnus-decode-header-methods
  7733. '(mail-decode-encoded-word-region)
  7734. "List of methods used to decode headers.
  7735. This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
  7736. is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
  7737. \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
  7738. whose names match REGEXP.
  7739. For example:
  7740. \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
  7741. mail-decode-encoded-word-region
  7742. (\"chinese\" . rfc1843-decode-region))
  7743. ")
  7744. (defvar gnus-decode-header-methods-cache nil)
  7745. (defun gnus-multi-decode-header (start end)
  7746. "Apply the functions from `gnus-encoded-word-methods' that match."
  7747. (unless (and gnus-decode-header-methods-cache
  7748. (eq gnus-newsgroup-name
  7749. (car gnus-decode-header-methods-cache)))
  7750. (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
  7751. (dolist (x gnus-decode-header-methods)
  7752. (if (symbolp x)
  7753. (nconc gnus-decode-header-methods-cache (list x))
  7754. (if (and gnus-newsgroup-name
  7755. (string-match (car x) gnus-newsgroup-name))
  7756. (nconc gnus-decode-header-methods-cache
  7757. (list (cdr x)))))))
  7758. (let ((xlist gnus-decode-header-methods-cache))
  7759. (pop xlist)
  7760. (save-restriction
  7761. (narrow-to-region start end)
  7762. (while xlist
  7763. (funcall (pop xlist) (point-min) (point-max))))))
  7764. ;;;
  7765. ;;; Treatment top-level handling.
  7766. ;;;
  7767. (defvar gnus-inhibit-article-treatments nil)
  7768. (defun gnus-treat-article (gnus-treat-condition
  7769. &optional part-number total-parts gnus-treat-type)
  7770. (let ((gnus-treat-length (- (point-max) (point-min)))
  7771. (alist gnus-treatment-function-alist)
  7772. (article-goto-body-goes-to-point-min-p t)
  7773. (treated-type
  7774. (or (not gnus-treat-type)
  7775. (catch 'found
  7776. (let ((list gnus-article-treat-types))
  7777. (while list
  7778. (when (string-match (pop list) gnus-treat-type)
  7779. (throw 'found t)))))))
  7780. (highlightp (gnus-visual-p 'article-highlight 'highlight))
  7781. val elem)
  7782. (gnus-run-hooks 'gnus-part-display-hook)
  7783. (dolist (elem alist)
  7784. (setq val
  7785. (save-excursion
  7786. (when (gnus-buffer-live-p gnus-summary-buffer)
  7787. (set-buffer gnus-summary-buffer))
  7788. (symbol-value (car elem))))
  7789. (when (and (or (consp val)
  7790. treated-type)
  7791. (or (not gnus-inhibit-article-treatments)
  7792. (eq gnus-treat-condition 'head))
  7793. (gnus-treat-predicate val)
  7794. (or (not (get (car elem) 'highlight))
  7795. highlightp))
  7796. (save-restriction
  7797. (funcall (cadr elem)))))))
  7798. ;; Dynamic variables.
  7799. (defvar part-number)
  7800. (defvar total-parts)
  7801. (defvar gnus-treat-type)
  7802. (defvar gnus-treat-condition)
  7803. (defvar gnus-treat-length)
  7804. (defun gnus-treat-predicate (val)
  7805. (cond
  7806. ((null val)
  7807. nil)
  7808. (gnus-treat-condition
  7809. (eq gnus-treat-condition val))
  7810. ((and (listp val)
  7811. (stringp (car val)))
  7812. (apply 'gnus-or (mapcar `(lambda (s)
  7813. (string-match s ,(or gnus-newsgroup-name "")))
  7814. val)))
  7815. ((listp val)
  7816. (let ((pred (pop val)))
  7817. (cond
  7818. ((eq pred 'or)
  7819. (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
  7820. ((eq pred 'and)
  7821. (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
  7822. ((eq pred 'not)
  7823. (not (gnus-treat-predicate (car val))))
  7824. ((eq pred 'typep)
  7825. (equal (car val) gnus-treat-type))
  7826. (t
  7827. (error "%S is not a valid predicate" pred)))))
  7828. ((eq val t)
  7829. t)
  7830. ((eq val 'head)
  7831. nil)
  7832. ((eq val 'first)
  7833. (eq part-number 1))
  7834. ((eq val 'last)
  7835. (eq part-number total-parts))
  7836. ((numberp val)
  7837. (< gnus-treat-length val))
  7838. (t
  7839. (error "%S is not a valid value" val))))
  7840. (defun gnus-article-encrypt-body (protocol &optional n)
  7841. "Encrypt the article body."
  7842. (interactive
  7843. (list
  7844. (or gnus-article-encrypt-protocol
  7845. (gnus-completing-read "Encrypt protocol"
  7846. (mapcar 'car gnus-article-encrypt-protocol-alist)
  7847. t))
  7848. current-prefix-arg))
  7849. ;; User might hit `K E' instead of `K e', so prompt once.
  7850. (when (and gnus-article-encrypt-protocol
  7851. gnus-novice-user)
  7852. (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
  7853. (error "Encrypt aborted")))
  7854. (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
  7855. (unless func
  7856. (error "Can't find the encrypt protocol %s" protocol))
  7857. (if (member gnus-newsgroup-name '("nndraft:delayed"
  7858. "nndraft:drafts"
  7859. "nndraft:queue"))
  7860. (error "Can't encrypt the article in group %s"
  7861. gnus-newsgroup-name))
  7862. (gnus-summary-iterate n
  7863. (with-current-buffer gnus-summary-buffer
  7864. (let ((mail-parse-charset gnus-newsgroup-charset)
  7865. (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
  7866. (summary-buffer gnus-summary-buffer)
  7867. references point)
  7868. (gnus-set-global-variables)
  7869. (when (gnus-group-read-only-p)
  7870. (error "The current newsgroup does not support article encrypt"))
  7871. (gnus-summary-show-article t)
  7872. (setq references
  7873. (or (mail-header-references gnus-current-headers) ""))
  7874. (set-buffer gnus-article-buffer)
  7875. (let* ((inhibit-read-only t)
  7876. (headers
  7877. (mapcar (lambda (field)
  7878. (and (save-restriction
  7879. (message-narrow-to-head)
  7880. (goto-char (point-min))
  7881. (search-forward field nil t))
  7882. (prog2
  7883. (message-narrow-to-field)
  7884. (buffer-string)
  7885. (delete-region (point-min) (point-max))
  7886. (widen))))
  7887. '("Content-Type:" "Content-Transfer-Encoding:"
  7888. "Content-Disposition:"))))
  7889. (message-narrow-to-head)
  7890. (message-remove-header "MIME-Version")
  7891. (goto-char (point-max))
  7892. (setq point (point))
  7893. (insert (apply 'concat headers))
  7894. (widen)
  7895. (narrow-to-region point (point-max))
  7896. (let ((message-options message-options))
  7897. (message-options-set 'message-sender user-mail-address)
  7898. (message-options-set 'message-recipients user-mail-address)
  7899. (message-options-set 'message-sign-encrypt 'not)
  7900. (funcall func))
  7901. (goto-char (point-min))
  7902. (insert "MIME-Version: 1.0\n")
  7903. (widen)
  7904. (gnus-summary-edit-article-done
  7905. references nil summary-buffer t))
  7906. (when gnus-keep-backlog
  7907. (gnus-backlog-remove-article
  7908. (car gnus-article-current) (cdr gnus-article-current)))
  7909. (gnus-flush-original-article-buffer)
  7910. (when gnus-use-cache
  7911. (gnus-cache-update-article
  7912. (car gnus-article-current) (cdr gnus-article-current))))))))
  7913. (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
  7914. "The following specs can be used:
  7915. %t The security MIME type
  7916. %i Additional info
  7917. %d Details
  7918. %D Details if button is pressed")
  7919. (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
  7920. "The following specs can be used:
  7921. %t The security MIME type
  7922. %i Additional info
  7923. %d Details
  7924. %D Details if button is pressed")
  7925. (defvar gnus-mime-security-button-line-format-alist
  7926. '((?t gnus-tmp-type ?s)
  7927. (?i gnus-tmp-info ?s)
  7928. (?d gnus-tmp-details ?s)
  7929. (?D gnus-tmp-pressed-details ?s)))
  7930. (defvar gnus-mime-security-button-commands
  7931. '((gnus-article-press-button "\r" "Show Detail")
  7932. (undefined "v")
  7933. (undefined "t")
  7934. (undefined "C")
  7935. (gnus-mime-security-save-part "o" "Save...")
  7936. (undefined "\C-o")
  7937. (undefined "r")
  7938. (undefined "d")
  7939. (undefined "c")
  7940. (undefined "i")
  7941. (undefined "E")
  7942. (undefined "e")
  7943. (undefined "p")
  7944. (gnus-mime-security-pipe-part "|" "Pipe To Command...")
  7945. (undefined ".")))
  7946. (defvar gnus-mime-security-button-map
  7947. (let ((map (make-sparse-keymap)))
  7948. (define-key map gnus-mouse-2 'gnus-article-push-button)
  7949. (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
  7950. (dolist (c gnus-mime-security-button-commands)
  7951. (define-key map (cadr c) (car c)))
  7952. map))
  7953. (easy-menu-define
  7954. gnus-mime-security-button-menu gnus-mime-security-button-map
  7955. "Security button menu."
  7956. `("Security Part"
  7957. ,@(delq nil
  7958. (mapcar (lambda (c)
  7959. (unless (eq (car c) 'undefined)
  7960. (vector (caddr c) (car c) :active t)))
  7961. gnus-mime-security-button-commands))))
  7962. (defun gnus-mime-security-button-menu (event prefix)
  7963. "Construct a context-sensitive menu of security commands."
  7964. (interactive "e\nP")
  7965. (save-window-excursion
  7966. (let ((pos (event-start event)))
  7967. (select-window (posn-window pos))
  7968. (goto-char (posn-point pos))
  7969. (gnus-article-check-buffer)
  7970. (popup-menu gnus-mime-security-button-menu nil prefix))))
  7971. (defvar gnus-mime-security-details-buffer nil)
  7972. (defvar gnus-mime-security-button-pressed nil)
  7973. (defvar gnus-mime-security-show-details-inline t
  7974. "If non-nil, show details in the article buffer.")
  7975. (defun gnus-mime-security-verify-or-decrypt (handle)
  7976. (mm-remove-parts (cdr handle))
  7977. (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
  7978. point (inhibit-read-only t))
  7979. (if region
  7980. (goto-char (car region)))
  7981. (setq point (point))
  7982. (with-current-buffer (mm-handle-multipart-original-buffer handle)
  7983. (let* ((mm-verify-option 'known)
  7984. (mm-decrypt-option 'known)
  7985. (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
  7986. (unless (eq nparts (cdr handle))
  7987. (mm-destroy-parts (cdr handle))
  7988. (setcdr handle nparts))))
  7989. (gnus-mime-display-security handle)
  7990. (when region
  7991. (delete-region (point) (cdr region))
  7992. (set-marker (car region) nil)
  7993. (set-marker (cdr region) nil))
  7994. (goto-char point)))
  7995. (defun gnus-mime-security-show-details (handle)
  7996. (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
  7997. (if (not details)
  7998. (gnus-message 5 "No details.")
  7999. (if gnus-mime-security-show-details-inline
  8000. (let ((gnus-mime-security-button-pressed
  8001. (not (get-text-property (point) 'gnus-mime-details)))
  8002. (gnus-mime-security-button-line-format
  8003. (get-text-property (point) 'gnus-line-format))
  8004. (inhibit-read-only t))
  8005. (forward-char -1)
  8006. (while (eq (get-text-property (point) 'gnus-line-format)
  8007. gnus-mime-security-button-line-format)
  8008. (forward-char -1))
  8009. (forward-char)
  8010. (save-restriction
  8011. (narrow-to-region (point) (point))
  8012. (gnus-insert-mime-security-button handle))
  8013. (delete-region (point)
  8014. (or (text-property-not-all
  8015. (point) (point-max)
  8016. 'gnus-line-format
  8017. gnus-mime-security-button-line-format)
  8018. (point-max))))
  8019. ;; Not inlined.
  8020. (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
  8021. (with-current-buffer gnus-mime-security-details-buffer
  8022. (erase-buffer)
  8023. t)
  8024. (setq gnus-mime-security-details-buffer
  8025. (gnus-get-buffer-create "*MIME Security Details*")))
  8026. (with-current-buffer gnus-mime-security-details-buffer
  8027. (insert details)
  8028. (goto-char (point-min)))
  8029. (pop-to-buffer gnus-mime-security-details-buffer)))))
  8030. (defun gnus-mime-security-press-button (handle)
  8031. (save-excursion
  8032. (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
  8033. (gnus-mime-security-show-details handle)
  8034. (gnus-mime-security-verify-or-decrypt handle))))
  8035. (defun gnus-insert-mime-security-button (handle &optional displayed)
  8036. (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
  8037. (gnus-tmp-type
  8038. (concat
  8039. (or (nth 2 (assoc protocol mm-verify-function-alist))
  8040. (nth 2 (assoc protocol mm-decrypt-function-alist))
  8041. "Unknown")
  8042. (if (equal (car handle) "multipart/signed")
  8043. " Signed" " Encrypted")
  8044. " Part"))
  8045. (gnus-tmp-info
  8046. (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
  8047. "Undecided"))
  8048. (gnus-tmp-details
  8049. (mm-handle-multipart-ctl-parameter handle 'gnus-details))
  8050. gnus-tmp-pressed-details
  8051. b e)
  8052. (setq gnus-tmp-details
  8053. (if gnus-tmp-details
  8054. (concat "\n" gnus-tmp-details)
  8055. ""))
  8056. (setq gnus-tmp-pressed-details
  8057. (if gnus-mime-security-button-pressed gnus-tmp-details ""))
  8058. (unless (bolp)
  8059. (insert "\n"))
  8060. (setq b (point))
  8061. (gnus-eval-format
  8062. gnus-mime-security-button-line-format
  8063. gnus-mime-security-button-line-format-alist
  8064. `(keymap ,gnus-mime-security-button-map
  8065. gnus-callback gnus-mime-security-press-button
  8066. gnus-line-format ,gnus-mime-security-button-line-format
  8067. gnus-mime-details ,gnus-mime-security-button-pressed
  8068. article-type annotation
  8069. gnus-data ,handle))
  8070. (setq e (if (bolp)
  8071. ;; Exclude a newline.
  8072. (1- (point))
  8073. (point)))
  8074. (when gnus-article-button-face
  8075. (gnus-overlay-put (gnus-make-overlay b e nil t)
  8076. 'face gnus-article-button-face))
  8077. (widget-convert-button
  8078. 'link b e
  8079. :mime-handle handle
  8080. :action 'gnus-widget-press-button
  8081. :button-keymap gnus-mime-security-button-map
  8082. :help-echo
  8083. (lambda (widget)
  8084. ;; Needed to properly clear the message due to a bug in
  8085. ;; wid-edit (XEmacs only).
  8086. (when (boundp 'help-echo-owns-message)
  8087. (setq help-echo-owns-message t))
  8088. (format
  8089. "%S: show detail; %S: more options"
  8090. (aref gnus-mouse-2 0)
  8091. (aref gnus-down-mouse-3 0))))))
  8092. (defun gnus-mime-display-security (handle)
  8093. (save-restriction
  8094. (narrow-to-region (point) (point))
  8095. (unless (gnus-unbuttonized-mime-type-p (car handle))
  8096. (gnus-insert-mime-security-button handle))
  8097. (gnus-mime-display-part (cadr handle))
  8098. (unless (bolp)
  8099. (insert "\n"))
  8100. (unless (gnus-unbuttonized-mime-type-p (car handle))
  8101. (let ((gnus-mime-security-button-line-format
  8102. gnus-mime-security-button-end-line-format))
  8103. (gnus-insert-mime-security-button handle)))
  8104. (mm-set-handle-multipart-parameter
  8105. handle 'gnus-region
  8106. (cons (set-marker (make-marker) (point-min))
  8107. (set-marker (make-marker) (point-max))))
  8108. (goto-char (point-max))))
  8109. (defun gnus-mime-security-run-function (function)
  8110. "Run FUNCTION with the security part under point."
  8111. (gnus-article-check-buffer)
  8112. (let ((data (get-text-property (point) 'gnus-data))
  8113. buffer handle)
  8114. (when (and (stringp (car-safe data))
  8115. (setq buffer (mm-handle-multipart-original-buffer data))
  8116. (setq handle (cadr data)))
  8117. (if (bufferp (mm-handle-buffer handle))
  8118. (progn
  8119. (setq handle (cons buffer (copy-sequence (cdr handle))))
  8120. (mm-handle-set-undisplayer handle nil))
  8121. (setq handle (mm-make-handle
  8122. buffer
  8123. (mm-handle-multipart-ctl-parameter handle 'protocol)
  8124. nil nil nil nil nil nil)))
  8125. (funcall function handle))))
  8126. (defun gnus-mime-security-save-part ()
  8127. "Save the security part under point."
  8128. (interactive)
  8129. (gnus-mime-security-run-function 'mm-save-part))
  8130. (defun gnus-mime-security-pipe-part ()
  8131. "Pipe the security part under point to a process."
  8132. (interactive)
  8133. (gnus-mime-security-run-function 'mm-pipe-part))
  8134. (gnus-ems-redefine)
  8135. (provide 'gnus-art)
  8136. (run-hooks 'gnus-art-load-hook)
  8137. ;;; gnus-art.el ends here