1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org>
2 
3 #ifndef INJECTOR_H
4 #define INJECTOR_H
5 
6 #include "message.h"
7 #include "event.h"
8 #include "list.h"
9 
10 class Query;
11 class Header;
12 class Address;
13 class Mailbox;
14 class Bodypart;
15 class Annotation;
16 class UStringList;
17 
18 
19 class Injectee
20     : public Message
21 {
22 public:
23     Injectee();
24 
25     void setUid( Mailbox *, uint );
26     uint uid( Mailbox * ) const;
27 
28     void setModSeq( Mailbox *, int64 );
29     int64 modSeq( Mailbox * ) const;
30 
31     EStringList * flags( Mailbox * ) const;
32     void setFlags( Mailbox *, const EStringList * );
33     void setFlags( Mailbox *, const UStringList * );
34     List<Annotation> * annotations( Mailbox * ) const;
35     void setAnnotations( Mailbox *, List<Annotation> * );
36 
37     List<Mailbox> * mailboxes() const;
38 
39     static Injectee * wrapUnparsableMessage( const EString &,
40                                              const EString &,
41                                              const EString &,
42                                              const EString & = "" );
43 private:
44     class InjecteeData * d;
45 };
46 
47 
48 class Injector
49     : public EventHandler
50 {
51 public:
52     Injector( EventHandler * );
53 
54     void execute();
55 
56     bool done() const;
57     bool failed() const;
58     EString error() const;
59 
60     void addInjection( List<Injectee> * );
61     void addDelivery( Injectee *, Address *, List<Address> *,
62                       class Date * = 0 );
63 
64     void setTransaction( class Transaction * );
65 
66     void addAddress( Address * );
67     uint addressId( Address * );
68 
69 private:
70     class InjectorData * d;
71 
72     void next();
73     void createMailboxes();
74     void findMessages();
75     void findDependencies();
76     void updateAddresses( List<Address> * );
77     void createDependencies();
78     void convertInReplyTo();
79     void addMoreReferences();
80     void convertThreadIndex();
81     void insertThreadIndexes();
82     void insertThreadRoots();
83     void insertBodyparts();
84     void addBodypartRow( Bodypart * );
85     void selectMessageIds();
86     void selectUids();
87     void insertMessages();
88     void insertDeliveries();
89     void addPartNumber( Query *, uint, const EString &, Bodypart * = 0 );
90     void addHeader( Query *, Query *, Query *, uint, const EString &, Header * );
91     void addMailbox( Query *, Injectee *, Mailbox * );
92     uint addFlags( Query *, Injectee *, Mailbox * );
93     uint addAnnotations( Query *, Injectee *, Mailbox * );
94     void logDescription();
95     void cache();
96     Query * selectNextvals( const EString &, uint );
97 
98     uint internalDate( Message * ) const;
99 };
100 
101 
102 
103 #endif
104