Fix akonadimodel.cpp:1: warning: unterminated character constant
[kdepim.git] / messageviewer / objecttreeparser.h
blob6f2f0c95c5581ac8407b9a4adba0b946cc3e1ae9
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 objecttreeparser.h
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2003 Marc Mutz <mutz@kde.org>
6 Copyright (C) 2002-2003, 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
7 Copyright (c) 2009 Andras Mantia <andras@kdab.net>
9 KMail is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License, version 2, as
11 published by the Free Software Foundation.
13 KMail is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 In addition, as a special exception, the copyright holders give
23 permission to link the code of this program with any edition of
24 the Qt library by Trolltech AS, Norway (or with modified versions
25 of Qt that use the same license as Qt), and distribute linked
26 combinations including the two. You must obey the GNU General
27 Public License in all respects for all of the code used other than
28 Qt. If you modify this file, you may extend this exception to
29 your version of the file, but you are not obligated to do so. If
30 you do not wish to do so, delete this exception statement from
31 your version.
34 #ifndef _MESSAGEVIEWER_OBJECTTREEPARSER_H_
35 #define _MESSAGEVIEWER_OBJECTTREEPARSER_H_
37 #include "messageviewer_export.h"
39 #include "nodehelper.h"
40 #include "objecttreesourceif.h"
42 #include <libkleo/kleo/cryptobackend.h>
43 #include <gpgme++/verificationresult.h>
45 #include <QList>
47 class QString;
49 namespace KMime {
50 class Content;
53 namespace GpgME {
54 class Error;
58 namespace MessageViewer {
60 class PartMetaData;
61 class ViewerPrivate;
62 class HtmlWriter;
63 class CSSHelper;
64 class AttachmentStrategy;
65 class NodeHelper;
68 class ProcessResult {
69 public:
70 explicit ProcessResult( NodeHelper *nodeHelper, KMMsgSignatureState inlineSignatureState = KMMsgNotSigned,
71 KMMsgEncryptionState inlineEncryptionState = KMMsgNotEncrypted,
72 bool neverDisplayInline = false,
73 bool isImage = false )
74 : mInlineSignatureState( inlineSignatureState ),
75 mInlineEncryptionState( inlineEncryptionState ),
76 mNeverDisplayInline( neverDisplayInline ),
77 mIsImage( isImage ),
78 mNodeHelper( nodeHelper ) {}
80 KMMsgSignatureState inlineSignatureState() const {
81 return mInlineSignatureState;
83 void setInlineSignatureState( KMMsgSignatureState state ) {
84 mInlineSignatureState = state;
87 KMMsgEncryptionState inlineEncryptionState() const {
88 return mInlineEncryptionState;
90 void setInlineEncryptionState( KMMsgEncryptionState state ) {
91 mInlineEncryptionState = state;
94 bool neverDisplayInline() const { return mNeverDisplayInline; }
95 void setNeverDisplayInline( bool display ) {
96 mNeverDisplayInline = display;
99 bool isImage() const { return mIsImage; }
100 void setIsImage( bool image ) {
101 mIsImage = image;
104 void adjustCryptoStatesOfNode( KMime::Content * node ) const;
106 private:
107 KMMsgSignatureState mInlineSignatureState;
108 KMMsgEncryptionState mInlineEncryptionState;
109 bool mNeverDisplayInline : 1;
110 bool mIsImage : 1;
111 NodeHelper* mNodeHelper;
115 \brief Parses messages and generates HTML display code out of them
117 \par Introduction
119 First, have a look at the documentation in Mainpage.dox and at the documentation of ViewerPrivate
120 to understand the broader picture.
122 Just a note on the terminology: 'Node' refers to a MIME part here, which in KMime is a
123 KMime::Content.
125 \par Basics
127 The ObjectTreeParser basically has two modes: Generating the HTML code for the Viewer, or only
128 extracting the textualContent() for situations where only the message text is needed, for example
129 when inline forwarding a message. The mode depends on the ObjectTreeSourceIf passed to the
130 constructor: If ObjectTreeSourceIf::htmlWriter() is not 0, then the HTML code generation mode is
131 used.
133 Basically, all the ObjectTreeParser does is going through the tree of MIME parts and operating on
134 those nodes. Operating here means creating the HTML code for the node or extracting the textual
135 content from it. This process is started with parseObjectTree(), where we loop over the subnodes
136 of the current root node. For each of those subnodes, we try to find a BodyPartFormatter that can
137 handle the type of the node. This can either be an internal function, such as
138 processMultiPartAlternativeSubtype() or processTextHtmlSubtype(), or it can be an external plugin.
139 More on external plugins later. When no matching formatter is found, defaultHandling() is called
140 for that node.
142 \par Multipart Nodes
144 Those nodes that are of type multipart have subnodes. If one of those children needs to be
145 processed normally, the processMultipartXXX() functions call stdChildHandling() for the node that
146 should be handled normally. stdChildHandling() creates its own ObjectTreeParser, which is a clone
147 of the current ObjectTreeParser, and processes the node. stdChildHandling() is not called for all
148 children of the multipart node, for example processMultiPartAlternativeSubtype() only calls it on
149 one of the children, as the other one doesn't need to be displayed. Similary,
150 processMultiPartSignedSubtype() doesn't call stdChildHandling() for the signature node, only for the
151 signed node.
153 \par Processed and Unprocessed Nodes
155 When a BodyPartFormatter has finished processing a node, it is processed. Nodes are set to being
156 not processed at the beginning of parseObjectTree(). The processed state of a node is saved in a
157 list in NodeHelper, see NodeHelper::setNodeProcessed(), NodeHelper::nodeProcessed() and the other
158 related helper functions.
160 It is the responsibility of the BodyPartFormatter to correctly call setNodeProcessed() and the
161 related functions. This is important so that processing the same node twice can be prevented. The
162 check that prevents duplicate processing is in parseObjectTree().
164 An example where duplicate processing would happen if we didn't check for it is in stdChildHandling(),
165 which is for example called from processMultiPartAlternativeSubtype(). Let's say the setting is to
166 prefer HTML over plain text. In this case, processMultiPartAlternativeSubtype() would call
167 stdChildHandling() on the HTML node, which would create a new ObjectTreeParser and call
168 parseObjectTree() on it. parseObjectTree() processes the node and all its siblings, and one of the
169 siblings is the plain text node, which shouldn't be processed! Therefore
170 processMultiPartAlternativeSubtype() sets the plain text node as been processed already.
172 \par Plain Text Output
174 Various nodes have plain text that should be displayed. This plain text is usually processed though
175 writeBodyString() first. That method checks if the provided text is an inline PGP text and decrypts
176 it if necessary. It also pushes the text through quotedHTML(), which does a number of things like
177 coloring quoted lines or detecting links and creating real link tags for them.
179 \par Modifying the Message
181 The ObjectTreeParser does not only parse its message, in some circumstances it also modifies it
182 before displaying. This is for example the case when displaying a decrypted message: The original
183 message only contains a binary blob of crypto data, and processMultiPartEncryptedSubtype() decrypts
184 that blob. After decryption, the current node is replaced with the decrypted node, which happens
185 in insertAndParseNewChildNode().
187 \par Crypto Operations
189 For signature and decryption handling, there are functions which help with generating the HTML code
190 for the signature header and footer. These are writeDeferredDecryptionBlock(), writeSigstatFooter()
191 and writeSigstatHeader(). As the name writeDeferredDecryptionBlock() suggests, a setting can cause
192 the message to not be decrypted unless the user clicks a link. Whether the message should be
193 decrypted or not can be controlled by ObjectTreeSourceIf::decryptMessage(). When the user clicks the
194 decryption link, the URLHandler for 'kmail:' URLs sets that variable to true and triggers an update
195 of the Viewer, which will cause parseObjectTree() to be called again.
197 \par Async Crypto Operations
199 The above case describes decryption the message in place. However, decryption and also verifying of
200 the signature can take a long time, so synchronous decryption and verifing would cause the Viewer to
201 block. Therefore it is possible to run these operations in async mode, see allowAsync().
202 In the first run of the async mode, all the ObjectTreeParser does is starting the decrypt or the
203 verify job, and informing the user that the operation is in progress with
204 writeDecryptionInProgressBlock() or with writeSigstatHeader(). Then, it creates and associates a
205 BodyPartMemento with the current node, for example a VerifyDetachedBodyPartMemento. Each node can
206 have multiple mementos associated with it, which are differeniated by name.
208 NodeHelper::setBodyPartMemento() and NodeHelper::bodyPartMemento() provide means to store and
209 retrieve these mementos. A memento is basically a thin wrapper around the crypto job, it stores the
210 job pointer, the job input data and the job result. Mementos can be used for any async situation,
211 not just for crypto jobs, but I'll describe crypto jobs here.
213 So in the first run of decrypting or verifying a message, the BodyPartFormatter only starts the
214 crypto job, creates the BodyPartMemento and writes the HTML code that tells the user that the
215 operation is in progress. parseObjectTree() thus finishes without waiting for anything, and the
216 message is displayed.
218 At some point, the crypto jobs then finish, which will cause slotResult() of the BodyPartMemento
219 to be called. slotResult() then saves the result to some member variable and calls
220 BodyPartMemento::notify(), which in the end will trigger an update of the Viewer. That update
221 will, in ViewerPrivate::parseMsg(), create a new ObjectTreeParser and call parseObjectTree() on it.
222 This is where the second run begins.
224 The functions that deal with decrypting of verifying, like processMultiPartSignedSubtype() or
225 processMultiPartEncryptedSubtype() will look if they find a BodyPartMemento that is associated with
226 the current node. Now it finds that memento, since it was created in the first run. It checks if the
227 memento's job has finished, and if so, the result can be written out (either the decrypted data or
228 the verified signature).
230 When dealing with encrypted nodes, new nodes are created with the decrypted data. It is important to
231 note that the original MIME tree is never modified, and remains the same as the original one. The method
232 createAndParseTempNode is called with the newly decrypted data, and it generates a new temporary node to
233 store the decrypted data. When these nodes are created, it is important to keep track of them as otherwise
234 some mementos that are added to the newly created temporary nodes will be constantly regenerated. As the
235 regeneration triggers a viewer update when complete, it results in an infinite refresh loop. The function
236 NodeHelper::linkAsPermanentDecrypted will create a link between the newly created node and the original parent.
237 Conversely, the function NodeHelper::attachExtraContent will create a link in the other direction, from the parent
238 node to the newly created temporary node.
240 When generating some mementos for nodes that may be temporary nodes (for example, contact photo mementos), the
241 function NodeHelper::setBodyPartMementoForPermanentParent is used. This will save the given body part memento for
242 the closest found permanent parent node, rather than the transient node itself. Then when checking for the existence
243 of a certain memento in a node, NodeHelper::findPermanentParentBodyPartMemento will check to see if any parent of the
244 given temporary node is a permanent (encrypted) node that has been used to generate the asked-for node.
246 To conclude: For async operations, parseObjectTree() is called twice: The first call starts the
247 crypto operation and creates the BodyPartMemento, the second calls sees that the BodyPartMemento is
248 there and can use its result for writing out the HTML.
250 \par PartMetaData and ProcessResult
252 For crypto operations, the class PartMetaData is used a lot, mainly to pass around info about the
253 crypto state of a node. A PartMetaData can also be associated with a node by using
254 NodeHelper::setPartMetaData(). The only user of that however is MessageAnalyzer::processPart() of
255 the Nepomuk E-Mail Feeder, which also uses the ObjectTreeParser to analyze the message.
257 You'll notice that a ProcessResult is passed to each formatter. The formatter is supposed to modify
258 the ProcessResult to tell the callers something about the state of the nodes that were processed.
259 One example for its use is to tell the caller about the crypto state of the node.
261 \par BodyPartFormatter Plugins
263 As mentioned way earlier, BodyPartFormatter can either be plugins or be internal. bodypartformatter.cpp
264 contains some trickery so that the processXXX() methods of the ObjectTreeParser are called from
265 a BodyPartFormatter associated with them, see the CREATE_BODY_PART_FORMATTER macro.
267 The BodyPartFormatter code is work in progress, it was supposed to be refactored, but that has not
268 yet happened at the time of writing. Therefore the code can seem a bit chaotic.
270 External plugins are loaded with loadPlugins() in bodypartformatterfactory.cpp. External plugins
271 can only use the classes in the interfaces/ directory, they include BodyPart, BodyPartMemento,
272 BodyPartFormatterPlugin, BodyPartFormatter, BodyPartURLHandler, HtmlWriter and URLHandler. Therefore
273 external plugins have powerful capabilities, which are needed for example in the iCal formatter or
274 in the vCard formatter.
276 \par Special HTML tags
278 As also mentioned in the documentation of ViewerPrivate, the ObjectTreeParser writes out special
279 links that are only understood by the viewer, for example 'kmail:' URLs or 'attachment:' URLs.
280 Also, some special HTML tags are created, which the Viewer later uses for post-processing. For
281 example a div with the id 'attachmentInjectionPoint', or a div with the id 'attachmentDiv', which
282 is used to mark an attachment in the body with a yellow border when the user clicks the attachment
283 in the header. Finally, parseObjectTree() creates an anchor with the id 'att%1', which is used in
284 the Viewer to scroll to the attachment.
286 class MESSAGEVIEWER_EXPORT ObjectTreeParser {
287 class CryptoProtocolSaver;
288 /** Internal. Copies the context of @p other, but not it's rawReplyString() */
289 ObjectTreeParser( const ObjectTreeParser & other );
290 public:
291 explicit ObjectTreeParser( ObjectTreeSourceIf *source, NodeHelper *nodeHelper = 0,
292 const Kleo::CryptoBackend::Protocol * protocol=0,
293 bool showOneMimePart=false, bool keepEncryptions=false,
294 bool includeSignatures=true,
295 const AttachmentStrategy * attachmentStrategy=0 );
296 virtual ~ObjectTreeParser();
298 void setAllowAsync( bool allow ) { assert( !mHasPendingAsyncJobs ); mAllowAsync = allow; }
299 bool allowAsync() const { return mAllowAsync; }
301 bool hasPendingAsyncJobs() const { return mHasPendingAsyncJobs; }
303 QByteArray rawReplyString() const { return mRawReplyString; }
305 /*! @return the text of the message, ie. what would appear in the
306 composer's text editor if this was edited. */
307 QString textualContent() const { return mTextualContent; }
309 QByteArray textualContentCharset() const { return mTextualContentCharset; }
311 void setCryptoProtocol( const Kleo::CryptoBackend::Protocol * protocol ) {
312 mCryptoProtocol = protocol;
314 const Kleo::CryptoBackend::Protocol* cryptoProtocol() const {
315 return mCryptoProtocol;
318 bool showOnlyOneMimePart() const { return mShowOnlyOneMimePart; }
319 void setShowOnlyOneMimePart( bool show ) {
320 mShowOnlyOneMimePart = show;
323 bool keepEncryptions() const { return mKeepEncryptions; }
324 void setKeepEncryptions( bool keep ) {
325 mKeepEncryptions = keep;
328 bool includeSignatures() const { return mIncludeSignatures; }
329 void setIncludeSignatures( bool include ) {
330 mIncludeSignatures = include;
333 // Controls whether Toltec invitations are displayed in their raw form or as a replacement text,
334 // which is used in processToltecMail().
335 void setShowRawToltecMail( bool showRawToltecMail ) { mShowRawToltecMail = showRawToltecMail; }
336 bool showRawToltecMail() const { return mShowRawToltecMail; }
338 /// Default text for processToltecMail(), which is used in messageviewer.kcfg, therefore it
339 /// needs to be static here.
340 static QString defaultToltecReplacementText();
342 const AttachmentStrategy * attachmentStrategy() const {
343 return mAttachmentStrategy;
346 HtmlWriter * htmlWriter() const { return mSource->htmlWriter(); }
348 CSSHelper * cssHelper() const { return mSource->cssHelper(); }
350 NodeHelper * nodeHelper() const { return mNodeHelper; }
352 /** Parse beginning at a given node and recursively parsing
353 the children of that node and it's next sibling. */
354 void parseObjectTree( KMime::Content * node );
356 private:
358 * Does the actual work for parseObjectTree. Unlike parseObjectTree(), this does not change the
359 * top-level content.
361 void parseObjectTreeInternal( KMime::Content * node );
363 /** Standard children handling a.k.a. multipart/mixed (w/o
364 kroupware hacks) */
365 void stdChildHandling( KMime::Content * child );
367 void defaultHandling( KMime::Content * node, ProcessResult & result );
369 /** 1. Create a new partNode using 'content' data and Content-Description
370 found in 'cntDesc'.
371 2. Parse the 'node' to display the content.
373 void createAndParseTempNode( KMime::Content* parentNode, const char * content, const char * cntDesc );
375 /** if data is 0:
376 Feeds the HTML widget with the contents of the opaque signed
377 data found in partNode 'sign'.
378 if data is set:
379 Feeds the HTML widget with the contents of the given
380 multipart/signed object.
381 Signature is tested. May contain body parts.
383 Returns whether a signature was found or not: use this to
384 find out if opaque data is signed or not. */
385 bool writeOpaqueOrMultipartSignedData( KMime::Content * data,
386 KMime::Content & sign,
387 const QString & fromAddress,
388 bool doCheck=true,
389 QByteArray * cleartextData=0,
390 const std::vector<GpgME::Signature> & paramSignatures = std::vector<GpgME::Signature>(),
391 bool hideErrors=false );
393 /** Writes out the block that we use when the node is encrypted,
394 but we're deferring decryption for later. */
395 void writeDeferredDecryptionBlock();
397 /** Writes out the block that we use when the node is encrypted,
398 but we've just kicked off async decryption. */
399 void writeDecryptionInProgressBlock();
402 /** Returns the contents of the given multipart/encrypted
403 object. Data is decypted. May contain body parts. */
404 bool okDecryptMIME( KMime::Content& data,
405 QByteArray& decryptedData,
406 bool& signatureFound,
407 std::vector<GpgME::Signature> &signatures,
408 bool showWarning,
409 bool& passphraseError,
410 bool& actuallyEncrypted,
411 bool& decryptionStarted,
412 PartMetaData &partMetaData );
415 * This is called for all multipart/mixed nodes. It checks if that belongs to a Toltec mail,
416 * by checking various criteria.
417 * If it is a toltec mail, a special text, instead of the confusing toltec text, will be
418 * displayed.
420 * @return true if the mail was indeed a toltec mail, in which case the node should not be
421 * processed further
423 bool processToltecMail( KMime::Content *node );
425 bool processMailmanMessage( KMime::Content* node );
427 /** Checks whether @p str contains external references. To be precise,
428 we only check whether @p str contains 'xxx="http[s]:' where xxx is
429 not href. Obfuscated external references are ignored on purpose.
431 static bool containsExternalReferences( const QString & str );
433 public:// (during refactoring)
435 bool processTextHtmlSubtype( KMime::Content * node, ProcessResult & result );
436 bool processTextPlainSubtype( KMime::Content *node, ProcessResult & result );
438 bool processMultiPartMixedSubtype( KMime::Content * node, ProcessResult & result );
439 bool processMultiPartAlternativeSubtype( KMime::Content * node, ProcessResult & result );
440 bool processMultiPartDigestSubtype( KMime::Content * node, ProcessResult & result );
441 bool processMultiPartParallelSubtype( KMime::Content * node, ProcessResult & result );
442 bool processMultiPartSignedSubtype( KMime::Content * node, ProcessResult & result );
443 bool processMultiPartEncryptedSubtype( KMime::Content * node, ProcessResult & result );
445 bool processMessageRfc822Subtype( KMime::Content * node, ProcessResult & result );
447 bool processApplicationOctetStreamSubtype( KMime::Content * node, ProcessResult & result );
448 bool processApplicationPkcs7MimeSubtype( KMime::Content * node, ProcessResult & result );
449 bool processApplicationChiasmusTextSubtype( KMime::Content * node, ProcessResult & result );
450 bool processApplicationMsTnefSubtype( KMime::Content *node, ProcessResult &result );
452 bool decryptChiasmus( const QByteArray& data, QByteArray& bodyDecoded, QString& errorText );
453 void writeBodyString( const QByteArray & bodyString,
454 const QString & fromAddress,
455 const QTextCodec * codec,
456 ProcessResult & result, bool decorate );
458 void writePartIcon( KMime::Content * msgPart, bool inlineImage = false );
460 QString sigStatusToString( const Kleo::CryptoBackend::Protocol * cryptProto,
461 int status_code,
462 GpgME::Signature::Summary summary,
463 int & frameColor,
464 bool & showKeyInfos );
465 QString writeSigstatHeader( PartMetaData & part,
466 const Kleo::CryptoBackend::Protocol * cryptProto,
467 const QString & fromAddress,
468 KMime::Content *node = 0);
469 QString writeSigstatFooter( PartMetaData & part );
471 // The attachment mark is a div that is placed around the attchment. It is used for drawing
472 // a yellow border around the attachment when scrolling to it. When scrolling to it, the border
473 // color of the div is changed, see KMReaderWin::scrollToAttachment().
474 void writeAttachmentMarkHeader( KMime::Content *node );
475 void writeAttachmentMarkFooter();
477 void writeBodyStr( const QByteArray & bodyString,
478 const QTextCodec * aCodec,
479 const QString & fromAddress,
480 KMMsgSignatureState & inlineSignatureState,
481 KMMsgEncryptionState & inlineEncryptionState,
482 bool decorate );
484 bool isMailmanMessage( KMime::Content * curNode );
486 public: // KMReaderWin still needs this...
487 void writeBodyStr( const QByteArray & bodyString,
488 const QTextCodec * aCodec,
489 const QString & fromAddress );
490 static KMime::Content* findType( KMime::Content* content, const QByteArray& mimeType, bool deep, bool wide );
492 static KMime::Content* findType( KMime::Content* content, const QByteArray& mediaType, const QByteArray& subType, bool deep, bool wide );
494 static KMime::Content* findTypeNot( KMime::Content* content, const QByteArray& mediaType, const QByteArray& subType, bool deep=true, bool wide=true );
497 private:
498 /** Change the string to `quoted' html (meaning, that the quoted
499 part of the message get italized */
500 QString quotedHTML(const QString& pos, bool decorate);
502 const QTextCodec * codecFor( KMime::Content * node ) const;
503 /** Check if the newline at position @p newLinePos in string @p s
504 seems to separate two paragraphs (important for correct BiDi
505 behavior, but is heuristic because paragraphs are not
506 well-defined) */
507 bool looksLikeParaBreak(const QString& s, unsigned int newLinePos) const;
509 #ifdef MARCS_DEBUG
510 void dumpToFile( const char * filename, const char * dataStart, size_t dataLen );
511 #else
512 void dumpToFile( const char *, const char *, size_t ) {}
513 #endif
515 private:
516 ObjectTreeSourceIf* mSource;
517 NodeHelper* mNodeHelper;
518 QByteArray mRawReplyString;
519 QByteArray mTextualContentCharset;
520 QString mTextualContent;
521 KMime::Content *mTopLevelContent;
522 const Kleo::CryptoBackend::Protocol * mCryptoProtocol;
524 /// Show only one mime part means that the user has selected some node in the message structure
525 /// viewer that is not the root, which means the user wants to only see the selected node and its
526 /// children. If that is the case, this variable is set to true.
527 /// The code needs to behave differently if this is set. For example, it should not process the
528 /// siblings. Also, consider inline images: Normally, those nodes are completely hidden, as the
529 /// HTML node embedds them. However, when showing only the node of the image, one has to show them,
530 /// as their is no HTML node in which they are displayed. There are many more cases where this
531 /// variable needs to be obeyed.
532 /// This variable is set to false again when processing the children in stdChildHandling(), as
533 /// the children can be completely displayed again.
534 bool mShowOnlyOneMimePart;
536 bool mKeepEncryptions;
537 bool mIncludeSignatures;
538 bool mHasPendingAsyncJobs;
539 bool mAllowAsync;
540 bool mShowRawToltecMail;
541 const AttachmentStrategy * mAttachmentStrategy;
542 // DataUrl Icons cache
543 QString mCollapseIcon;
544 QString mExpandIcon;
545 bool mDeleteNodeHelper;
551 #endif // _KMAIL_OBJECTTREEPARSER_H_