/// <summary>
 /// Returns a value indicating whether the given mailbox can be accepted as a recipient to the given sender.
 /// </summary>
 /// <param name="context">The session context.</param>
 /// <param name="to">The mailbox to test.</param>
 /// <param name="from">The sender's mailbox.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The acceptance state of the mailbox.</returns>
 public override Task <MailboxFilterResult> CanDeliverToAsync(
     ISessionContext context,
     IMailbox to,
     IMailbox @from,
     CancellationToken cancellationToken)
 {
     return(Task.FromResult(MailboxFilterResult.Yes));
 }
        public void WaitForActor(IMailbox <object> mailbox)
        {
            var actorInfo = GetCurrentActorInfo();
            var otherInfo = ((Mailbox <object>)mailbox).ownerActorInfo;

            WaitHelper(actorInfo, otherInfo);
            ThrowWaitExceptionIfNeeded(otherInfo);
        }
Example #3
0
        public virtual void GetMailboxById()
        {
            peter_mailbox = server.CreateMailbox(peter_address.LocalPart, PETER_PASSWORD, peter_address.Domain, peter_account, TestContext.ServerFactory);

            var mailboxGettedById = server.GetMailbox(peter_mailbox.Id, TestContext.ServerFactory);

            Assert.IsTrue(peter_mailbox.Equals(mailboxGettedById));
        }
        internal static Actor ActorFor(
            Stage stage,
            Actor parent,
            Definition definition,
            IAddress address,
            IMailbox mailbox,
            ISupervisor supervisor,
            ILogger logger)
        {
            var environment = new Environment(
                stage,
                address,
                definition,
                parent,
                mailbox,
                supervisor,
                logger);

            ThreadLocalEnvironment.Value = environment;

            Actor actor = null;

            int definitionParameterCount = definition.InternalParameters().Count;

            if (definitionParameterCount == 0)
            {
                actor = (Actor)Activator.CreateInstance(definition.Type);
            }
            else
            {
                foreach (var ctor in definition.Type.GetConstructors())
                {
                    if (ctor.GetParameters().Length != definitionParameterCount)
                    {
                        continue;
                    }

                    actor = Start(ctor, address, definition, logger);

                    if (actor != null)
                    {
                        break;
                    }
                }
            }

            if (actor == null)
            {
                throw new MissingMethodException("No constructor matches the given number of parameters.");
            }

            if (parent != null)
            {
                parent.LifeCycle.Environment.AddChild(actor);
            }

            return(actor);
        }
Example #5
0
 public void UnlockMutex(IMailbox<object> me)
 {
     Safety.Assert(owner == me);
     owner = null;
     if (lockQueue.Count <= 0) return;
     owner = lockQueue[0];
     lockQueue.RemoveAt(0);
     owner.Send(new object());
 }
 public TaskCompletionSourceHelper(
     IActorRuntime runtime,
     IMailbox<object> taskMailbox,
     Task task)
 {
     this.runtime = runtime;
     this.taskMailbox = taskMailbox;
     this.task = task;
 }
Example #7
0
        /// <summary>
        /// Returns the Mailbox as an Address string.
        /// </summary>
        /// <param name="mailbox">The mailbox to perform the operation on.</param>
        /// <returns>The address string that represents the mailbox.</returns>
        public static string AsAddress(this IMailbox mailbox)
        {
            if (mailbox == null)
            {
                throw new ArgumentNullException(nameof(mailbox));
            }

            return(String.Format(CultureInfo.InvariantCulture, "{0}@{1}", mailbox.User, mailbox.Host));
        }
        public void Setup()
        {
            var      executionRepository = new ExecutionRepository();
            IMailbox mailbox             = executionRepository;
            IReportCommandExecution reportCommandExecution = executionRepository;

            _getCommandResult = executionRepository;
            _dispatcher       = new MyDispatcher(reportCommandExecution, mailbox);
        }
        protected virtual void OnAddedMailbox(IMailbox e)
        {
            EventHandler <IMailbox> handler = AddedMailbox;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #10
0
 public void PulseAllMutex(IMailbox <object> me)
 {
     Safety.Assert(owner == me);
     foreach (var mailbox in waitQueue)
     {
         mailbox.Send(new object());
     }
     waitQueue.Clear();
 }
Example #11
0
 public void CheckMessages(IMailbox<string> res)
 {
     StringBuilder sb = new StringBuilder();
     foreach (var m in _messages)
     {
         sb.Append($"From: {m.Item1};\n Message: {m.Item2}\n\n");
     }
     res.Send(sb.ToString());
 }
        private static void FindWellKnownFolders(IMailbox mailbox, PropTagFolderMapping[] map, FolderHierarchyUtils.GetPropsDelegate getProps, Dictionary <WellKnownFolderType, byte[]> wellKnownFolders)
        {
            NamedPropMapper namedPropMapper = CommonUtils.CreateNamedPropMapper(mailbox);

            PropTag[] array = new PropTag[map.Length];
            for (int i = 0; i < map.Length; i++)
            {
                InboxNamedPropFolderMapping inboxNamedPropFolderMapping = map[i] as InboxNamedPropFolderMapping;
                if (inboxNamedPropFolderMapping != null)
                {
                    namedPropMapper.ByNamedProp.AddKey(inboxNamedPropFolderMapping.NamedPropData);
                }
            }
            for (int j = 0; j < map.Length; j++)
            {
                InboxNamedPropFolderMapping inboxNamedPropFolderMapping2 = map[j] as InboxNamedPropFolderMapping;
                if (inboxNamedPropFolderMapping2 != null)
                {
                    array[j] = namedPropMapper.MapNamedProp(inboxNamedPropFolderMapping2.NamedPropData, PropType.Binary);
                }
                else
                {
                    array[j] = map[j].Ptag;
                }
            }
            PropValueData[] a      = getProps(array);
            PropValue[]     native = DataConverter <PropValueConverter, PropValue, PropValueData> .GetNative(a);

            for (int k = 0; k < map.Length; k++)
            {
                byte[] array2 = null;
                if (!native[k].IsNull() && !native[k].IsError())
                {
                    InboxIndexedFolderMapping inboxIndexedFolderMapping = map[k] as InboxIndexedFolderMapping;
                    if (inboxIndexedFolderMapping == null)
                    {
                        array2 = native[k].GetBytes();
                    }
                    else
                    {
                        byte[][] bytesArray = native[k].GetBytesArray();
                        if (bytesArray != null && bytesArray.Length > inboxIndexedFolderMapping.EntryIndex)
                        {
                            array2 = bytesArray[inboxIndexedFolderMapping.EntryIndex];
                        }
                        else
                        {
                            array2 = null;
                        }
                    }
                }
                if (array2 != null)
                {
                    wellKnownFolders[map[k].WKFType] = array2;
                }
            }
        }
 public TaskCompletionSourceHelper(
     IActorRuntime runtime,
     IMailbox <object> taskMailbox,
     Task task)
 {
     this.runtime     = runtime;
     this.taskMailbox = taskMailbox;
     this.task        = task;
 }
Example #14
0
 public NamedPropMapper(IMailbox mailbox, bool createMappingsIfNeeded)
 {
     this.mailbox = mailbox;
     this.createMappingsIfNeeded = createMappingsIfNeeded;
     this.byId        = new NamedPropMapper.PropIdIndex();
     this.byNamedProp = new NamedPropMapper.NamedPropIndex();
     base.RegisterIndex(this.byId);
     base.RegisterIndex(this.byNamedProp);
 }
Example #15
0
 public void PulseAllMutex(IMailbox<object> me)
 {
     Safety.Assert(owner == me);
     foreach (var mailbox in waitQueue)
     {
         mailbox.Send(new object());
     }
     waitQueue.Clear();
 }
Example #16
0
        /// <summary>
        /// Returns a value indicating whether the given mailbox can be accepted as a recipient to the given sender.
        /// </summary>
        /// <param name="context">The session context.</param>
        /// <param name="to">The mailbox to test.</param>
        /// <param name="from">The sender's mailbox.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The acceptance state of the mailbox.</returns>
        public override async Task <MailboxFilterResult> CanDeliverToAsync(
            ISessionContext context,
            IMailbox to,
            IMailbox @from,
            CancellationToken cancellationToken)
        {
            await Task.Delay(_delay, cancellationToken);

            return(MailboxFilterResult.Yes);
        }
Example #17
0
        public MyDispatcher(IReportCommandExecution reportCommandExecution, IMailbox mailbox)
        {
            _reportCommandExecution = reportCommandExecution;
            _mailbox = mailbox;

            _commandToHandlerMapping = new Dictionary <Type, Type>();
            _queryToHandlerMapping   = new Dictionary <Type, Type>();

            Discover();
        }
Example #18
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="mailboxFilterFactory">The mailbox filter factory to use.</param>
        public RcptCommand(IMailbox address, IMailboxFilterFactory mailboxFilterFactory)
        {
            if (mailboxFilterFactory == null)
            {
                throw new ArgumentNullException(nameof(mailboxFilterFactory));
            }

            _address = address;
            _mailboxFilterFactory = mailboxFilterFactory;
        }
Example #19
0
        public void CheckMessages(IMailbox <string> res)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var m in _messages)
            {
                sb.Append($"From: {m.Item1};\n Message: {m.Item2}\n\n");
            }
            res.Send(sb.ToString());
        }
Example #20
0
 public PrincipalMapper(IMailbox mailbox)
 {
     this.mailbox       = mailbox;
     this.byMailboxGuid = new PrincipalMapper.MailboxGuidIndex();
     this.bySid         = new PrincipalMapper.SidIndex();
     this.byX500Proxy   = new PrincipalMapper.X500ProxyIndex();
     base.RegisterIndex(this.byMailboxGuid);
     base.RegisterIndex(this.bySid);
     base.RegisterIndex(this.byX500Proxy);
 }
Example #21
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="mailboxFilterFactory">The mailbox filter factory to use.</param>
        public RcptCommand(IMailbox address, IMailboxFilterFactory mailboxFilterFactory)
        {
            if (mailboxFilterFactory == null)
            {
                throw new ArgumentNullException(nameof(mailboxFilterFactory));
            }

            _address = address;
            _mailboxFilterFactory = mailboxFilterFactory;
        }
Example #22
0
 public static MailboxData ToMailboxData(this IMailbox mailbox)
 {
     return(new MailboxData
     {
         Id = mailbox.Id,
         UserId = mailbox.Account.TeamlabAccount.ID.ToString(),
         Address = mailbox.Address.ToAddressData(),
         Aliases = mailbox.Aliases.Select(addr => addr.ToAddressData()).ToList()
     });
 }
Example #23
0
        public void LockMutex(IMailbox<object> me)
        {
            if (owner == null)
            {
                owner = me;
                me.Send(new object());
                return;
            }

            lockQueue.Add(me);
        }
Example #24
0
        private T GetOrCreateProxy <T>(IMailbox <object> mailbox)
            where T : ITypedActor
        {
            Type proxyType = proxies.GetProxyType(typeof(T));
            var  res       = (T)Activator.CreateInstance(
                proxyType,
                mailbox,
                actorRuntime);

            return(res);
        }
Example #25
0
        private static object TryCreateWithProxyClass(Type proxyClass, Actor actor, IMailbox mailbox)
        {
            var instance = Activator.CreateInstance(proxyClass, actor, mailbox);

            if (instance == null)
            {
                throw new ArgumentException($"Cannot create an instance for proxy class '{proxyClass.FullName}'");
            }

            return(instance);
        }
Example #26
0
        public void LockMutex(IMailbox <object> me)
        {
            if (owner == null)
            {
                owner = me;
                me.Send(new object());
                return;
            }

            lockQueue.Add(me);
        }
 public void Init()
 {
     server = TestContext.CreateServer();
     peter_domain = server.CreateWebDomain(_peterDomainName, IS_VERIFIED, TestContext.ServerFactory);
     peter_mail_group_address = TestContext.CreateRandomMailAddress(peter_domain);
     var peterMailboxAddress = TestContext.CreateRandomMailAddress(peter_domain);
     var peterAccount = TestContext.GetMailAccount(peterMailboxAddress.LocalPart, _peterDomainName);
     peter_mailbox = server.CreateMailbox(peterMailboxAddress.LocalPart, PETER_PASSWORD, peterMailboxAddress.Domain, peterAccount,
                                          TestContext.ServerFactory);
     peter_mail_group = server.CreateMailGroup(peter_mail_group_address.LocalPart, peter_mail_group_address.Domain, new List<int> { peter_mailbox.Address.Id }, TestContext.ServerFactory);
 }
 public void SubscribeSource(string source, IMailbox subscriber)
 {
     if (pushSubscriptions.ContainsKey(source))
     {
         pushSubscriptions[source] = subscriber;
     }
     else
     {
         pushSubscriptions.Add(source, subscriber);
     }
 }
Example #29
0
        internal object[] ActorProxyFor(Type[] protocols, Actor actor, IMailbox mailbox)
        {
            var proxies = new object[protocols.Length];

            for (int idx = 0; idx < protocols.Length; ++idx)
            {
                proxies[idx] = ActorProxyFor(protocols[idx], actor, mailbox);
            }

            return(proxies);
        }
Example #30
0
            public Task<MailboxFilterResult> CanAcceptFromAsync(IMailbox @from, int size = 0)
            {
               
                    if (String.Equals(@from.Host, "test.com"))
                    {
                        return Task.FromResult(MailboxFilterResult.Yes);
                    }

                    return Task.FromResult(MailboxFilterResult.NoPermanently);
                
            }
        /// <summary>
        /// Returns a value indicating whether the given mailbox can be accepted as a sender.
        /// </summary>
        /// <param name="context">The session context.</param>
        /// <param name="from">The mailbox to test.</param>
        /// <param name="size">The estimated message size to accept.</param>
        /// <returns>The acceptance state of the mailbox.</returns>
        public async Task<MailboxFilterResult> CanAcceptFromAsync(ISessionContext context, IMailbox @from, int size = 0)
        {
            if (_filters == null || _filters.Any() == false)
            {
                return MailboxFilterResult.Yes;
            }

            var results = await Task.WhenAll(_filters.Select(f => f.CanAcceptFromAsync(context, @from, size)));

            return results.Max();
        }
Example #32
0
        private static object TryCreate(Actor actor, IMailbox mailbox, Type protocol, string targetClassname)
        {
            var proxyClass = LoadProxyClassFor(targetClassname, actor);
            if (proxyClass != null && proxyClass.IsGenericTypeDefinition)
            {
                var genericTypeParams = protocol.GetGenericArguments();
                proxyClass = proxyClass.MakeGenericType(genericTypeParams);
            }

            return TryCreateWithProxyClass(proxyClass, actor, mailbox);
        }
        /// <summary>
        /// Returns a value indicating whether the given mailbox can be accepted as a recipient to the given sender.
        /// </summary>
        /// <param name="context">The session context.</param>
        /// <param name="to">The mailbox to test.</param>
        /// <param name="from">The sender's mailbox.</param>
        /// <returns>The acceptance state of the mailbox.</returns>
        public async Task<MailboxFilterResult> CanDeliverToAsync(ISessionContext context, IMailbox to, IMailbox @from)
        {
            if (_filters == null || _filters.Any() == false)
            {
                return MailboxFilterResult.Yes;
            }

            var results = await Task.WhenAll(_filters.Select(f => f.CanDeliverToAsync(context, to, @from)));

            return results.Max();
        }
Example #34
0
        public virtual void AddMemberToMailGroup()
        {
            var peterAddress = TestContext.CreateRandomMailAddress(peter_domain);

            peter_mailbox = server.CreateMailbox(peterAddress.LocalPart, PETER_PASSWORD, peterAddress.Domain, TestContext.GetMailAccount(peterAddress.LocalPart, _peterDomainName), TestContext.ServerFactory);
            peter_mail_group.AddMember(peter_mailbox.Address.Id, TestContext.ServerFactory);
            var mailGroupMembers = peter_mail_group.GetMembers(TestContext.ServerFactory);

            Assert.Greater(mailGroupMembers.Count, 0);
            Assert.IsTrue(mailGroupMembers.Contains(peter_mailbox.Address));
        }
        public virtual void AliasAddAndRemoveSyncronizationWithServerTest()
        {
            peter_alias = peter_mailbox.AddAlias(peter_alias.LocalPart, peter_alias.Domain, TestContext.ServerFactory);
            peter_mailbox = server.GetMailbox(peter_mailbox.Id, TestContext.ServerFactory);
            Assert.IsTrue(peter_mailbox.Aliases.Contains(peter_alias));

            peter_mailbox.RemoveAlias(peter_alias.Id);
            peter_mailbox = server.GetMailbox(peter_mailbox.Id, TestContext.ServerFactory);
            Assert.IsFalse(peter_mailbox.Aliases.Contains(peter_alias));
            server.DeleteMailbox(peter_mailbox);
        }
Example #36
0
        public virtual void AliasAddAndRemoveSyncronizationWithServerTest()
        {
            peter_alias   = peter_mailbox.AddAlias(peter_alias.LocalPart, peter_alias.Domain, TestContext.ServerFactory);
            peter_mailbox = server.GetMailbox(peter_mailbox.Id, TestContext.ServerFactory);
            Assert.IsTrue(peter_mailbox.Aliases.Contains(peter_alias));

            peter_mailbox.RemoveAlias(peter_alias.Id);
            peter_mailbox = server.GetMailbox(peter_mailbox.Id, TestContext.ServerFactory);
            Assert.IsFalse(peter_mailbox.Aliases.Contains(peter_alias));
            server.DeleteMailbox(peter_mailbox);
        }
        /// <summary>
        /// Returns a value indicating whether the given mailbox can be accepted as a sender.
        /// </summary>
        /// <param name="context">The session context.</param>
        /// <param name="from">The mailbox to test.</param>
        /// <param name="size">The estimated message size to accept.</param>
        /// <returns>The acceptance state of the mailbox.</returns>
        public override Task<MailboxFilterResult> CanAcceptFromAsync(ISessionContext context, IMailbox @from, int size = 0)
        {
            var endpoint = (IPEndPoint) context.RemoteEndPoint;
            
            // only accept connections from localhost
            if (endpoint.Address.Equals(IPAddress.Parse("127.0.0.1")))
            {
                return Task.FromResult(MailboxFilterResult.Yes);
            }

            return Task.FromResult(MailboxFilterResult.NoPermanently);
        }
Example #38
0
        public void Execute(IMailbox mailbox)
        {
            if (IsClosed)
            {
                return;
            }

            if (mailbox.Delivering(true))
            {
                executor.Execute(mailbox);
            }
        }
Example #39
0
        private void RemoveMailboxFunction(IMailbox o)
        {
            var item = o as MboxMailbox;

            if (item != null)
            {
                if (Account.Mailboxes.Contains <MboxMailbox>(item))
                {
                    Account.Mailboxes.Remove <MboxMailbox>(item);
                }
            }
        }
Example #40
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="parameters">The list of extended (ESMTP) parameters.</param>
        /// <param name="mailboxFilterFactory">The mailbox filter factory to create the filters from.</param>
        /// <param name="maxMessageSize">The maximum message size (0 for no limit).</param>
        public MailCommand(IMailbox address, IDictionary<string, string> parameters, IMailboxFilterFactory mailboxFilterFactory, int maxMessageSize = 0)
        {
            if (mailboxFilterFactory == null)
            {
                throw new ArgumentNullException(nameof(mailboxFilterFactory));
            }

            _address = address;
            _parameters = parameters;
            _mailboxFilterFactory = mailboxFilterFactory;
            _maxMessageSize = maxMessageSize;
        }
Example #41
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="parameters">The list of extended (ESMTP) parameters.</param>
        /// <param name="mailboxFilterFactory">The mailbox filter factory to create the filters from.</param>
        /// <param name="maxMessageSize">The maximum message size (0 for no limit).</param>
        public MailCommand(IMailbox address, IDictionary <string, string> parameters, IMailboxFilterFactory mailboxFilterFactory, int maxMessageSize = 0)
        {
            if (mailboxFilterFactory == null)
            {
                throw new ArgumentNullException(nameof(mailboxFilterFactory));
            }

            _address              = address;
            _parameters           = parameters;
            _mailboxFilterFactory = mailboxFilterFactory;
            _maxMessageSize       = maxMessageSize;
        }
Example #42
0
 public void Init()
 {
     server               = TestContext.CreateServer();
     peter_domain         = server.CreateWebDomain(_peterDomainName, IS_VERIFIED, TestContext.ServerFactory);
     peter_address        = TestContext.CreateRandomMailAddress(peter_domain);
     peter_second_address = TestContext.CreateRandomMailAddress(peter_domain);
     peter_alias          = TestContext.CreateRandomMailAddress(peter_domain);
     peter_account        = TestContext.GetMailAccount(peter_address.LocalPart, _peterDomainName);
     peter_second_account = TestContext.GetMailAccount(peter_second_address.LocalPart, _peterDomainName);
     peter_mailbox        = server.CreateMailbox(peter_address.LocalPart, PETER_PASSWORD, peter_domain, peter_account, TestContext.ServerFactory);
     peter_second_mailbox = server.CreateMailbox(peter_second_address.LocalPart, PETER_PASSWORD, peter_domain, peter_second_account, TestContext.ServerFactory);
 }
Example #43
0
        private void RemoveMailboxFunction(IMailbox o)
        {
            var item = o as AuthenticatedMailbox;

            if (item != null)
            {
                if (_account.Mailboxes.Contains <AuthenticatedMailbox>(item))
                {
                    _account.Mailboxes.Remove <AuthenticatedMailbox>(item);
                }
            }
        }
 public void Init()
 {
     server = TestContext.CreateServer();
     peter_domain = server.CreateWebDomain(_peterDomainName, IS_VERIFIED, TestContext.ServerFactory);
     peter_address = TestContext.CreateRandomMailAddress(peter_domain);
     peter_second_address = TestContext.CreateRandomMailAddress(peter_domain);
     peter_alias = TestContext.CreateRandomMailAddress(peter_domain);
     peter_account = TestContext.GetMailAccount(peter_address.LocalPart, _peterDomainName);
     peter_second_account = TestContext.GetMailAccount(peter_second_address.LocalPart, _peterDomainName);
     peter_mailbox = server.CreateMailbox(peter_address.LocalPart, PETER_PASSWORD, peter_domain, peter_account, TestContext.ServerFactory);
     peter_second_mailbox = server.CreateMailbox(peter_second_address.LocalPart, PETER_PASSWORD, peter_domain, peter_second_account, TestContext.ServerFactory);
 }
Example #45
0
        public void Clean()
        {
            if (peter_mailbox != null)
            {
                server.DeleteMailbox(peter_mailbox);
                peter_mailbox = null;
            }

            if (peter_domain != null)
            {
                server.DeleteWebDomain(peter_domain, TestContext.ServerFactory);
                peter_domain = null;
            }
        }
Example #46
0
        public virtual void CreateMailboxOnServer()
        {
            peter_mailbox = server.CreateMailbox(peter_address.LocalPart, PETER_PASSWORD, peter_address.Domain, peter_account, TestContext.ServerFactory);

            Assert.Greater(peter_mailbox.Id, 0, "mailbox.Id must be > 0");
            Assert.GreaterOrEqual(peter_mailbox.Tenant, 0, "mailbox.Tenant must be >= 0");
            Assert.IsNotNull(peter_mailbox.Account, "mailbox.Account");
            Assert.IsNotNull(peter_mailbox.Address, "mailbox.Address");
            Assert.IsNotNull(peter_mailbox.Aliases, "mailbox.Aliases");

            Assert.IsNotEmpty(peter_mailbox.Account.Login);
            Assert.IsNotNull(peter_mailbox.Account.TeamlabAccount);

            Assert.Greater(peter_mailbox.Address.Id, 0);
            Assert.GreaterOrEqual(peter_mailbox.Address.Tenant, 0);
            Assert.IsNotEmpty(peter_mailbox.Address.LocalPart);

            Assert.IsNotNull(peter_mailbox.Address.Domain);
            Assert.Greater(peter_mailbox.Address.Domain.Id, 0);
            Assert.IsNotEmpty(peter_mailbox.Address.Domain.Name);
        }
Example #47
0
        internal static int AddMailbox(IMailbox mailbox)
        {
            lock (s_slotSync)
            {
                if (!s_active)
                {
                    Activate();
                }

                //  If max_sockets limit was reached, throw exception.
                if (s_emptySlots.Count == 0)
                {
                    throw new NetMQException(ErrorCode.TooManyOpenSockets);
                }

                //  Choose a slot for the socket.
                int slot = s_emptySlots.Dequeue();
                s_slots[slot] = mailbox;

                return slot;
            }
        }
Example #48
0
 /// <summary>
 /// Returns a value indicating whether the given mailbox can be accepted as a sender.
 /// </summary>
 /// <param name="context">The session context.</param>
 /// <param name="from">The mailbox to test.</param>
 /// <param name="size">The estimated message size to accept.</param>
 /// <returns>The acceptance state of the mailbox.</returns>
 public virtual Task<MailboxFilterResult> CanAcceptFromAsync(ISessionContext context, IMailbox @from, int size = 0)
 {
     return Task.FromResult(MailboxFilterResult.Yes);
 }
Example #49
0
 public MailboxBase(IMailbox mailbox)
     : this(new MailAccountBase(mailbox.Account), new MailAddressBase(mailbox.Address), mailbox.Aliases.Select(a => new MailAddressBase(a)).ToList())
 {
     
 }
Example #50
0
        public virtual void GetMailboxByNonExistentId()
        {
            peter_mailbox = server.CreateMailbox(peter_address.LocalPart, PETER_PASSWORD, peter_address.Domain, peter_account, TestContext.ServerFactory);
            server.DeleteMailbox(peter_mailbox);
            
            var mailboxesAfterDeleting = server.GetMailboxes(TestContext.ServerFactory);
            Assert.IsFalse(mailboxesAfterDeleting.Contains(peter_mailbox), "Mailbox wasn't deleted.");

            var mailboxGettedById = server.GetMailbox(peter_mailbox.Id, TestContext.ServerFactory);
            Assert.AreEqual(null, mailboxGettedById);
        }
Example #51
0
        public override void DeleteMailbox(IMailbox mailbox)
        {
            if (mailbox == null)
                throw new ArgumentNullException("mailbox", "ServerModel::DeleteMailbox");

            using (var dbContextWithTran = TeamlabMailboxDal.CreateMailDbContext(true))
            {
                TeamlabMailboxDal.DeleteMailbox(mailbox.Id, dbContextWithTran.DbManager);
                _DeleteMailbox(new MailboxBase(mailbox));
                dbContextWithTran.CommitTransaction();
            }

        }
Example #52
0
 public override void UpdateMailbox(IMailbox mailbox)
 {
     _UpdateMailbox(new MailboxBase(mailbox));
 }
 public virtual void DoubleAddMemberToMailGroup()
 {
     var peterAddress = TestContext.CreateRandomMailAddress(peter_domain);
     peter_mailbox = server.CreateMailbox(peterAddress.LocalPart, PETER_PASSWORD, peterAddress.Domain, TestContext.GetMailAccount(peterAddress.LocalPart, _peterDomainName), TestContext.ServerFactory);
     peter_mail_group.AddMember(peter_mailbox.Address.Id, TestContext.ServerFactory);
     var mailGroupMembers = peter_mail_group.GetMembers(TestContext.ServerFactory);
     Assert.Greater(mailGroupMembers.Count, 0);
     Assert.IsTrue(mailGroupMembers.Contains(peter_mailbox.Address));
     Assert.Throws<ArgumentException>(() => peter_mail_group.AddMember(peter_mailbox.Address.Id, TestContext.ServerFactory));
 }
Example #54
0
 /// <summary>
 /// Appends the message to the given mailbox.
 /// </summary>
 /// <remarks>The mailbox's sourceclient has to be connected.</remarks>
 /// <param name="imapMailbox">The mailbox the message has to be appended to.</param>
 /// <example>
 /// <code>
 /// C#
 /// 
 ///Message message = new Message();
 ///message.From = new Address("*****@*****.**","John Doe");
 ///message.To.Add("*****@*****.**","Mike Johns");
 ///message.Subject = "hey!";
 ///message.Attachments.Add("C:\\myfile.doc");
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John.";
 ///
 ///Imap4Client imap = new Imap4Client();
 ///imap.Connect("mail.myhost.com",8505);
 ///Mailbox inbox = imap.SelectMailbox("inbox");
 ///
 ///message.Append(inbox);
 ///
 ///imap.Close();
 ///imap.Disconnect();
 /// 
 /// VB.NET
 /// 
 ///Dim message As New Message
 ///message.From = new Address("*****@*****.**","John Doe")
 ///message.To.Add("*****@*****.**","Mike Johns")
 ///message.Subject = "hey!"
 ///message.Attachments.Add("C:\myfile.doc")
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 ///
 ///Dim imap As New Imap4Client
 ///imap.Connect("mail.myhost.com",8505)
 ///Dim inbox As Mailbox = imap.SelectMailbox("inbox")
 ///
 ///message.Append(inbox)
 ///
 ///imap.Close()
 ///imap.Disconnect()
 ///  
 /// JScript.NET
 /// 
 ///var message:Message = new Message();
 ///message.From = new Address("*****@*****.**","John Doe")
 ///message.To.Add("*****@*****.**","Mike Johns");
 ///message.Subject = "hey!";
 ///message.Attachments.Add("C:\\myfile.doc");
 ///message.BodyHtml.Text = "As promised, the requested document.&lt;br />&lt;br />Regards,&lt;br>John."
 ///
 ///var imap:Imap4Client = new Imap4Client();
 ///imap.Connect("mail.myhost.com",8505);
 ///var inbox:Mailbox = imap.SelectMailbox("inbox");
 ///
 ///message.Append(inbox);
 ///
 ///imap.Close();
 ///imap.Disconnect();
 /// </code>
 /// </example>
 public void Append(IMailbox imapMailbox)
 {
     imapMailbox.Append(this.ToString());
 }
Example #55
0
 public abstract void UpdateMailbox(IMailbox mailbox);
Example #56
0
 public abstract void DeleteMailbox(IMailbox mailbox);
Example #57
0
 /// <summary>
 /// Returns a value indicating whether the given mailbox can be accepted as a recipient to the given sender.
 /// </summary>
 /// <param name="context">The session context.</param>
 /// <param name="to">The mailbox to test.</param>
 /// <param name="from">The sender's mailbox.</param>
 /// <returns>The acceptance state of the mailbox.</returns>
 public virtual Task<MailboxFilterResult> CanDeliverToAsync(ISessionContext context, IMailbox to, IMailbox @from)
 {
     return Task.FromResult(MailboxFilterResult.Yes);
 }
Example #58
0
 public virtual void DoubleCreateMailbox()
 {
     peter_mailbox = server.CreateMailbox(peter_address.LocalPart, PETER_PASSWORD, peter_address.Domain, peter_account, TestContext.ServerFactory);
     server.CreateMailbox(peter_address.LocalPart, PETER_PASSWORD, peter_address.Domain, peter_account, TestContext.ServerFactory);
 }
Example #59
0
 public IAsyncResult BeginAppend(IMailbox imapMailbox, AsyncCallback callback)
 {
     this._delegateAppend = this.Append;
     return this._delegateAppend.BeginInvoke(imapMailbox, callback, this._delegateAppend);
 }
Example #60
0
 public void WaitMutex(IMailbox<object> me)
 {
     UnlockMutex(me);
     waitQueue.Add(me);
 }