Skip to content
Permalink
Browse files

Implemented per-user flags for public folders

Added funcionality for per-user flags using aditional table in the database that keeps track which user read which message in a public folder.
  • Loading branch information...
94ivana committed Oct 26, 2017
1 parent 8f54c73 commit d129a38b153ede57c58883547502fc5ddd7b3c2b
@@ -12,6 +12,8 @@ if exists (select * from sysobjects where id = object_id('hm_domain_aliases') an

if exists (select * from sysobjects where id = object_id('hm_messages') and objectproperty(id, 'isusertable') = 1) drop table hm_messages

if exists (select * from sysobjects where id = object_id('hm_flags') and objectproperty(id, 'isusertable') = 1) drop table hm_flags

if exists (select * from sysobjects where id = object_id('hm_message_metadata') and objectproperty(id, 'isusertable') = 1) drop table hm_message_metadata

if exists (select * from sysobjects where id = object_id('hm_settings') and objectproperty(id, 'isusertable') = 1) drop table hm_settings
@@ -662,6 +664,15 @@ create table hm_logon_failures
failuretime datetime not null
)

create table hm_flags
(
MsgID int not null,
UsrID int not null,
Flag int
)

ALTER TABLE hm_flags ADD CONSTRAINT hm_flags_pk PRIMARY KEY NONCLUSTERED (MsgID,UsrID)

CREATE NONCLUSTERED INDEX idx_hm_logon_failures_ipaddress ON hm_logon_failures (ipaddress1, ipaddress2)

CREATE CLUSTERED INDEX idx_hm_logon_failures_failuretime ON hm_logon_failures (failuretime)
@@ -952,6 +963,3 @@ insert into hm_tcpipports (portprotocol, portnumber, portaddress1, portaddress2,
insert into hm_tcpipports (portprotocol, portnumber, portaddress1, portaddress2, portconnectionsecurity, portsslcertificateid) values (5, 143, 0, NULL, 0, 0)

insert into hm_dbversion values (5700)



@@ -12,6 +12,8 @@ drop table if exists hm_domain_aliases;

drop table if exists hm_messages;

drop table if exists hm_flags;

drop table if exists hm_message_metadata;

drop table if exists hm_dbversion;
@@ -165,6 +167,15 @@ CREATE INDEX idx_hm_messages ON hm_messages (messageaccountid, messagefolderid);

CREATE INDEX idx_hm_messages_type ON hm_messages (messagetype);

create table hm_flags
(

MsgID int not null ,
UsrID in not null ,
Flag int,
primary key (MsgID,UsrID)
) DEFAULT CHARSET=utf8;

create table hm_message_metadata
(
metadata_id bigint auto_increment not null, primary key(`metadata_id`),
@@ -23,6 +23,8 @@ select hm_drop_table('hm_domain_aliases');

select hm_drop_table('hm_messages');

select hm_drop_table('hm_flags');

select hm_drop_table('hm_message_metadata');

select hm_drop_table('hm_dbversion');
@@ -179,6 +181,15 @@ CREATE INDEX idx_hm_messages ON hm_messages (messageaccountid, messagefolderid);

CREATE INDEX idx_hm_messages_type ON hm_messages (messagetype);

create table hm_flags
(

MsgID int not null,
UsrID int not null,
Flag int,
primary key (MsgID,UsrID)
);

create table hm_message_metadata
(
metadata_id bigserial not null primary key,
@@ -6,4 +6,14 @@ insert into hm_settings (settingname, settingstring, settinginteger) values ('En

insert into hm_settings (settingname, settingstring, settinginteger) values ('EnableImapSASLInitialResponse', '', 0)

if exists (select * from sysobjects where id = object_id('hm_flags') and objectproperty(id, 'isusertable') = 1) drop table hm_flags

create table hm_flags (
MsgID int not null,
UsrID int not null,
Flag int
)

ALTER TABLE hm_flags ADD CONSTRAINT hm_flags_pk PRIMARY KEY NONCLUSTERED (MsgID,UsrID)

update hm_dbversion set value = 5700;
@@ -6,4 +6,15 @@ insert into hm_settings (settingname, settingstring, settinginteger) values ('En

insert into hm_settings (settingname, settingstring, settinginteger) values ('EnableImapSASLInitialResponse', '', 0)

if exists (select * from sysobjects where id = object_id('hm_flags') and objectproperty(id, 'isusertable') = 1) drop table hm_flags

create table hm_flags(

MsgID int not null,
UsrID int not null,
Flag int
)

ALTER TABLE hm_flags ADD CONSTRAINT hm_flags_pk PRIMARY KEY NONCLUSTERED (MsgID,UsrID)

update hm_dbversion set value = 5700
@@ -6,4 +6,15 @@ insert into hm_settings (settingname, settingstring, settinginteger) values ('En

insert into hm_settings (settingname, settingstring, settinginteger) values ('EnableImapSASLInitialResponse', '', 0);

drop table if exists hm_flags;

create table hm_flags
(

MsgID int not null ,
UsrID in not null ,
Flag int,
primary key (MsgID,UsrID)
) DEFAULT CHARSET=utf8;

update hm_dbversion set value = 5700;
@@ -107,7 +107,7 @@ namespace HM
}

bool
FolderManager::UpdateMessageFlags(int accountID, int folderID, __int64 messageID, int flags)
FolderManager::UpdateMessageFlags(int accountID, int folderID, __int64 messageID, int flags, int user)
{
std::shared_ptr<IMAPFolders> folders;
if (accountID > 0)
@@ -127,8 +127,16 @@ namespace HM
if (!message)
return false;

message->SetFlags(flags);
return PersistentMessage::SaveFlags(message);
if (message->GetAccountID() == 0)
{
message->SetFlagsByUsr(user, flags, message->GetID());
return PersistentMessage::SaveFlagsPublic(message, user);
}
else
{
message->SetFlags(flags);
return PersistentMessage::SaveFlags(message);
}
}


@@ -18,7 +18,7 @@ namespace HM
bool GetInboxMessages(int accountID, std::vector<std::shared_ptr<Message> > &result);
bool DeleteInboxMessages(int accountID, std::set<int> uids, const std::function<void()> &callbackEvery1000Message);

bool UpdateMessageFlags(int accountID, int folderID, __int64 messageID, int flags);
bool UpdateMessageFlags(int accountID, int folderID, __int64 messageID, int flags, int user);

private:

@@ -89,6 +89,15 @@ namespace HM
{
return (flags_ & iFlag) > 0;
}
bool
Message::GetFlagByUsr_(int iFlag, int usr, int msgid) const
{
SQLCommand command2("select * from hm_flags where MsgID = @MSGID and UsrID = @USERID ");
command2.AddParameter("@MSGID", msgid);
command2.AddParameter("@USERID", usr);
std::shared_ptr<DALRecordset> pRS2 = Application::Instance()->GetDBManager()->OpenRecordset(command2);
return (((short)pRS2->GetLongValue("Flag")) & iFlag > 0);
}

void
Message::SetFlag_(int iFlag, bool bSet)
@@ -98,19 +107,65 @@ namespace HM
else
flags_ = flags_ & ~iFlag;
}
void
Message::SetFlagByUsr_(int iFlag, bool bSet, int iUsr, int msgid)
{
if (bSet)
flags_ = flags_ | iFlag;
else
flags_ = flags_ & ~iFlag;
SQLCommand com("select * from hm_flags where MsgID=@MSGID and UsrID=@USRID");
com.AddParameter("@MSGID", msgid);
com.AddParameter("@USRID", iUsr);
std::shared_ptr<DALRecordset> pRS2;
pRS2 = Application::Instance()->GetDBManager()->OpenRecordset(com);
int MessageID = pRS2->GetLongValue("MsgID");
if (MessageID == 0)
{
SQLStatement oStatement;
oStatement.SetStatementType(SQLStatement::STInsert);
oStatement.SetTable("hm_flags");
oStatement.SetIdentityColumn("DataID");
oStatement.AddColumn("MsgID", msgid);
oStatement.AddColumn("UsrID", iUsr);

oStatement.AddColumn("Flag", flags_);
Application::Instance()->GetDBManager()->Execute(oStatement);
}
else
{
SQLCommand komanda("update hm_flags set Flag = @FLAGS where MsgID=@MSGID and UsrID=@USRID");
komanda.AddParameter("@FLAGS", flags_);
komanda.AddParameter("@MSGID", msgid);
komanda.AddParameter("@USRID", iUsr);
Application::Instance()->GetDBManager()->Execute(komanda);
}
}

bool
Message::GetFlagSeen() const
{
return GetFlag_(FlagSeen);
}

bool
Message::GetFlagSeenByUsr(int usr, int msgid) const
{
return GetFlagByUsr_(FlagSeen, usr, msgid);
}

void
Message::SetFlagSeen(bool bNewVal)
{
SetFlag_(FlagSeen, bNewVal);
}

void
Message::SetFlagSeenByUsr(int usr, bool nVal, int msgid)
{
SetFlagByUsr_(FlagSeen, nVal, usr, msgid);
}

bool
Message::GetFlagDeleted() const
{
@@ -63,10 +63,49 @@ namespace HM
void SetFolderID(__int64 iFolderID) { message_folder_id_ = (int) iFolderID; }

short GetFlags() {return flags_; }
short GetFlagsByUsr(int usr, int msgid)
{
SQLCommand command2("select * from hm_flags where MsgID = @MSGID and UsrID = @USERID ");
command2.AddParameter("@MSGID", msgid);
command2.AddParameter("@USERID", usr);
std::shared_ptr<DALRecordset> pRS2 = Application::Instance()->GetDBManager()->OpenRecordset(command2);
return (short)pRS2->GetLongValue("Flag");
}
void SetFlags(short iNewVal) {flags_ = iNewVal; }
void SetFlagsByUsr(int user, short iNewVal, int msgid)
{
SQLCommand com("select * from hm_flags where MsgID=@MSGID and UsrID=@USRID");
com.AddParameter("@MSGID", msgid);
com.AddParameter("@USRID", user);
std::shared_ptr<DALRecordset> pRS2;
pRS2 = Application::Instance()->GetDBManager()->OpenRecordset(com);
int MessageID = pRS2->GetLongValue("MsgID");
if (MessageID == 0)
{
SQLStatement oStatement;
oStatement.SetStatementType(SQLStatement::STInsert);
oStatement.SetTable("hm_flags");
oStatement.SetIdentityColumn("DataID");
oStatement.AddColumn("MsgID", msgid);
oStatement.AddColumn("UsrID", user);

oStatement.AddColumn("Flag", flags_);
Application::Instance()->GetDBManager()->Execute(oStatement);
}
else
{
SQLCommand komanda("update hm_flags set Flag = @FLAGS where MsgID=@MSGID and UsrID=@USRID");
komanda.AddParameter("@FLAGS", flags_);
komanda.AddParameter("@MSGID", msgid);
komanda.AddParameter("@USRID", user);
Application::Instance()->GetDBManager()->Execute(komanda);
}
}

bool GetFlagSeen() const;
bool GetFlagSeenByUsr(int usr, int msgid) const;
void SetFlagSeen(bool bNewVal);
void SetFlagSeenByUsr(int usr, bool nVal, int msgid);
bool GetFlagDeleted() const;
void SetFlagDeleted(bool bNewVal);
bool GetFlagDraft() const;
@@ -115,6 +154,8 @@ namespace HM

bool GetFlag_(int iFlag) const;
void SetFlag_(int iFlag, bool bSet);
bool GetFlagByUsr_(int iFlag, int usr, int msgid) const;
void SetFlagByUsr_(int iFlag, bool bSet, int iUsr, int msgid);

std::shared_ptr<MessageRecipients> recipients_;

@@ -53,12 +53,21 @@ namespace HM

if (iMessageID > 0)
{
SQLCommand command(_T("delete from hm_messages where messageid = @MESSAGEID"));
SQLCommand command;
SQLCommand command1;
command.SetQueryString(_T("delete from hm_messages where messageid = @MESSAGEID"));
command.AddParameter("@MESSAGEID", iMessageID);

if (pMessage->GetAccountID() == 0)
{
command1.SetQueryString(_T("delete from hm_flags where MsgID = @MESSAGEID"));
command1.AddParameter("@MESSAGEID", iMessageID);

}
if (!Application::Instance()->GetDBManager()->Execute(command))
return false;

if (!Application::Instance()->GetDBManager()->Execute(command1))
return false;
// If the message is placed into an account, there won't be any recipients
// connected to it. If the message is still in the queue, we must delete the
// recipients as well.
@@ -204,7 +213,24 @@ namespace HM
pMessage->SetNoOfRetries((unsigned short) pRS->GetLongValue("messagecurnooftries"));
pMessage->SetFolderID(pRS->GetLongValue("messagefolderid"));

pMessage->SetFlags((short) pRS->GetLongValue("messageflags"));
if (pRS->GetLongValue("messageaccountid") == 0)
{
SQLCommand command2("select * from hm_flags where MsgID = @MSGID ");

command2.AddParameter("@MSGID", pMessage->GetID());
std::shared_ptr<DALRecordset> pRS2 = Application::Instance()->GetDBManager()->OpenRecordset(command2);

while (!pRS2->IsEOF())
{
int userID = pRS2->GetLongValue("UsrID");
pMessage->SetFlagsByUsr(userID, (short)pRS2->GetLongValue("Flag"), pMessage->GetID());
pRS2->MoveNext();
}
}
else
{
pMessage->SetFlags((short)pRS->GetLongValue("messageflags"));
}
pMessage->SetUID((unsigned int) pRS->GetLongValue("messageuid"));

if (bReadRecipients)
@@ -1269,6 +1295,17 @@ namespace HM

return Application::Instance()->GetDBManager()->Execute(sqlCommand);
}
bool
PersistentMessage::SaveFlagsPublic(std::shared_ptr<Message> message, int uss)
{
String statement = "UPDATE hm_flags SET Flag = @FLAGS WHERE MsgID = @MESSAGEID";

SQLCommand sqlCommand(statement);
sqlCommand.AddParameter("@FLAGS", message->GetFlagsByUsr(uss, message->GetID()));
sqlCommand.AddParameter("@MESSAGEID", message->GetID());

return Application::Instance()->GetDBManager()->Execute(sqlCommand);
}

bool
PersistentMessage::IsPartialPath(const String &path)
@@ -72,6 +72,7 @@ namespace HM
static bool GetPartialFilename(const String &fullPath, String &partialPath);

static bool SaveFlags(std::shared_ptr<Message> message);
static bool SaveFlagsPublic(std::shared_ptr<Message> message, int uss);

static bool IsPartialPath(const String &path);
int GetLatestMessageId();

0 comments on commit d129a38

Please sign in to comment.
You can’t perform that action at this time.